Skip to content

Commit bc4e9c3

Browse files
Revert "Implement ugly workaround to not emit Test\AssertionSucceeded and Test\AssertionFailed events when they have no subscribers"
This reverts commit 0e3868b.
1 parent 9ae1912 commit bc4e9c3

31 files changed

+35
-166
lines changed

src/Event/Dispatcher/DeferringDispatcher.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ public function registerSubscriber(Subscriber $subscriber): void
3434
$this->dispatcher->registerSubscriber($subscriber);
3535
}
3636

37-
/**
38-
* @todo Remove this method once we found a better way to avoid creating event objects
39-
* that are expensive to create when there are no subscribers registered for them
40-
*
41-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
42-
*/
43-
public function seal(): void
44-
{
45-
$this->dispatcher->seal();
46-
}
47-
4837
public function dispatch(Event $event): void
4938
{
5039
if ($this->recording) {

src/Event/Dispatcher/DirectDispatcher.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
namespace PHPUnit\Event;
1111

1212
use function array_key_exists;
13-
use function assert;
1413
use function dirname;
1514
use function sprintf;
1615
use function str_starts_with;
17-
use PHPUnit\Event\Test\AssertionFailedSubscriber;
18-
use PHPUnit\Event\Test\AssertionSucceededSubscriber;
1916
use Throwable;
2017

2118
/**
@@ -40,34 +37,6 @@ public function __construct(TypeMap $map)
4037
$this->typeMap = $map;
4138
}
4239

43-
/**
44-
* @todo Remove this method once we found a better way to avoid creating event objects
45-
* that are expensive to create when there are no subscribers registered for them
46-
*
47-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
48-
*/
49-
public function seal(): void
50-
{
51-
$emitter = Facade::emitter();
52-
53-
assert($emitter instanceof DispatchingEmitter);
54-
55-
if (!empty($this->tracers)) {
56-
$emitter->emitAssertionSucceededEvents();
57-
$emitter->emitAssertionFailedEvents();
58-
59-
return;
60-
}
61-
62-
if (isset($this->subscribers[AssertionSucceededSubscriber::class])) {
63-
$emitter->emitAssertionSucceededEvents();
64-
}
65-
66-
if (isset($this->subscribers[AssertionFailedSubscriber::class])) {
67-
$emitter->emitAssertionFailedEvents();
68-
}
69-
}
70-
7140
public function registerTracer(Tracer\Tracer $tracer): void
7241
{
7342
$this->tracers[] = $tracer;

src/Event/Dispatcher/SubscribableDispatcher.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,4 @@ interface SubscribableDispatcher extends Dispatcher
2020
public function registerSubscriber(Subscriber $subscriber): void;
2121

2222
public function registerTracer(Tracer\Tracer $tracer): void;
23-
24-
/**
25-
* @todo Remove this method once we found a better way to avoid creating event objects
26-
* that are expensive to create when there are no subscribers registered for them
27-
*
28-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
29-
*/
30-
public function seal(): void;
3123
}

src/Event/Emitter/DispatchingEmitter.php

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ final class DispatchingEmitter implements Emitter
3131
private readonly Telemetry\System $system;
3232
private readonly Telemetry\Snapshot $startSnapshot;
3333
private Telemetry\Snapshot $previousSnapshot;
34-
private bool $emitAssertionSucceededEvents = false;
35-
private bool $emitAssertionFailedEvents = false;
3634

3735
public function __construct(Dispatcher $dispatcher, Telemetry\System $system)
3836
{
@@ -43,50 +41,6 @@ public function __construct(Dispatcher $dispatcher, Telemetry\System $system)
4341
$this->previousSnapshot = $system->snapshot();
4442
}
4543

46-
/**
47-
* @todo Remove this method once we found a better way to avoid creating event objects
48-
* that are expensive to create when there are no subscribers registered for them
49-
*
50-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
51-
*/
52-
public function emitAssertionSucceededEvents(): void
53-
{
54-
$this->emitAssertionSucceededEvents = true;
55-
}
56-
57-
/**
58-
* @todo Remove this method once we found a better way to avoid creating event objects
59-
* that are expensive to create when there are no subscribers registered for them
60-
*
61-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
62-
*/
63-
public function emitsAssertionSucceededEvents(): bool
64-
{
65-
return $this->emitAssertionSucceededEvents;
66-
}
67-
68-
/**
69-
* @todo Remove this method once we found a better way to avoid creating event objects
70-
* that are expensive to create when there are no subscribers registered for them
71-
*
72-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
73-
*/
74-
public function emitAssertionFailedEvents(): void
75-
{
76-
$this->emitAssertionFailedEvents = true;
77-
}
78-
79-
/**
80-
* @todo Remove this method once we found a better way to avoid creating event objects
81-
* that are expensive to create when there are no subscribers registered for them
82-
*
83-
* @see https://github.com/sebastianbergmann/phpunit/issues/5261
84-
*/
85-
public function emitsAssertionFailedEvents(): bool
86-
{
87-
return $this->emitAssertionFailedEvents;
88-
}
89-
9044
/**
9145
* @throws InvalidArgumentException
9246
* @throws UnknownEventTypeException
@@ -446,14 +400,10 @@ public function testRegisteredComparator(string $className): void
446400
*/
447401
public function testAssertionSucceeded(mixed $value, Constraint\Constraint $constraint, string $message): void
448402
{
449-
if (!$this->emitAssertionSucceededEvents) {
450-
return;
451-
}
452-
453403
$this->dispatcher->dispatch(
454404
new Test\AssertionSucceeded(
455405
$this->telemetryInfo(),
456-
(new Exporter)->export($value),
406+
'',
457407
$constraint->toString(),
458408
$constraint->count(),
459409
$message,
@@ -467,10 +417,6 @@ public function testAssertionSucceeded(mixed $value, Constraint\Constraint $cons
467417
*/
468418
public function testAssertionFailed(mixed $value, Constraint\Constraint $constraint, string $message): void
469419
{
470-
if (!$this->emitAssertionFailedEvents) {
471-
return;
472-
}
473-
474420
$this->dispatcher->dispatch(
475421
new Test\AssertionFailed(
476422
$this->telemetryInfo(),

src/Event/Events/Test/Assertion/AssertionSucceeded.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
final class AssertionSucceeded implements Event
2020
{
2121
private readonly Telemetry\Info $telemetryInfo;
22-
private readonly string $value;
2322
private readonly string $constraint;
2423
private readonly int $count;
2524
private readonly string $message;
2625

2726
public function __construct(Telemetry\Info $telemetryInfo, string $value, string $constraint, int $count, string $message)
2827
{
2928
$this->telemetryInfo = $telemetryInfo;
30-
$this->value = $value;
3129
$this->constraint = $constraint;
3230
$this->count = $count;
3331
$this->message = $message;
@@ -38,9 +36,12 @@ public function telemetryInfo(): Telemetry\Info
3836
return $this->telemetryInfo;
3937
}
4038

39+
/**
40+
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/5183
41+
*/
4142
public function value(): string
4243
{
43-
return $this->value;
44+
return '';
4445
}
4546

4647
public function count(): int
@@ -65,9 +66,8 @@ public function asString(): string
6566
}
6667

6768
return sprintf(
68-
'Assertion Succeeded (Constraint: %s, Value: %s%s)',
69+
'Assertion Succeeded (Constraint: %s%s)',
6970
$this->constraint,
70-
$this->value,
7171
$message
7272
);
7373
}

src/Event/Facade.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function emitter(): Emitter
6868
}
6969

7070
/** @noinspection PhpUnused */
71-
public static function initForIsolation(HRTime $offset, bool $emitAssertionSucceededEvents, bool $emitAssertionFailedEvents): CollectingDispatcher
71+
public static function initForIsolation(HRTime $offset): CollectingDispatcher
7272
{
7373
$dispatcher = new CollectingDispatcher;
7474

@@ -80,14 +80,6 @@ public static function initForIsolation(HRTime $offset, bool $emitAssertionSucce
8080
)
8181
);
8282

83-
if ($emitAssertionSucceededEvents) {
84-
self::$emitter->emitAssertionSucceededEvents();
85-
}
86-
87-
if ($emitAssertionFailedEvents) {
88-
self::$emitter->emitAssertionFailedEvents();
89-
}
90-
9183
self::$sealed = true;
9284

9385
return $dispatcher;
@@ -108,7 +100,6 @@ public static function forward(EventCollection $events): void
108100

109101
public static function seal(): void
110102
{
111-
self::deferredDispatcher()->seal();
112103
self::deferredDispatcher()->flush();
113104

114105
self::$sealed = true;

src/Framework/TestRunner.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,6 @@ public function runInSeparateProcess(TestCase $test, bool $runEntireClass, bool
272272
$includedFiles = '';
273273
$iniSettings = '';
274274

275-
$emitter = Event\Facade::emitter();
276-
277-
assert($emitter instanceof Event\DispatchingEmitter);
278-
279-
$emitAssertionSucceededEvents = $emitter->emitsAssertionSucceededEvents() ? 'true' : 'false';
280-
$emitAssertionFailedEvents = $emitter->emitsAssertionFailedEvents() ? 'true' : 'false';
281-
282275
if (ConfigurationRegistry::get()->hasBootstrap()) {
283276
$bootstrap = ConfigurationRegistry::get()->bootstrap();
284277
}
@@ -338,8 +331,6 @@ public function runInSeparateProcess(TestCase $test, bool $runEntireClass, bool
338331
'offsetSeconds' => $offset[0],
339332
'offsetNanoseconds' => $offset[1],
340333
'serializedConfiguration' => $serializedConfiguration,
341-
'emitAssertionSucceededEvents' => $emitAssertionSucceededEvents,
342-
'emitAssertionFailedEvents' => $emitAssertionFailedEvents,
343334
];
344335

345336
if (!$runEntireClass) {

src/Util/PHP/Template/TestCaseClass.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function __phpunit_run_isolated_test()
3737
PHPUnit\Event\Telemetry\HRTime::fromSecondsAndNanoseconds(
3838
{offsetSeconds},
3939
{offsetNanoseconds}
40-
),
41-
{emitAssertionSucceededEvents},
42-
{emitAssertionFailedEvents}
40+
)
4341
);
4442

4543
require_once '{filename}';

src/Util/PHP/Template/TestCaseMethod.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function __phpunit_run_isolated_test()
3737
PHPUnit\Event\Telemetry\HRTime::fromSecondsAndNanoseconds(
3838
{offsetSeconds},
3939
{offsetNanoseconds}
40-
),
41-
{emitAssertionSucceededEvents},
42-
{emitAssertionFailedEvents}
40+
)
4341
);
4442

4543
require_once '{filename}';

tests/end-to-end/event/invalid-coverage-metadata.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Test Suite Started (default, 1 test)
4040
Test Suite Started (PHPUnit\TestFixture\Event\InvalidCoverageMetadata\InvalidCoverageMetadataTest, 1 test)
4141
Test Preparation Started (PHPUnit\TestFixture\Event\InvalidCoverageMetadata\InvalidCoverageMetadataTest::testOne)
4242
Test Prepared (PHPUnit\TestFixture\Event\InvalidCoverageMetadata\InvalidCoverageMetadataTest::testOne)
43-
Assertion Succeeded (Constraint: is true, Value: true)
43+
Assertion Succeeded (Constraint: is true)
4444
Test Passed (PHPUnit\TestFixture\Event\InvalidCoverageMetadata\InvalidCoverageMetadataTest::testOne)
4545
Test Triggered PHPUnit Warning (PHPUnit\TestFixture\Event\InvalidCoverageMetadata\InvalidCoverageMetadataTest::testOne)
4646
Class "PHPUnit\TestFixture\Event\InvalidCoverageMetadata\This\Does\Not\Exist" is not a valid target for code coverage

0 commit comments

Comments
 (0)