Skip to content

Commit 6ac53c5

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: Review translations for Chinese (zh_TW) review translation messages(be) set path to the PHPUnit autoload file Update Turkish translation for Twig template validation message [PhpUnitBridge] Clean up mocked features only when group is present Remove translations for slug validation error add missing $extensions and $extensionsMessage to the Image constraint
2 parents d8a37b5 + 2836a02 commit 6ac53c5

File tree

4 files changed

+123
-12
lines changed

4 files changed

+123
-12
lines changed

SymfonyExtension.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Event\Code\Test;
15+
use PHPUnit\Event\Code\TestMethod;
1416
use PHPUnit\Event\Test\BeforeTestMethodErrored;
1517
use PHPUnit\Event\Test\BeforeTestMethodErroredSubscriber;
1618
use PHPUnit\Event\Test\Errored;
@@ -19,6 +21,7 @@
1921
use PHPUnit\Event\Test\FinishedSubscriber;
2022
use PHPUnit\Event\Test\Skipped;
2123
use PHPUnit\Event\Test\SkippedSubscriber;
24+
use PHPUnit\Metadata\Group;
2225
use PHPUnit\Runner\Extension\Extension;
2326
use PHPUnit\Runner\Extension\Facade;
2427
use PHPUnit\Runner\Extension\ParameterCollection;
@@ -50,31 +53,36 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
5053
$facade->registerSubscriber(new class implements ErroredSubscriber {
5154
public function notify(Errored $event): void
5255
{
53-
SymfonyExtension::disableClockMock();
54-
SymfonyExtension::disableDnsMock();
56+
SymfonyExtension::disableClockMock($event->test());
57+
SymfonyExtension::disableDnsMock($event->test());
5558
}
5659
});
5760
$facade->registerSubscriber(new class implements FinishedSubscriber {
5861
public function notify(Finished $event): void
5962
{
60-
SymfonyExtension::disableClockMock();
61-
SymfonyExtension::disableDnsMock();
63+
SymfonyExtension::disableClockMock($event->test());
64+
SymfonyExtension::disableDnsMock($event->test());
6265
}
6366
});
6467
$facade->registerSubscriber(new class implements SkippedSubscriber {
6568
public function notify(Skipped $event): void
6669
{
67-
SymfonyExtension::disableClockMock();
68-
SymfonyExtension::disableDnsMock();
70+
SymfonyExtension::disableClockMock($event->test());
71+
SymfonyExtension::disableDnsMock($event->test());
6972
}
7073
});
7174

7275
if (interface_exists(BeforeTestMethodErroredSubscriber::class)) {
7376
$facade->registerSubscriber(new class implements BeforeTestMethodErroredSubscriber {
7477
public function notify(BeforeTestMethodErrored $event): void
7578
{
76-
SymfonyExtension::disableClockMock();
77-
SymfonyExtension::disableDnsMock();
79+
if (method_exists($event, 'test')) {
80+
SymfonyExtension::disableClockMock($event->test());
81+
SymfonyExtension::disableDnsMock($event->test());
82+
} else {
83+
ClockMock::withClockMock(false);
84+
DnsMock::withMockedHosts([]);
85+
}
7886
}
7987
});
8088
}
@@ -91,16 +99,38 @@ public function notify(BeforeTestMethodErrored $event): void
9199
/**
92100
* @internal
93101
*/
94-
public static function disableClockMock(): void
102+
public static function disableClockMock(Test $test): void
95103
{
96-
ClockMock::withClockMock(false);
104+
if (self::hasGroup($test, 'time-sensitive')) {
105+
ClockMock::withClockMock(false);
106+
}
97107
}
98108

99109
/**
100110
* @internal
101111
*/
102-
public static function disableDnsMock(): void
112+
public static function disableDnsMock(Test $test): void
103113
{
104-
DnsMock::withMockedHosts([]);
114+
if (self::hasGroup($test, 'dns-sensitive')) {
115+
DnsMock::withMockedHosts([]);
116+
}
117+
}
118+
119+
/**
120+
* @internal
121+
*/
122+
public static function hasGroup(Test $test, string $groupName): bool
123+
{
124+
if (!$test instanceof TestMethod) {
125+
return false;
126+
}
127+
128+
foreach ($test->metadata() as $metadata) {
129+
if ($metadata instanceof Group && $groupName === $metadata->groupName()) {
130+
return true;
131+
}
132+
}
133+
134+
return false;
105135
}
106136
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ClockMock;
16+
use Symfony\Bridge\PhpUnit\DnsMock;
17+
18+
class SymfonyExtensionWithManualRegister extends TestCase
19+
{
20+
public static function setUpBeforeClass(): void
21+
{
22+
ClockMock::register(self::class);
23+
ClockMock::withClockMock(strtotime('2024-05-20 15:30:00'));
24+
25+
DnsMock::register(self::class);
26+
DnsMock::withMockedHosts([
27+
'example.com' => [
28+
['type' => 'A', 'ip' => '1.2.3.4'],
29+
],
30+
]);
31+
}
32+
33+
public static function tearDownAfterClass(): void
34+
{
35+
ClockMock::withClockMock(false);
36+
DnsMock::withMockedHosts([]);
37+
}
38+
39+
public function testDate()
40+
{
41+
self::assertSame('2024-05-20 15:30:00', date('Y-m-d H:i:s'));
42+
}
43+
44+
public function testGetHostByName()
45+
{
46+
self::assertSame('1.2.3.4', gethostbyname('example.com'));
47+
}
48+
49+
public function testTime()
50+
{
51+
self::assertSame(1716219000, time());
52+
}
53+
54+
public function testDnsGetRecord()
55+
{
56+
self::assertSame([[
57+
'host' => 'example.com',
58+
'class' => 'IN',
59+
'ttl' => 1,
60+
'type' => 'A',
61+
'ip' => '1.2.3.4',
62+
]], dns_get_record('example.com'));
63+
}
64+
}

Tests/symfonyextension.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if (!getenv('SYMFONY_PHPUNIT_VERSION') || version_compare(getenv('SYMFONY_PHPUNI
55
--FILE--
66
<?php
77
passthru(\sprintf('NO_COLOR=1 php %s/simple-phpunit.php -c %s/Fixtures/symfonyextension/phpunit-with-extension.xml.dist %s/SymfonyExtension.php', getenv('SYMFONY_SIMPLE_PHPUNIT_BIN_DIR'), __DIR__, __DIR__));
8+
echo PHP_EOL;
9+
passthru(\sprintf('NO_COLOR=1 php %s/simple-phpunit.php -c %s/Fixtures/symfonyextension/phpunit-with-extension.xml.dist %s/SymfonyExtensionWithManualRegister.php', getenv('SYMFONY_SIMPLE_PHPUNIT_BIN_DIR'), __DIR__, __DIR__));
810
--EXPECTF--
911
PHPUnit %s
1012

@@ -18,3 +20,14 @@ Time: %s, Memory: %s
1820

1921
OK, but there were issues!
2022
Tests: 76, Assertions: 76, Deprecations: 1.
23+
24+
PHPUnit %s
25+
26+
Runtime: PHP %s
27+
Configuration: %s/src/Symfony/Bridge/PhpUnit/Tests/Fixtures/symfonyextension/phpunit-with-extension.xml.dist
28+
29+
.... 4 / 4 (100%)
30+
31+
Time: %s, Memory: %s
32+
33+
OK (4 tests, 4 assertions)

bin/simple-phpunit.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
386386
$cmd .= '%2$s';
387387
}
388388

389+
if (version_compare($PHPUNIT_VERSION, '11.0', '>=')) {
390+
$GLOBALS['_composer_autoload_path'] = "$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/vendor/autoload.php";
391+
}
392+
389393
if ($components) {
390394
$skippedTests = $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] ?? false;
391395
$runningProcs = [];

0 commit comments

Comments
 (0)