Skip to content

Commit

Permalink
fix issue with skipping test during setUp using PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Oct 31, 2023
1 parent ab6d425 commit 2f55b23
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
namespace DAMA\DoctrineTestBundle\PHPUnit;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use PHPUnit\Event\Test\Finished as TestFinishedEvent;
use PHPUnit\Event\Test\FinishedSubscriber as TestFinishedSubscriber;
use PHPUnit\Event\Test\Errored;
use PHPUnit\Event\Test\ErroredSubscriber;
use PHPUnit\Event\Test\Failed;
use PHPUnit\Event\Test\FailedSubscriber;
use PHPUnit\Event\Test\MarkedIncomplete;
use PHPUnit\Event\Test\MarkedIncompleteSubscriber;
use PHPUnit\Event\Test\Passed;
use PHPUnit\Event\Test\PassedSubscriber;
use PHPUnit\Event\Test\PreparationStarted as TestStartedEvent;
use PHPUnit\Event\Test\PreparationStartedSubscriber as TestStartedSubscriber;
use PHPUnit\Event\Test\Skipped;
use PHPUnit\Event\Test\SkippedSubscriber;
use PHPUnit\Event\TestRunner\Finished as TestRunnerFinishedEvent;
use PHPUnit\Event\TestRunner\FinishedSubscriber as TestRunnerFinishedSubscriber;
use PHPUnit\Event\TestRunner\Started as TestRunnerStartedEvent;
Expand Down Expand Up @@ -42,8 +50,36 @@ public function notify(TestStartedEvent $event): void
}
});

$facade->registerSubscriber(new class() implements TestFinishedSubscriber {
public function notify(TestFinishedEvent $event): void
$facade->registerSubscriber(new class() implements SkippedSubscriber {
public function notify(Skipped $event): void
{
StaticDriver::rollBack();
}
});

$facade->registerSubscriber(new class() implements PassedSubscriber {
public function notify(Passed $event): void
{
StaticDriver::rollBack();
}
});

$facade->registerSubscriber(new class() implements FailedSubscriber {
public function notify(Failed $event): void
{
StaticDriver::rollBack();
}
});

$facade->registerSubscriber(new class() implements ErroredSubscriber {
public function notify(Errored $event): void
{
StaticDriver::rollBack();
}
});

$facade->registerSubscriber(new class() implements MarkedIncompleteSubscriber {
public function notify(MarkedIncomplete $event): void
{
StaticDriver::rollBack();
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Functional/PhpunitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ class PhpunitTest extends TestCase
{
use FunctionalTestTrait;

protected function setUp(): void
{
parent::setUp();
$this->init();
/** @phpstan-ignore-next-line */
if ((method_exists($this, 'name') ? $this->name() : $this->getName()) === 'testSkippedTestDuringSetup') {
$this->markTestSkipped();
}
}

public function testChangeDbState(): void
{
$this->assertRowCount(0);
Expand Down Expand Up @@ -123,6 +133,21 @@ public function testPreviousChangesAreRolledBackAfterUsingSavePoint(): void
$this->assertRowCount(0);
}

public function testSkippedTest(): void
{
$this->markTestSkipped();
}

public function testSkippedTestDuringSetup(): void
{
$this->assertTrue(true);
}

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

public function testRollBackChangesWithReOpenedConnection(): void
{
$this->connection->close();
Expand Down

0 comments on commit 2f55b23

Please sign in to comment.