laravel-wallet: TransactionStartException will always be throwed in tests with RefreshDatabase trait
Describe your task The test suite in laravel are always executed inside a database transaction if you’re using the LazilyRefreshDatabase trait. After v8.2, all tests that has a wallet transaction are broken
To Reproduce Steps to reproduce the behavior:
- write an action that has a
app(DatabaseServiceInterface::class)->transaction
. - write a test with
LazilyRefreshDatabase
trait.
Expected behavior The test will broke with “Bavix\Wallet\Internal\Exceptions\TransactionStartException : Working inside an embedded transaction is not possible”, but this transaction was started by the framework itself, not in userland.
Server:
- php version: 8.1
- database: postgres 14
- wallet version 8.2
- cache lock: redis
- cache wallets: redis
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (11 by maintainers)
Good article if someone get into this issue someday: https://www.code-distortion.net/books/fast-test-databases/
Using commit strategy after factory creation started to give me wrong results after the first test (e.g: 3 tests in the same file)
The same happens with
RefreshDatabase
trait (withoutDB::commit
exactly like your test case) instead ofLazyRefreshDatabase
I will try to make an example in that repo like I did before.
Here is an example: https://github.com/ibrunotome/laravel-wallet-transaction-exception-example