Skip to content

Commit 6321d41

Browse files
sebastianbergmannSchranktheseerstaabmTesla91
committed
Implement TestRunner\ChildProcessStarted and TestRunner\ChildProcessFinished events
Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de> Co-authored-by: Fabian Blechschmidt <github@fabian-blechschmidt.de> Co-authored-by: Arne Blankerts <arne@blankerts.de> Co-authored-by: Markus Staab <markus.staab@redaxo.de> Co-authored-by: Nicola Pilcher <nicola.pilcher@gmail.com> Co-authored-by: Andreas Möller <am@localheinz.com> Co-authored-by: Sebastian Heuer <sebastian@phpeople.de>
1 parent 319909f commit 6321d41

24 files changed

+315
-1
lines changed

ChangeLog-11.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
77
### Added
88

99
* [#5948](https://github.com/sebastianbergmann/phpunit/pull/5948): Support for Property Hooks in Test Doubles
10+
* `TestRunner\ChildProcessStarted` and `TestRunner\ChildProcessFinished` events
1011

1112
[11.5.0]: https://github.com/sebastianbergmann/phpunit/compare/11.4...11.5

src/Event/Emitter/DispatchingEmitter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ public function testRunnerTriggeredGarbageCollection(): void
262262
);
263263
}
264264

265+
public function testRunnerStartedChildProcess(): void
266+
{
267+
$this->dispatcher->dispatch(
268+
new TestRunner\ChildProcessStarted($this->telemetryInfo()),
269+
);
270+
}
271+
272+
public function testRunnerFinishedChildProcess(string $stdout, string $stderr): void
273+
{
274+
$this->dispatcher->dispatch(
275+
new TestRunner\ChildProcessFinished(
276+
$this->telemetryInfo(),
277+
$stdout,
278+
$stderr,
279+
),
280+
);
281+
}
282+
265283
/**
266284
* @throws InvalidArgumentException
267285
* @throws UnknownEventTypeException

src/Event/Emitter/Emitter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ public function testAfterLastTestMethodFinished(string $testClassName, ClassMeth
277277

278278
public function testSuiteFinished(TestSuite $testSuite): void;
279279

280+
public function testRunnerStartedChildProcess(): void;
281+
282+
public function testRunnerFinishedChildProcess(string $stdout, string $stderr): void;
283+
280284
public function testRunnerTriggeredDeprecation(string $message): void;
281285

282286
public function testRunnerTriggeredWarning(string $message): void;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\TestRunner;
11+
12+
use PHPUnit\Event\Event;
13+
use PHPUnit\Event\Telemetry;
14+
15+
/**
16+
* @immutable
17+
*
18+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final readonly class ChildProcessFinished implements Event
21+
{
22+
private Telemetry\Info $telemetryInfo;
23+
private string $stdout;
24+
private string $stderr;
25+
26+
public function __construct(Telemetry\Info $telemetryInfo, string $stdout, string $stderr)
27+
{
28+
$this->telemetryInfo = $telemetryInfo;
29+
$this->stdout = $stdout;
30+
$this->stderr = $stderr;
31+
}
32+
33+
public function telemetryInfo(): Telemetry\Info
34+
{
35+
return $this->telemetryInfo;
36+
}
37+
38+
public function stdout(): string
39+
{
40+
return $this->stdout;
41+
}
42+
43+
public function stderr(): string
44+
{
45+
return $this->stderr;
46+
}
47+
48+
public function asString(): string
49+
{
50+
return 'Child Process Finished';
51+
}
52+
}
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 <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\TestRunner;
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 ChildProcessFinishedSubscriber extends Subscriber
18+
{
19+
public function notify(ChildProcessFinished $event): void;
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\TestRunner;
11+
12+
use PHPUnit\Event\Event;
13+
use PHPUnit\Event\Telemetry;
14+
15+
/**
16+
* @immutable
17+
*
18+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final readonly class ChildProcessStarted implements Event
21+
{
22+
private Telemetry\Info $telemetryInfo;
23+
24+
public function __construct(Telemetry\Info $telemetryInfo)
25+
{
26+
$this->telemetryInfo = $telemetryInfo;
27+
}
28+
29+
public function telemetryInfo(): Telemetry\Info
30+
{
31+
return $this->telemetryInfo;
32+
}
33+
34+
public function asString(): string
35+
{
36+
return 'Child Process Started';
37+
}
38+
}
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 <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\TestRunner;
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 ChildProcessStartedSubscriber extends Subscriber
18+
{
19+
public function notify(ChildProcessStarted $event): void;
20+
}

src/Event/Facade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ private function registerDefaultTypes(TypeMap $typeMap): void
236236
TestRunner\GarbageCollectionDisabled::class,
237237
TestRunner\GarbageCollectionTriggered::class,
238238
TestRunner\GarbageCollectionEnabled::class,
239+
TestRunner\ChildProcessFinished::class,
240+
TestRunner\ChildProcessStarted::class,
239241

240242
TestSuite\Filtered::class,
241243
TestSuite\Finished::class,

src/Framework/TestRunner/templates/class.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function __phpunit_run_isolated_test()
7878
}
7979
}
8080

81+
Facade::emitter()->testRunnerFinishedChildProcess($output, '');
82+
8183
file_put_contents(
8284
'{processResultFile}',
8385
serialize(

src/Framework/TestRunner/templates/method.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function __phpunit_run_isolated_test()
7878
}
7979
}
8080

81+
Facade::emitter()->testRunnerFinishedChildProcess($output, '');
82+
8183
file_put_contents(
8284
'{processResultFile}',
8385
serialize(

0 commit comments

Comments
 (0)