There is already an active transaction
mareckigit opened this issue · 6 comments
When I use:
./bin/phpunit --group mygroup
I get exception: There is already an active transaction
When I use:
./bin/phpunit
it works.
Before installation of doctrine-test-bundle both cases worked correctly.
- Can I see a stack trace of that exception?
- Are you doing any database things inside
setUpBeforeClass
methods?
I simulate authethication in setUpBeforeClass(). When it's moved to single test, it works.
PDOException {#1263
#message: "There is already an active transaction"
#code: 0
#file: "./vendor/dama/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php"
#line: 126
+errorInfo: null
trace: {
./vendor/dama/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php:126 { …}
./vendor/dama/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php:20 { …}
./bin/.phpunit/phpunit-7.5-0/src/Runner/Hook/TestListenerAdapter.php:40 {
PHPUnit\Runner\TestListenerAdapter->startTest(Test $test): void^
› if ($hook instanceof BeforeTestHook) {
› $hook->executeBeforeTest(TestUtil::describeAsString($test));
› }
}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestResult.php:406 { …}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestResult.php:626 { …}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestCase.php:797 { …}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestSuite.php:746 { …}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestSuite.php:746 { …}
./bin/.phpunit/phpunit-7.5-0/src/Framework/TestSuite.php:746 { …}
./bin/.phpunit/phpunit-7.5-0/src/TextUI/TestRunner.php:652 { …}
./bin/.phpunit/phpunit-7.5-0/src/TextUI/Command.php:206 { …}
./bin/.phpunit/phpunit-7.5-0/src/TextUI/Command.php:162 { …}
./bin/.phpunit/phpunit-7.5-0/phpunit:18 { …}
./vendor/symfony/phpunit-bridge/bin/simple-phpunit.php:344 { …}
./bin/phpunit:13 { …}
}
}
Currently there is no way to support that unfortunately 😢
See #108
The BeforeTestHook
this bundle uses is executed after the setUpBeforeClass
so all changes done there are not transactional anymore and there is no way to roll them back.
Sorry, I haven't seen this issue. I've added StaticDriver::commit()
to setUpBeforeClass()
and now it works.
It is strange for me that the exception was thrown only when the filter by group was used. Without any filter, when all tests are run, the exception is not thrown. Do you know what's the relationship?
Thanks for help.
Update:
Now, when I'm executing all tests with added StaticDriver::commit()
, exception is thrown from other tests.
Finally I resolved this by #108 (comment)
It is strange for me that the exception was thrown only when the filter by group was used. Without any filter, when all tests are run, the exception is not thrown. Do you know what's the relationship?
probably its because when you run all tests the test does not run as the first test? But when you run only for that group then the test with setUpBeforeClass
runs first? Or the other way around. That would explain it.