Skip to content

Commit f3247fd

Browse files
committed
bug #60500 [PhpUnitBridge] Fix cleaning up mocked features with attributes (HypeMC)
This PR was merged into the 7.3 branch. Discussion ---------- [PhpUnitBridge] Fix cleaning up mocked features with attributes | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Fixes usage of the attributes introduced in #59384 to reflect changes made in #60484. Commits ------- 62da782 [PhpUnitBridge] Fix cleaning up mocked features with attributes
2 parents 5bddd3f + 62da782 commit f3247fd

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

.github/workflows/phpunit-bridge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
php-version: "7.2"
3636

3737
- name: Lint
38-
run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait | parallel -j 4 php -l {}
38+
run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait -e SymfonyExtension | parallel -j 4 php -l {}

src/Symfony/Bridge/PhpUnit/SymfonyExtension.php

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use PHPUnit\Runner\Extension\Facade;
2727
use PHPUnit\Runner\Extension\ParameterCollection;
2828
use PHPUnit\TextUI\Configuration\Configuration;
29+
use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive;
30+
use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive;
2931
use Symfony\Bridge\PhpUnit\Extension\EnableClockMockSubscriber;
3032
use Symfony\Bridge\PhpUnit\Extension\RegisterClockMockSubscriber;
3133
use Symfony\Bridge\PhpUnit\Extension\RegisterDnsMockSubscriber;
@@ -50,35 +52,51 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
5052

5153
$facade->registerSubscriber(new RegisterClockMockSubscriber($reader));
5254
$facade->registerSubscriber(new EnableClockMockSubscriber($reader));
53-
$facade->registerSubscriber(new class implements ErroredSubscriber {
55+
$facade->registerSubscriber(new class($reader) implements ErroredSubscriber {
56+
public function __construct(private AttributeReader $reader)
57+
{
58+
}
59+
5460
public function notify(Errored $event): void
5561
{
56-
SymfonyExtension::disableClockMock($event->test());
57-
SymfonyExtension::disableDnsMock($event->test());
62+
SymfonyExtension::disableClockMock($event->test(), $this->reader);
63+
SymfonyExtension::disableDnsMock($event->test(), $this->reader);
5864
}
5965
});
60-
$facade->registerSubscriber(new class implements FinishedSubscriber {
66+
$facade->registerSubscriber(new class($reader) implements FinishedSubscriber {
67+
public function __construct(private AttributeReader $reader)
68+
{
69+
}
70+
6171
public function notify(Finished $event): void
6272
{
63-
SymfonyExtension::disableClockMock($event->test());
64-
SymfonyExtension::disableDnsMock($event->test());
73+
SymfonyExtension::disableClockMock($event->test(), $this->reader);
74+
SymfonyExtension::disableDnsMock($event->test(), $this->reader);
6575
}
6676
});
67-
$facade->registerSubscriber(new class implements SkippedSubscriber {
77+
$facade->registerSubscriber(new class($reader) implements SkippedSubscriber {
78+
public function __construct(private AttributeReader $reader)
79+
{
80+
}
81+
6882
public function notify(Skipped $event): void
6983
{
70-
SymfonyExtension::disableClockMock($event->test());
71-
SymfonyExtension::disableDnsMock($event->test());
84+
SymfonyExtension::disableClockMock($event->test(), $this->reader);
85+
SymfonyExtension::disableDnsMock($event->test(), $this->reader);
7286
}
7387
});
7488

7589
if (interface_exists(BeforeTestMethodErroredSubscriber::class)) {
76-
$facade->registerSubscriber(new class implements BeforeTestMethodErroredSubscriber {
90+
$facade->registerSubscriber(new class($reader) implements BeforeTestMethodErroredSubscriber {
91+
public function __construct(private AttributeReader $reader)
92+
{
93+
}
94+
7795
public function notify(BeforeTestMethodErrored $event): void
7896
{
7997
if (method_exists($event, 'test')) {
80-
SymfonyExtension::disableClockMock($event->test());
81-
SymfonyExtension::disableDnsMock($event->test());
98+
SymfonyExtension::disableClockMock($event->test(), $this->reader);
99+
SymfonyExtension::disableDnsMock($event->test(), $this->reader);
82100
} else {
83101
ClockMock::withClockMock(false);
84102
DnsMock::withMockedHosts([]);
@@ -99,27 +117,27 @@ public function notify(BeforeTestMethodErrored $event): void
99117
/**
100118
* @internal
101119
*/
102-
public static function disableClockMock(Test $test): void
120+
public static function disableClockMock(Test $test, AttributeReader $reader): void
103121
{
104-
if (self::hasGroup($test, 'time-sensitive')) {
122+
if (self::hasGroup($test, 'time-sensitive', $reader, TimeSensitive::class)) {
105123
ClockMock::withClockMock(false);
106124
}
107125
}
108126

109127
/**
110128
* @internal
111129
*/
112-
public static function disableDnsMock(Test $test): void
130+
public static function disableDnsMock(Test $test, AttributeReader $reader): void
113131
{
114-
if (self::hasGroup($test, 'dns-sensitive')) {
132+
if (self::hasGroup($test, 'dns-sensitive', $reader, DnsSensitive::class)) {
115133
DnsMock::withMockedHosts([]);
116134
}
117135
}
118136

119137
/**
120138
* @internal
121139
*/
122-
public static function hasGroup(Test $test, string $groupName): bool
140+
public static function hasGroup(Test $test, string $groupName, AttributeReader $reader, string $attribute): bool
123141
{
124142
if (!$test instanceof TestMethod) {
125143
return false;
@@ -131,6 +149,6 @@ public static function hasGroup(Test $test, string $groupName): bool
131149
}
132150
}
133151

134-
return false;
152+
return [] !== $reader->forClassAndMethod($test->className(), $test->methodName(), $attribute);
135153
}
136154
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy