dmaicher / doctrine-test-bundle

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

Allow manual operations on static connections #203

Closed chriskaya closed 2 years ago

chriskaya commented 2 years ago

These small changes allow me to handle specific cases like dependent tests (#151 ), or disabling DAMA for a specific class (#182 )

Here's how I use it:

public static function setUpBeforeClass(): void
{
    StaticDriver::setManualOperations(true);
    StaticDriver::beginTransaction();
}

public static function tearDownAfterClass(): void
{
    StaticDriver::rollBack();
    StaticDriver::setManualOperations(false);
}

But it could also be used just for a few tests, like this:

public function testOne(): void
{
    StaticDriver::setManualOperations(true);

    $this->assertTrue(false);
}

/**
 * @depends testOne
 */
public function testTwo(): void
{
    // ...

    StaticDriver::setManualOperations(false);
}
dmaicher commented 2 years ago

I would like to not change the public API of StaticDriver yet as there might be some changes coming anyway when trying to have an annotation with PHPUnit 10 to selectively disable it as mentioned here.

I guess for now if you need this feature you can create your own PHPUnit extension and not use the one provided by this bundle.

Thanks anyway for taking the time to look into it :+1: