Skip to content

Commit

Permalink
Subscribe to Test\PreparationStarted event
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 14, 2023
1 parent ab302b9 commit 2ad7f18
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PHPUnit\Event\Test\Failed;
use PHPUnit\Event\Test\Finished;
use PHPUnit\Event\Test\MarkedIncomplete;
use PHPUnit\Event\Test\PreparationStarted;
use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\Skipped;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
Expand Down Expand Up @@ -176,9 +177,17 @@ public function testSuiteFinished(): void
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function testPrepared(Prepared $event): void
public function testPreparationStarted(PreparationStarted $event): void
{
$this->createTestCase($event);
}

/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function testPrepared(Prepared $event): void
{
$this->prepared = true;
}

Expand Down Expand Up @@ -273,6 +282,7 @@ private function registerSubscribers(Facade $facade): void
$facade->registerSubscribers(
new TestSuiteStartedSubscriber($this),
new TestSuiteFinishedSubscriber($this),
new TestPreparationStartedSubscriber($this),
new TestPreparedSubscriber($this),
new TestFinishedSubscriber($this),
new TestErroredSubscriber($this),
Expand Down Expand Up @@ -408,7 +418,7 @@ private function name(Test $test): string
*
* @psalm-assert !null $this->currentTestCase
*/
private function createTestCase(Errored|Failed|MarkedIncomplete|Prepared|Skipped $event): void
private function createTestCase(Errored|Failed|MarkedIncomplete|PreparationStarted|Prepared|Skipped $event): void
{
$testCase = $this->document->createElement('testcase');

Expand Down
30 changes: 30 additions & 0 deletions src/Logging/JUnit/Subscriber/TestPreparationStartedSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Logging\JUnit;

use PHPUnit\Event\InvalidArgumentException;
use PHPUnit\Event\Test\PreparationStarted;
use PHPUnit\Event\Test\PreparationStartedSubscriber;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TestPreparationStartedSubscriber extends Subscriber implements PreparationStartedSubscriber
{
/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function notify(PreparationStarted $event): void
{
$this->logger()->testPreparationStarted($event);
}
}

0 comments on commit 2ad7f18

Please sign in to comment.