Skip to content

Commit 25c813d

Browse files
Merge branch '10.5' into 11.5
2 parents 6093ee5 + a7dbfad commit 25c813d

31 files changed

+1252
-6
lines changed

ChangeLog-11.5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
44

55
## [11.5.3] - 2025-MM-DD
66

7+
### Added
8+
9+
* `Test\AfterLastTestMethodErrored`, `Test\AfterTestMethodErrored`, `Test\BeforeTestMethodErrored`, `Test\PostConditionErrored`, and `Test\PreConditionErrored` events
10+
711
### Fixed
812

913
* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected

src/Event/Emitter/DispatchingEmitter.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,24 @@ public function testBeforeTestMethodCalled(string $testClassName, ClassMethod $c
412412
* @throws InvalidArgumentException
413413
* @throws UnknownEventTypeException
414414
*/
415+
public function testBeforeTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
416+
{
417+
$this->dispatcher->dispatch(
418+
new Test\BeforeTestMethodErrored(
419+
$this->telemetryInfo(),
420+
$testClassName,
421+
$calledMethod,
422+
$throwable,
423+
),
424+
);
425+
}
426+
427+
/**
428+
* @psalm-param class-string $testClassName
429+
*
430+
* @throws InvalidArgumentException
431+
* @throws UnknownEventTypeException
432+
*/
415433
public function testBeforeTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
416434
{
417435
$this->dispatcher->dispatch(
@@ -446,6 +464,24 @@ public function testPreConditionCalled(string $testClassName, ClassMethod $calle
446464
* @throws InvalidArgumentException
447465
* @throws UnknownEventTypeException
448466
*/
467+
public function testPreConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
468+
{
469+
$this->dispatcher->dispatch(
470+
new Test\PreConditionErrored(
471+
$this->telemetryInfo(),
472+
$testClassName,
473+
$calledMethod,
474+
$throwable,
475+
),
476+
);
477+
}
478+
479+
/**
480+
* @psalm-param class-string $testClassName
481+
*
482+
* @throws InvalidArgumentException
483+
* @throws UnknownEventTypeException
484+
*/
449485
public function testPreConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void
450486
{
451487
$this->dispatcher->dispatch(
@@ -1016,6 +1052,24 @@ public function testPostConditionCalled(string $testClassName, ClassMethod $call
10161052
* @throws InvalidArgumentException
10171053
* @throws UnknownEventTypeException
10181054
*/
1055+
public function testPostConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
1056+
{
1057+
$this->dispatcher->dispatch(
1058+
new Test\PostConditionErrored(
1059+
$this->telemetryInfo(),
1060+
$testClassName,
1061+
$calledMethod,
1062+
$throwable,
1063+
),
1064+
);
1065+
}
1066+
1067+
/**
1068+
* @psalm-param class-string $testClassName
1069+
*
1070+
* @throws InvalidArgumentException
1071+
* @throws UnknownEventTypeException
1072+
*/
10191073
public function testPostConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void
10201074
{
10211075
$this->dispatcher->dispatch(
@@ -1050,6 +1104,24 @@ public function testAfterTestMethodCalled(string $testClassName, ClassMethod $ca
10501104
* @throws InvalidArgumentException
10511105
* @throws UnknownEventTypeException
10521106
*/
1107+
public function testAfterTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
1108+
{
1109+
$this->dispatcher->dispatch(
1110+
new Test\AfterTestMethodErrored(
1111+
$this->telemetryInfo(),
1112+
$testClassName,
1113+
$calledMethod,
1114+
$throwable,
1115+
),
1116+
);
1117+
}
1118+
1119+
/**
1120+
* @psalm-param class-string $testClassName
1121+
*
1122+
* @throws InvalidArgumentException
1123+
* @throws UnknownEventTypeException
1124+
*/
10531125
public function testAfterTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
10541126
{
10551127
$this->dispatcher->dispatch(
@@ -1084,6 +1156,24 @@ public function testAfterLastTestMethodCalled(string $testClassName, ClassMethod
10841156
* @throws InvalidArgumentException
10851157
* @throws UnknownEventTypeException
10861158
*/
1159+
public function testAfterLastTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
1160+
{
1161+
$this->dispatcher->dispatch(
1162+
new Test\AfterLastTestMethodErrored(
1163+
$this->telemetryInfo(),
1164+
$testClassName,
1165+
$calledMethod,
1166+
$throwable,
1167+
),
1168+
);
1169+
}
1170+
1171+
/**
1172+
* @psalm-param class-string $testClassName
1173+
*
1174+
* @throws InvalidArgumentException
1175+
* @throws UnknownEventTypeException
1176+
*/
10871177
public function testAfterLastTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
10881178
{
10891179
$this->dispatcher->dispatch(

src/Event/Emitter/Emitter.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public function testBeforeTestMethodCalled(string $testClassName, ClassMethod $c
8888
/**
8989
* @param class-string $testClassName
9090
*/
91+
public function testBeforeTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;
92+
93+
/**
94+
* @psalm-param class-string $testClassName
95+
*/
9196
public function testBeforeTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;
9297

9398
/**
@@ -98,6 +103,11 @@ public function testPreConditionCalled(string $testClassName, ClassMethod $calle
98103
/**
99104
* @param class-string $testClassName
100105
*/
106+
public function testPreConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;
107+
108+
/**
109+
* @psalm-param class-string $testClassName
110+
*/
101111
public function testPreConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void;
102112

103113
public function testPrepared(Code\Test $test): void;
@@ -254,6 +264,11 @@ public function testPostConditionCalled(string $testClassName, ClassMethod $call
254264
/**
255265
* @param class-string $testClassName
256266
*/
267+
public function testPostConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;
268+
269+
/**
270+
* @psalm-param class-string $testClassName
271+
*/
257272
public function testPostConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void;
258273

259274
/**
@@ -264,6 +279,11 @@ public function testAfterTestMethodCalled(string $testClassName, ClassMethod $ca
264279
/**
265280
* @param class-string $testClassName
266281
*/
282+
public function testAfterTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;
283+
284+
/**
285+
* @psalm-param class-string $testClassName
286+
*/
267287
public function testAfterTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;
268288

269289
/**
@@ -274,6 +294,11 @@ public function testAfterLastTestMethodCalled(string $testClassName, ClassMethod
274294
/**
275295
* @param class-string $testClassName
276296
*/
297+
public function testAfterLastTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;
298+
299+
/**
300+
* @psalm-param class-string $testClassName
301+
*/
277302
public function testAfterLastTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;
278303

279304
public function testSuiteFinished(TestSuite $testSuite): void;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 const PHP_EOL;
13+
use function sprintf;
14+
use PHPUnit\Event\Code;
15+
use PHPUnit\Event\Code\Throwable;
16+
use PHPUnit\Event\Event;
17+
use PHPUnit\Event\Telemetry;
18+
19+
/**
20+
* @psalm-immutable
21+
*
22+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
23+
*/
24+
final class AfterLastTestMethodErrored implements Event
25+
{
26+
private readonly Telemetry\Info $telemetryInfo;
27+
28+
/**
29+
* @psalm-var class-string
30+
*/
31+
private readonly string $testClassName;
32+
private readonly Code\ClassMethod $calledMethod;
33+
private readonly Throwable $throwable;
34+
35+
/**
36+
* @psalm-param class-string $testClassName
37+
*/
38+
public function __construct(Telemetry\Info $telemetryInfo, string $testClassName, Code\ClassMethod $calledMethod, Throwable $throwable)
39+
{
40+
$this->telemetryInfo = $telemetryInfo;
41+
$this->testClassName = $testClassName;
42+
$this->calledMethod = $calledMethod;
43+
$this->throwable = $throwable;
44+
}
45+
46+
public function telemetryInfo(): Telemetry\Info
47+
{
48+
return $this->telemetryInfo;
49+
}
50+
51+
/**
52+
* @psalm-return class-string
53+
*/
54+
public function testClassName(): string
55+
{
56+
return $this->testClassName;
57+
}
58+
59+
public function calledMethod(): Code\ClassMethod
60+
{
61+
return $this->calledMethod;
62+
}
63+
64+
public function throwable(): Throwable
65+
{
66+
return $this->throwable;
67+
}
68+
69+
public function asString(): string
70+
{
71+
$message = $this->throwable->message();
72+
73+
if (!empty($message)) {
74+
$message = PHP_EOL . $message;
75+
}
76+
77+
return sprintf(
78+
'After Last Test Method Errored (%s::%s)%s',
79+
$this->calledMethod->className(),
80+
$this->calledMethod->methodName(),
81+
$message,
82+
);
83+
}
84+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 AfterLastTestMethodErroredSubscriber extends Subscriber
18+
{
19+
public function notify(AfterLastTestMethodErrored $event): void;
20+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 const PHP_EOL;
13+
use function sprintf;
14+
use PHPUnit\Event\Code;
15+
use PHPUnit\Event\Code\Throwable;
16+
use PHPUnit\Event\Event;
17+
use PHPUnit\Event\Telemetry;
18+
19+
/**
20+
* @psalm-immutable
21+
*
22+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
23+
*/
24+
final class AfterTestMethodErrored implements Event
25+
{
26+
private readonly Telemetry\Info $telemetryInfo;
27+
28+
/**
29+
* @psalm-var class-string
30+
*/
31+
private readonly string $testClassName;
32+
private readonly Code\ClassMethod $calledMethod;
33+
private readonly Throwable $throwable;
34+
35+
/**
36+
* @psalm-param class-string $testClassName
37+
*/
38+
public function __construct(Telemetry\Info $telemetryInfo, string $testClassName, Code\ClassMethod $calledMethod, Throwable $throwable)
39+
{
40+
$this->telemetryInfo = $telemetryInfo;
41+
$this->testClassName = $testClassName;
42+
$this->calledMethod = $calledMethod;
43+
$this->throwable = $throwable;
44+
}
45+
46+
public function telemetryInfo(): Telemetry\Info
47+
{
48+
return $this->telemetryInfo;
49+
}
50+
51+
/**
52+
* @psalm-return class-string
53+
*/
54+
public function testClassName(): string
55+
{
56+
return $this->testClassName;
57+
}
58+
59+
public function calledMethod(): Code\ClassMethod
60+
{
61+
return $this->calledMethod;
62+
}
63+
64+
public function throwable(): Throwable
65+
{
66+
return $this->throwable;
67+
}
68+
69+
public function asString(): string
70+
{
71+
$message = $this->throwable->message();
72+
73+
if (!empty($message)) {
74+
$message = PHP_EOL . $message;
75+
}
76+
77+
return sprintf(
78+
'After Test Method Errored (%s::%s)%s',
79+
$this->calledMethod->className(),
80+
$this->calledMethod->methodName(),
81+
$message,
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)