Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with skipping test during setUp using PHPUnit 10 #263

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading