dmaicher / doctrine-test-bundle

Symfony bundle to isolate your app's doctrine database tests and improve the test performance
MIT License
1.07k stars 60 forks source link

There is already an active transaction #264

Closed dgarciaortiz94 closed 7 months ago

dgarciaortiz94 commented 8 months ago

Hello.

I'm using Symfony 6.2v and when I execute my tests with

php bin/phpunit

and this bundle is active, I get de following error message:

There is already an active transaction

This is my phpunit config:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="tests/bootstrap.php"
         convertDeprecationsToExceptions="false"
>
    <php>
        <ini name="display_errors" value="1" />
        <ini name="error_reporting" value="-1" />
        <server name="APP_ENV" value="test" force="true" />
        <server name="SHELL_VERBOSITY" value="-1" />
        <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
        <server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">src</directory>
        </include>
    </coverage>

    <listeners>
        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
    </listeners>

    <extensions>
        <extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
    </extensions>
</phpunit>

The bundle is included inside extensions tag.

If I comment the bundle extension my tests run successfully.

dmaicher commented 8 months ago

Which version of the bundle are you using? Could you test the latest BETA for version 8?

dgarciaortiz94 commented 8 months ago

@dmaicher I've tested the 7.2.1 stable version and all beta versions.

dmaicher commented 7 months ago

Hm hard to say. 2 options:

dmaicher commented 7 months ago

Let me know if there is any update. Can re-open the issue then.

dgarciaortiz94 commented 7 months ago

@dmaicher I found the issue, it was my mistake.

I was using setUpBeforeClass wrongly in my parent test class and I didn't realize that it was opening a transaction before tests were executed.

Thank you and I'm sorry for the mistake.