File tree Expand file tree Collapse file tree 8 files changed +135
-0
lines changed
tests/unit/Event/Events/Test/Lifecycle Expand file tree Collapse file tree 8 files changed +135
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ All notable changes of the PHPUnit 10.4 release series are documented in this fi
10
10
* [ #5462 ] ( https://github.com/sebastianbergmann/phpunit/pull/5462 ) : Support for multiple arguments
11
11
* [ #5471 ] ( https://github.com/sebastianbergmann/phpunit/issues/5471 ) : ` assertFileMatchesFormat() ` and ` assertFileMatchesFormatFile() `
12
12
* [ #5515 ] ( https://github.com/sebastianbergmann/phpunit/issues/5515 ) : ` PHPUnit\Runner\Extension\Facade::requireExportOfObjects() ` so that test runner extensions can indicate that they require the export of objects for events such as ` Test\AssertionSucceeded ` and ` Test\AssertionFailed `
13
+ * ` Test\PreparationFailed ` event
13
14
* Attribute ` id ` attribute for ` testCaseMethod ` elements in the XML document generated by ` --list-tests-xml `
14
15
15
16
### Changed
Original file line number Diff line number Diff line change @@ -307,6 +307,20 @@ public function testPreparationStarted(Code\Test $test): void
307
307
);
308
308
}
309
309
310
+ /**
311
+ * @throws InvalidArgumentException
312
+ * @throws UnknownEventTypeException
313
+ */
314
+ public function testPreparationFailed (Code \Test $ test ): void
315
+ {
316
+ $ this ->dispatcher ->dispatch (
317
+ new Test \PreparationFailed (
318
+ $ this ->telemetryInfo (),
319
+ $ test ,
320
+ ),
321
+ );
322
+ }
323
+
310
324
/**
311
325
* @psalm-param class-string $testClassName
312
326
*
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ public function testSuiteStarted(TestSuite $testSuite): void;
63
63
64
64
public function testPreparationStarted (Code \Test $ test ): void ;
65
65
66
+ public function testPreparationFailed (Code \Test $ test ): void ;
67
+
66
68
/**
67
69
* @psalm-param class-string $testClassName
68
70
*/
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \Event \Test ;
11
+
12
+ use function sprintf ;
13
+ use PHPUnit \Event \Code ;
14
+ use PHPUnit \Event \Event ;
15
+ use PHPUnit \Event \Telemetry ;
16
+
17
+ /**
18
+ * @psalm-immutable
19
+ *
20
+ * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
21
+ */
22
+ final class PreparationFailed implements Event
23
+ {
24
+ private readonly Telemetry \Info $ telemetryInfo ;
25
+ private readonly Code \Test $ test ;
26
+
27
+ public function __construct (Telemetry \Info $ telemetryInfo , Code \Test $ test )
28
+ {
29
+ $ this ->telemetryInfo = $ telemetryInfo ;
30
+ $ this ->test = $ test ;
31
+ }
32
+
33
+ public function telemetryInfo (): Telemetry \Info
34
+ {
35
+ return $ this ->telemetryInfo ;
36
+ }
37
+
38
+ public function test (): Code \Test
39
+ {
40
+ return $ this ->test ;
41
+ }
42
+
43
+ public function asString (): string
44
+ {
45
+ return sprintf (
46
+ 'Test Preparation Failed (%s) ' ,
47
+ $ this ->test ->id (),
48
+ );
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \Event \Test ;
11
+
12
+ use PHPUnit \Event \Subscriber ;
13
+
14
+ /**
15
+ * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16
+ */
17
+ interface PreparationFailedSubscriber extends Subscriber
18
+ {
19
+ public function notify (PreparationFailed $ event ): void ;
20
+ }
Original file line number Diff line number Diff line change @@ -204,6 +204,7 @@ private function registerDefaultTypes(TypeMap $typeMap): void
204
204
Test \PreConditionFinished::class,
205
205
Test \PreparationStarted::class,
206
206
Test \Prepared::class,
207
+ Test \PreparationFailed::class,
207
208
Test \PrintedUnexpectedOutput::class,
208
209
Test \Skipped::class,
209
210
Test \WarningTriggered::class,
Original file line number Diff line number Diff line change @@ -673,6 +673,10 @@ final public function runBare(): void
673
673
} catch (AssertionError |AssertionFailedError $ e ) {
674
674
if (!$ this ->wasPrepared ) {
675
675
$ this ->wasPrepared = true ;
676
+
677
+ $ emitter ->testPreparationFailed (
678
+ $ this ->valueObjectForEvents (),
679
+ );
676
680
}
677
681
678
682
$ this ->status = TestStatus::failure ($ e ->getMessage ());
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \Event \Test ;
11
+
12
+ use PHPUnit \Event \AbstractEventTestCase ;
13
+ use PHPUnit \Framework \Attributes \CoversClass ;
14
+ use PHPUnit \Framework \Attributes \Small ;
15
+
16
+ #[CoversClass(PreparationFailed::class)]
17
+ #[Small]
18
+ final class PreparationFailedTest extends AbstractEventTestCase
19
+ {
20
+ public function testConstructorSetsValues (): void
21
+ {
22
+ $ telemetryInfo = $ this ->telemetryInfo ();
23
+ $ test = $ this ->testValueObject ();
24
+
25
+ $ event = new PreparationFailed (
26
+ $ telemetryInfo ,
27
+ $ test ,
28
+ );
29
+
30
+ $ this ->assertSame ($ telemetryInfo , $ event ->telemetryInfo ());
31
+ $ this ->assertSame ($ test , $ event ->test ());
32
+ }
33
+
34
+ public function testCanBeRepresentedAsString (): void
35
+ {
36
+ $ event = new PreparationFailed (
37
+ $ this ->telemetryInfo (),
38
+ $ this ->testValueObject (),
39
+ );
40
+
41
+ $ this ->assertSame ('Test Preparation Failed (FooTest::testBar) ' , $ event ->asString ());
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments