Skip to content

Commit

Permalink
fix compatibility with PHPUnit < 10.5.41 and < 11.5.6 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher authored Feb 4, 2025
1 parent 1eab74f commit eefe54f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ 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();
}
});
if (interface_exists(BeforeTestMethodErroredSubscriber::class)) {
$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
9 changes: 6 additions & 3 deletions tests/Functional/PhpunitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use Doctrine\DBAL\Exception\TableNotFoundException;
use PHPUnit\Event\Test\BeforeTestMethodErroredSubscriber;
use PHPUnit\Framework\TestCase;

class PhpunitTest extends TestCase
Expand All @@ -14,13 +15,15 @@ protected function setUp(): void
{
parent::setUp();
$this->init();
/** @phpstan-ignore-next-line */
/** @phpstan-ignore method.notFound,function.alreadyNarrowedType */
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') {
if (interface_exists(BeforeTestMethodErroredSubscriber::class)
/** @phpstan-ignore method.notFound,function.alreadyNarrowedType */
&& (method_exists($this, 'name') ? $this->name() : $this->getName()) === 'testIncompleteTestDuringSetup'
) {
$this->markTestIncomplete();
}
}
Expand Down

0 comments on commit eefe54f

Please sign in to comment.