-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments: Speed up Laravel tests with database transactions #9
Comments
You can also use RefreshDatabase Trait |
I would advice not using this technique. Transactions should already be used to prevent data corruption during normal application usage. Using transactions during testing only works if the database supports nested transactions, and MySQL doesn't. |
So the official documentation is wrong? |
The MysSQL 5.7 documentation describes Statements That Cause an Implicit Commit. Under Transaction-control and locking statements it mentions
The new version 8 handles this the same way. |
Kwebble, I mean laravel's official documentation. The official documentation recommends using this trait. It seems to me that this trait is smart enough to detect your database driver and decide wether or not it should use a database transaction. |
OK, I understand. I haven't seen the Laravel implementation of this feature. Perhaps it is possible by using a separate database connection for the test changes and configuring the normal connection to allow dirty reads of uncommitted changes. But then the testing environment differs from production. Also, I know the Laravel documentation is not complete or always clear. In fact I've written about that: http://kwebble.com/blog/2017-05-17_14:26:52 |
If that's the case (laravel's official documentation not being accurate) have you submitted a pull request? (Not a rhetorical question) |
No, I did not. There's no time for me at work to do that. And privately I don't use Laravel. If I would contribute documentation it would be PHPDoc to describe all method arguments and return values, not the website. Having fully documented code looks more important to me. Once I found out the site does not describe all features I only use it as starting point, not as ultimate reference. |
I think Laravel's Transaction support nesting |
@kwebble Here are some links if you want to read further https://secure.php.net/manual/en/pdo.begintransaction.php#116669 https://stackoverflow.com/a/11941449/1132836 That's why Laravel's documentation recommends using RefreshDatabase Trait. |
Comments left on this issue will be shown live on the post: https://jordaneldredge.com/blog/speed-up-laravel-tests-with-database-transactions/
The text was updated successfully, but these errors were encountered: