orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.1k stars 136 forks source link

Filament tests failing with testbench 9.x #393

Closed mokhosh closed 7 months ago

mokhosh commented 7 months ago

Description:

We've been working on dependencies supporting Laravel 11 to be able to support it in Filament. https://github.com/filamentphp/filament/pull/10972

Now the dependencies are ok, but most tests fail with this error:

  FAILED  Tests\src\Actions\ActionTest > it can call an action with data                                  PDOException
  There is already an active transaction

  at vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:150
    146▕         if ($this->transactions == 0) {
    147▕             $this->reconnectIfMissingConnection();
    148▕
    149▕             try {
  ➜ 150▕                 $this->getPdo()->beginTransaction();
    151▕             } catch (Throwable $e) {
    152▕                 $this->handleBeginTransactionException($e);
    153▕             }
    154▕         } elseif ($this->transactions >= 1 && $this->queryGrammar->supportsSavepoints()) {

I checked out the PRs and commits of laravel/framework, but none of them seemed to have caused the issue. I'm guessing it's a testbench issue, specially after going through this PR https://github.com/laravel/framework/pull/49385

Can you please shed some light?

Steps To Reproduce:

crynobone commented 7 months ago

https://github.com/laravel/framework/pull/49385 is not merged yet and has nothing to do with this issue.

crynobone commented 7 months ago

See https://github.com/laravel/framework/pull/47912

In Laravel 11, RefreshDatabase and LazilyRefreshDatabase combined with in-memory database will keep PDO instances between tests and is the root cause of this issue. You would need to reset RefreshDatabaseState between tests.