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:

  1. write an action that has a app(DatabaseServiceInterface::class)->transaction.
  2. 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)

Most upvoted comments

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)

Screen Shot 2022-04-12 at 08 21 59 Screen Shot 2022-04-12 at 08 21 18

The same happens with RefreshDatabase trait (without DB::commit exactly like your test case) instead of LazyRefreshDatabase

I will try to make an example in that repo like I did before.