Skip to content

Commit

Permalink
roll back transactions for tests marked as incomplete in setUp()
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Feb 1, 2025
1 parent 866bbbf commit 1ffef30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace DAMA\DoctrineTestBundle\PHPUnit;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use PHPUnit\Event\Test\BeforeTestMethodErrored;
use PHPUnit\Event\Test\BeforeTestMethodErroredSubscriber;
use PHPUnit\Event\Test\Errored;
use PHPUnit\Event\Test\ErroredSubscriber;
use PHPUnit\Event\Test\Finished as TestFinishedEvent;
Expand Down Expand Up @@ -75,6 +77,14 @@ public function notify(TestFinishedEvent $event): void
}
});

$facade->registerSubscriber(new class implements BeforeTestMethodErroredSubscriber {
public function notify(BeforeTestMethodErrored $event): void
{
// needed for tests marked incomplete during setUp()
PHPUnitExtension::rollBack();
}
});

$facade->registerSubscriber(new class implements ErroredSubscriber {
public function notify(Errored $event): void
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/PhpunitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ protected function setUp(): void
if ((method_exists($this, 'name') ? $this->name() : $this->getName()) === 'testSkippedTestDuringSetup') {
$this->markTestSkipped();
}

/** @phpstan-ignore-next-line */
if ((method_exists($this, 'name') ? $this->name() : $this->getName()) === 'testIncompleteTestDuringSetup') {
$this->markTestIncomplete();
}
}

public function testChangeDbState(): void
Expand Down Expand Up @@ -147,6 +152,11 @@ public function testSkippedTestDuringSetup(): void
$this->expectNotToPerformAssertions();
}

public function testIncompleteTestDuringSetup(): void
{
$this->expectNotToPerformAssertions();
}

public function testMarkIncomplete(): void
{
$this->markTestIncomplete();
Expand Down

0 comments on commit 1ffef30

Please sign in to comment.