From 2d32721e963dcd3fc1846feb556e8b4aebe65e0e Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Wed, 11 Dec 2024 14:08:35 +0100 Subject: [PATCH 01/40] chore: PHP CS Fixer fixes --- bin/simple-phpunit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index 0472e8c..843516c 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -110,7 +110,7 @@ } if (version_compare($PHPUNIT_VERSION, '10.0', '>=') && version_compare($PHPUNIT_VERSION, '11.0', '<')) { - fwrite(STDERR, 'This script does not work with PHPUnit 10.'.\PHP_EOL); + fwrite(\STDERR, 'This script does not work with PHPUnit 10.'.\PHP_EOL); exit(1); } From 84abc8a704a518156fcdfff5f4f5215fb5c62b52 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Tue, 7 Jan 2025 09:53:54 +0100 Subject: [PATCH 02/40] [PhpUnitBridge] Enable configuring mock ns with attributes --- Attribute/DnsSensitive.php | 21 ++ Attribute/TimeSensitive.php | 21 ++ CHANGELOG.md | 5 + Extension/DisableClockMockSubscriber.php | 12 ++ Extension/DisableDnsMockSubscriber.php | 12 ++ Extension/EnableClockMockSubscriber.php | 12 ++ Extension/RegisterClockMockSubscriber.php | 11 ++ Extension/RegisterDnsMockSubscriber.php | 11 ++ Metadata/AttributeReader.php | 78 ++++++++ SymfonyExtension.php | 13 +- .../symfonyextension/tests/bootstrap.php | 3 + Tests/Metadata/AttributeReaderTest.php | 96 +++++++++ Tests/Metadata/Fixtures/FooBar.php | 38 ++++ Tests/SymfonyExtension.php | 21 ++ Tests/symfonyextension.phpt | 5 +- Tests/symfonyextensionnotregistered.phpt | 187 +++++++++++++++++- 16 files changed, 536 insertions(+), 10 deletions(-) create mode 100644 Attribute/DnsSensitive.php create mode 100644 Attribute/TimeSensitive.php create mode 100644 Metadata/AttributeReader.php create mode 100644 Tests/Metadata/AttributeReaderTest.php create mode 100644 Tests/Metadata/Fixtures/FooBar.php diff --git a/Attribute/DnsSensitive.php b/Attribute/DnsSensitive.php new file mode 100644 index 0000000..4c80ec5 --- /dev/null +++ b/Attribute/DnsSensitive.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Attribute; + +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class DnsSensitive +{ + public function __construct( + public readonly ?string $class = null, + ) { + } +} diff --git a/Attribute/TimeSensitive.php b/Attribute/TimeSensitive.php new file mode 100644 index 0000000..da9e816 --- /dev/null +++ b/Attribute/TimeSensitive.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Attribute; + +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class TimeSensitive +{ + public function __construct( + public readonly ?string $class = null, + ) { + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c74702..dd7b418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.3 +--- + + * Enable configuring clock and DNS mock namespaces with attributes + 7.2 --- diff --git a/Extension/DisableClockMockSubscriber.php b/Extension/DisableClockMockSubscriber.php index 885e6ea..1de94db 100644 --- a/Extension/DisableClockMockSubscriber.php +++ b/Extension/DisableClockMockSubscriber.php @@ -15,13 +15,20 @@ use PHPUnit\Event\Test\Finished; use PHPUnit\Event\Test\FinishedSubscriber; use PHPUnit\Metadata\Group; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\ClockMock; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; /** * @internal */ class DisableClockMockSubscriber implements FinishedSubscriber { + public function __construct( + private AttributeReader $reader, + ) { + } + public function notify(Finished $event): void { $test = $event->test(); @@ -33,7 +40,12 @@ public function notify(Finished $event): void foreach ($test->metadata() as $metadata) { if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) { ClockMock::withClockMock(false); + break; } } + + if ($this->reader->forClassAndMethod($test->className(), $test->methodName(), TimeSensitive::class)) { + ClockMock::withClockMock(false); + } } } diff --git a/Extension/DisableDnsMockSubscriber.php b/Extension/DisableDnsMockSubscriber.php index fc3e754..29cdbbf 100644 --- a/Extension/DisableDnsMockSubscriber.php +++ b/Extension/DisableDnsMockSubscriber.php @@ -15,13 +15,20 @@ use PHPUnit\Event\Test\Finished; use PHPUnit\Event\Test\FinishedSubscriber; use PHPUnit\Metadata\Group; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; use Symfony\Bridge\PhpUnit\DnsMock; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; /** * @internal */ class DisableDnsMockSubscriber implements FinishedSubscriber { + public function __construct( + private AttributeReader $reader, + ) { + } + public function notify(Finished $event): void { $test = $event->test(); @@ -33,7 +40,12 @@ public function notify(Finished $event): void foreach ($test->metadata() as $metadata) { if ($metadata instanceof Group && 'dns-sensitive' === $metadata->groupName()) { DnsMock::withMockedHosts([]); + break; } } + + if ($this->reader->forClassAndMethod($test->className(), $test->methodName(), DnsSensitive::class)) { + DnsMock::withMockedHosts([]); + } } } diff --git a/Extension/EnableClockMockSubscriber.php b/Extension/EnableClockMockSubscriber.php index c10c5dc..b3d5633 100644 --- a/Extension/EnableClockMockSubscriber.php +++ b/Extension/EnableClockMockSubscriber.php @@ -15,13 +15,20 @@ use PHPUnit\Event\Test\PreparationStarted; use PHPUnit\Event\Test\PreparationStartedSubscriber; use PHPUnit\Metadata\Group; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\ClockMock; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; /** * @internal */ class EnableClockMockSubscriber implements PreparationStartedSubscriber { + public function __construct( + private AttributeReader $reader, + ) { + } + public function notify(PreparationStarted $event): void { $test = $event->test(); @@ -33,7 +40,12 @@ public function notify(PreparationStarted $event): void foreach ($test->metadata() as $metadata) { if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) { ClockMock::withClockMock(true); + break; } } + + if ($this->reader->forClassAndMethod($test->className(), $test->methodName(), TimeSensitive::class)) { + ClockMock::withClockMock(true); + } } } diff --git a/Extension/RegisterClockMockSubscriber.php b/Extension/RegisterClockMockSubscriber.php index e2955fe..b89f164 100644 --- a/Extension/RegisterClockMockSubscriber.php +++ b/Extension/RegisterClockMockSubscriber.php @@ -15,13 +15,20 @@ use PHPUnit\Event\TestSuite\Loaded; use PHPUnit\Event\TestSuite\LoadedSubscriber; use PHPUnit\Metadata\Group; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\ClockMock; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; /** * @internal */ class RegisterClockMockSubscriber implements LoadedSubscriber { + public function __construct( + private AttributeReader $reader, + ) { + } + public function notify(Loaded $event): void { foreach ($event->testSuite()->tests() as $test) { @@ -34,6 +41,10 @@ public function notify(Loaded $event): void ClockMock::register($test->className()); } } + + foreach ($this->reader->forClassAndMethod($test->className(), $test->methodName(), TimeSensitive::class) as $attribute) { + ClockMock::register($attribute->class ?? $test->className()); + } } } } diff --git a/Extension/RegisterDnsMockSubscriber.php b/Extension/RegisterDnsMockSubscriber.php index 81382d5..80e9a33 100644 --- a/Extension/RegisterDnsMockSubscriber.php +++ b/Extension/RegisterDnsMockSubscriber.php @@ -15,13 +15,20 @@ use PHPUnit\Event\TestSuite\Loaded; use PHPUnit\Event\TestSuite\LoadedSubscriber; use PHPUnit\Metadata\Group; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; use Symfony\Bridge\PhpUnit\DnsMock; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; /** * @internal */ class RegisterDnsMockSubscriber implements LoadedSubscriber { + public function __construct( + private AttributeReader $reader, + ) { + } + public function notify(Loaded $event): void { foreach ($event->testSuite()->tests() as $test) { @@ -34,6 +41,10 @@ public function notify(Loaded $event): void DnsMock::register($test->className()); } } + + foreach ($this->reader->forClassAndMethod($test->className(), $test->methodName(), DnsSensitive::class) as $attribute) { + DnsMock::register($attribute->class ?? $test->className()); + } } } } diff --git a/Metadata/AttributeReader.php b/Metadata/AttributeReader.php new file mode 100644 index 0000000..37f592a --- /dev/null +++ b/Metadata/AttributeReader.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Metadata; + +/** + * @template T of object + */ +final class AttributeReader +{ + /** + * @var array, list>> + */ + private array $cache = []; + + /** + * @param class-string $className + * @param class-string $name + * + * @return list + */ + public function forClass(string $className, string $name): array + { + $attributes = $this->cache[$className] ??= $this->readAttributes(new \ReflectionClass($className)); + + return $attributes[$name] ?? []; + } + + /** + * @param class-string $className + * @param class-string $name + * + * @return list + */ + public function forMethod(string $className, string $methodName, string $name): array + { + $attributes = $this->cache[$className.'::'.$methodName] ??= $this->readAttributes(new \ReflectionMethod($className, $methodName)); + + return $attributes[$name] ?? []; + } + + /** + * @param class-string $className + * @param class-string $name + * + * @return list + */ + public function forClassAndMethod(string $className, string $methodName, string $name): array + { + return [ + ...$this->forClass($className, $name), + ...$this->forMethod($className, $methodName, $name), + ]; + } + + private function readAttributes(\ReflectionClass|\ReflectionMethod $reflection): array + { + $attributeInstances = []; + + foreach ($reflection->getAttributes() as $attribute) { + if (!str_starts_with($name = $attribute->getName(), 'Symfony\\Bridge\\PhpUnit\\Attribute\\')) { + continue; + } + + $attributeInstances[$name][] = $attribute->newInstance(); + } + + return $attributeInstances; + } +} diff --git a/SymfonyExtension.php b/SymfonyExtension.php index 1df4f20..a21e462 100644 --- a/SymfonyExtension.php +++ b/SymfonyExtension.php @@ -20,6 +20,7 @@ use Symfony\Bridge\PhpUnit\Extension\EnableClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterDnsMockSubscriber; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; use Symfony\Component\ErrorHandler\DebugClassLoader; class SymfonyExtension implements Extension @@ -30,15 +31,17 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete DebugClassLoader::enable(); } + $reader = new AttributeReader(); + if ($parameters->has('clock-mock-namespaces')) { foreach (explode(',', $parameters->get('clock-mock-namespaces')) as $namespace) { ClockMock::register($namespace.'\DummyClass'); } } - $facade->registerSubscriber(new RegisterClockMockSubscriber()); - $facade->registerSubscriber(new EnableClockMockSubscriber()); - $facade->registerSubscriber(new DisableClockMockSubscriber()); + $facade->registerSubscriber(new RegisterClockMockSubscriber($reader)); + $facade->registerSubscriber(new EnableClockMockSubscriber($reader)); + $facade->registerSubscriber(new DisableClockMockSubscriber($reader)); if ($parameters->has('dns-mock-namespaces')) { foreach (explode(',', $parameters->get('dns-mock-namespaces')) as $namespace) { @@ -46,7 +49,7 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete } } - $facade->registerSubscriber(new RegisterDnsMockSubscriber()); - $facade->registerSubscriber(new DisableDnsMockSubscriber()); + $facade->registerSubscriber(new RegisterDnsMockSubscriber($reader)); + $facade->registerSubscriber(new DisableDnsMockSubscriber($reader)); } } diff --git a/Tests/Fixtures/symfonyextension/tests/bootstrap.php b/Tests/Fixtures/symfonyextension/tests/bootstrap.php index 95dcc78..3616e50 100644 --- a/Tests/Fixtures/symfonyextension/tests/bootstrap.php +++ b/Tests/Fixtures/symfonyextension/tests/bootstrap.php @@ -21,11 +21,14 @@ }); require __DIR__.'/../../../../SymfonyExtension.php'; +require __DIR__.'/../../../../Attribute/DnsSensitive.php'; +require __DIR__.'/../../../../Attribute/TimeSensitive.php'; require __DIR__.'/../../../../Extension/DisableClockMockSubscriber.php'; require __DIR__.'/../../../../Extension/DisableDnsMockSubscriber.php'; require __DIR__.'/../../../../Extension/EnableClockMockSubscriber.php'; require __DIR__.'/../../../../Extension/RegisterClockMockSubscriber.php'; require __DIR__.'/../../../../Extension/RegisterDnsMockSubscriber.php'; +require __DIR__.'/../../../../Metadata/AttributeReader.php'; if (file_exists(__DIR__.'/../../../../vendor/autoload.php')) { require __DIR__.'/../../../../vendor/autoload.php'; diff --git a/Tests/Metadata/AttributeReaderTest.php b/Tests/Metadata/AttributeReaderTest.php new file mode 100644 index 0000000..351a62a --- /dev/null +++ b/Tests/Metadata/AttributeReaderTest.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Tests\Metadata; + +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; +use Symfony\Bridge\PhpUnit\Metadata\AttributeReader; +use Symfony\Bridge\PhpUnit\Tests\Metadata\Fixtures\FooBar; + +/** + * @requires PHP 8.0 + */ +final class AttributeReaderTest extends TestCase +{ + /** + * @dataProvider provideReadCases + */ + public function testAttributesAreRead(string $method, string $attributeClass, array $expected) + { + $reader = new AttributeReader(); + + $attributes = $reader->forClassAndMethod(FooBar::class, $method, $attributeClass); + + self::assertContainsOnlyInstancesOf($attributeClass, $attributes); + self::assertSame($expected, array_column($attributes, 'class')); + } + + public static function provideReadCases(): iterable + { + yield ['testOne', DnsSensitive::class, [ + 'App\Foo\Bar\A', + 'App\Foo\Bar\B', + 'App\Foo\Baz\C', + ]]; + yield ['testTwo', DnsSensitive::class, [ + 'App\Foo\Bar\A', + 'App\Foo\Bar\B', + ]]; + yield ['testThree', DnsSensitive::class, [ + 'App\Foo\Bar\A', + 'App\Foo\Bar\B', + 'App\Foo\Corge\F', + ]]; + + yield ['testOne', TimeSensitive::class, [ + 'App\Foo\Bar\A', + ]]; + yield ['testTwo', TimeSensitive::class, [ + 'App\Foo\Bar\A', + 'App\Foo\Qux\D', + 'App\Foo\Qux\E', + ]]; + yield ['testThree', TimeSensitive::class, [ + 'App\Foo\Bar\A', + 'App\Foo\Corge\G', + ]]; + } + + public function testAttributesAreCached() + { + $reader = new AttributeReader(); + $cacheRef = new \ReflectionProperty(AttributeReader::class, 'cache'); + + self::assertEmpty($cacheRef->getValue($reader)); + + $reader->forClass(FooBar::class, TimeSensitive::class); + + self::assertCount(1, $cache = $cacheRef->getValue($reader)); + self::assertArrayHasKey(FooBar::class, $cache); + self::assertAttributesCount($cache[FooBar::class], 2, 1); + + $reader->forMethod(FooBar::class, 'testThree', DnsSensitive::class); + + self::assertCount(2, $cache = $cacheRef->getValue($reader)); + self::assertArrayHasKey($key = FooBar::class.'::testThree', $cache); + self::assertAttributesCount($cache[$key], 1, 1); + } + + private static function assertAttributesCount(array $attributes, int $expectedDnsCount, int $expectedTimeCount): void + { + self::assertArrayHasKey(DnsSensitive::class, $attributes); + self::assertCount($expectedDnsCount, $attributes[DnsSensitive::class]); + self::assertArrayHasKey(TimeSensitive::class, $attributes); + self::assertCount($expectedTimeCount, $attributes[TimeSensitive::class]); + } +} diff --git a/Tests/Metadata/Fixtures/FooBar.php b/Tests/Metadata/Fixtures/FooBar.php new file mode 100644 index 0000000..63b9d28 --- /dev/null +++ b/Tests/Metadata/Fixtures/FooBar.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Tests\Metadata\Fixtures; + +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; + +#[DnsSensitive('App\Foo\Bar\A')] +#[DnsSensitive('App\Foo\Bar\B')] +#[TimeSensitive('App\Foo\Bar\A')] +final class FooBar +{ + #[DnsSensitive('App\Foo\Baz\C')] + public function testOne() + { + } + + #[TimeSensitive('App\Foo\Qux\D')] + #[TimeSensitive('App\Foo\Qux\E')] + public function testTwo() + { + } + + #[DnsSensitive('App\Foo\Corge\F')] + #[TimeSensitive('App\Foo\Corge\G')] + public function testThree() + { + } +} diff --git a/Tests/SymfonyExtension.php b/Tests/SymfonyExtension.php index ac2d907..1219c27 100644 --- a/Tests/SymfonyExtension.php +++ b/Tests/SymfonyExtension.php @@ -14,9 +14,13 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\Tests\Fixtures\symfonyextension\src\ClassExtendingFinalClass; use Symfony\Bridge\PhpUnit\Tests\Fixtures\symfonyextension\src\FinalClass; +#[DnsSensitive('App\Foo\A')] +#[TimeSensitive('App\Foo\A')] class SymfonyExtension extends TestCase { public function testExtensionOfFinalClass() @@ -28,6 +32,7 @@ public function testExtensionOfFinalClass() #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testTimeMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\time', $namespace))); @@ -35,6 +40,7 @@ public function testTimeMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testMicrotimeMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\microtime', $namespace))); @@ -42,6 +48,7 @@ public function testMicrotimeMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testSleepMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\sleep', $namespace))); @@ -49,6 +56,7 @@ public function testSleepMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testUsleepMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\usleep', $namespace))); @@ -56,6 +64,7 @@ public function testUsleepMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testDateMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\date', $namespace))); @@ -63,6 +72,7 @@ public function testDateMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testGmdateMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\gmdate', $namespace))); @@ -70,6 +80,7 @@ public function testGmdateMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('time-sensitive')] + #[TimeSensitive('App\Bar\B')] public function testHrtimeMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\hrtime', $namespace))); @@ -77,6 +88,7 @@ public function testHrtimeMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testCheckdnsrrMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\checkdnsrr', $namespace))); @@ -84,6 +96,7 @@ public function testCheckdnsrrMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testDnsCheckRecordMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\dns_check_record', $namespace))); @@ -91,6 +104,7 @@ public function testDnsCheckRecordMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testGetmxrrMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\getmxrr', $namespace))); @@ -98,6 +112,7 @@ public function testGetmxrrMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testDnsGetMxMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\dns_get_mx', $namespace))); @@ -105,6 +120,7 @@ public function testDnsGetMxMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testGethostbyaddrMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\gethostbyaddr', $namespace))); @@ -112,6 +128,7 @@ public function testGethostbyaddrMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testGethostbynameMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\gethostbyname', $namespace))); @@ -119,6 +136,7 @@ public function testGethostbynameMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testGethostbynamelMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\gethostbynamel', $namespace))); @@ -126,6 +144,7 @@ public function testGethostbynamelMockIsRegistered(string $namespace) #[DataProvider('mockedNamespaces')] #[Group('dns-sensitive')] + #[DnsSensitive('App\Bar\B')] public function testDnsGetRecordMockIsRegistered(string $namespace) { $this->assertTrue(\function_exists(\sprintf('%s\dns_get_record', $namespace))); @@ -136,5 +155,7 @@ public static function mockedNamespaces(): iterable yield 'test class namespace' => [__NAMESPACE__]; yield 'namespace derived from test namespace' => ['Symfony\Bridge\PhpUnit']; yield 'explicitly configured namespace' => ['App']; + yield 'explicitly configured namespace through attribute on class' => ['App\Foo']; + yield 'explicitly configured namespace through attribute on method' => ['App\Bar']; } } diff --git a/Tests/symfonyextension.phpt b/Tests/symfonyextension.phpt index 2c808c2..933352f 100644 --- a/Tests/symfonyextension.phpt +++ b/Tests/symfonyextension.phpt @@ -11,9 +11,10 @@ PHPUnit %s Runtime: PHP %s Configuration: %s/src/Symfony/Bridge/PhpUnit/Tests/Fixtures/symfonyextension/phpunit-with-extension.xml.dist -D............................................. 46 / 46 (100%) +D................................................................ 65 / 76 ( 85%) +........... 76 / 76 (100%) Time: %s, Memory: %s OK, but there were issues! -Tests: 46, Assertions: 46, Deprecations: 1. +Tests: 76, Assertions: 76, Deprecations: 1. diff --git a/Tests/symfonyextensionnotregistered.phpt b/Tests/symfonyextensionnotregistered.phpt index aa3d4d3..e66b677 100644 --- a/Tests/symfonyextensionnotregistered.phpt +++ b/Tests/symfonyextensionnotregistered.phpt @@ -11,11 +11,12 @@ PHPUnit %s Runtime: PHP %s Configuration: %s/src/Symfony/Bridge/PhpUnit/Tests/Fixtures/symfonyextension/phpunit-without-extension.xml.dist -FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 46 / 46 (100%) +FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 65 / 76 ( 85%) +FFFFFFFFFFF 76 / 76 (100%) Time: %s, Memory: %s -There were 46 failures: +There were 76 failures: %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testExtensionOfFinalClass Expected deprecation with message "The "Symfony\Bridge\PhpUnit\Tests\Fixtures\symfonyextension\src\FinalClass" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Bridge\PhpUnit\Tests\Fixtures\symfonyextension\src\ClassExtendingFinalClass"." was not triggered @@ -40,6 +41,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -58,6 +71,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -76,6 +101,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -94,6 +131,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -112,6 +161,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -130,6 +191,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -148,6 +221,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -166,6 +251,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -184,6 +281,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -202,6 +311,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -220,6 +341,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -238,6 +371,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -256,6 +401,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -274,6 +431,18 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + %d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. @@ -292,5 +461,17 @@ Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +Failed asserting that false is true. + +%s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d +%s/.phpunit/phpunit-%s/phpunit:%d + FAILURES! -Tests: 46, Assertions: 46, Failures: 46. +Tests: 76, Assertions: 76, Failures: 76. From d05a6f15831e1ca71bc858a38cbcfcd000c056fc Mon Sep 17 00:00:00 2001 From: HypeMC Date: Sat, 11 Jan 2025 09:32:52 +0100 Subject: [PATCH 03/40] [PhpUnitBridge] Mark `AttributeReader` as internal --- Metadata/AttributeReader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Metadata/AttributeReader.php b/Metadata/AttributeReader.php index 37f592a..ca4e4c4 100644 --- a/Metadata/AttributeReader.php +++ b/Metadata/AttributeReader.php @@ -12,6 +12,8 @@ namespace Symfony\Bridge\PhpUnit\Metadata; /** + * @internal + * * @template T of object */ final class AttributeReader From 7964cd02c09e361eb7a81b0d7bf502429b472716 Mon Sep 17 00:00:00 2001 From: jwaguet <48832885+jwaguet@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:27:54 +0100 Subject: [PATCH 04/40] [PhpUnitBridge] Add CAA type in DnsMock --- CHANGELOG.md | 1 + DnsMock.php | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7b418..0b139af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Enable configuring clock and DNS mock namespaces with attributes + * Add support for CAA record type in DnsMock for improved DNS mocking capabilities 7.2 --- diff --git a/DnsMock.php b/DnsMock.php index c558cd0..84251c1 100644 --- a/DnsMock.php +++ b/DnsMock.php @@ -30,6 +30,7 @@ class DnsMock 'NAPTR' => \DNS_NAPTR, 'TXT' => \DNS_TXT, 'HINFO' => \DNS_HINFO, + 'CAA' => '\\' !== \DIRECTORY_SEPARATOR ? \DNS_CAA : 0, ]; /** From 962787c76a8b8f20da9505a70cf4fc3cb6b092d3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 3 Feb 2025 18:35:30 +0100 Subject: [PATCH 05/40] [Security] Improve BC-layer to deprecate eraseCredentials methods --- Legacy/SymfonyTestsListenerTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 2b45051..486d3bf 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -336,7 +336,7 @@ public static function handleError($type, $msg, $file, $line, $context = []) return $h ? $h($type, $msg, $file, $line, $context) : false; } - // If the message is serialized we need to extract the message. This occurs when the error is triggered by + // If the message is serialized we need to extract the message. This occurs when the error is triggered // by the isolated test path in \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest(). $parsedMsg = @unserialize($msg); if (\is_array($parsedMsg)) { From 3f154eaf26b84b1d6fcceb051b4f217d89eaca74 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 2 Mar 2025 16:03:52 +0100 Subject: [PATCH 06/40] replace assertEmpty() with stricter assertions --- Tests/Metadata/AttributeReaderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Metadata/AttributeReaderTest.php b/Tests/Metadata/AttributeReaderTest.php index 351a62a..b82a7ac 100644 --- a/Tests/Metadata/AttributeReaderTest.php +++ b/Tests/Metadata/AttributeReaderTest.php @@ -71,7 +71,7 @@ public function testAttributesAreCached() $reader = new AttributeReader(); $cacheRef = new \ReflectionProperty(AttributeReader::class, 'cache'); - self::assertEmpty($cacheRef->getValue($reader)); + self::assertSame([], $cacheRef->getValue($reader)); $reader->forClass(FooBar::class, TimeSensitive::class); From 93b590209fd3088dc526cb7e013cc475e8510213 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 13 Mar 2025 23:58:12 +0100 Subject: [PATCH 07/40] chore: PHP CS Fixer fixes --- bin/simple-phpunit.php | 2 +- bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index 843516c..5e50111 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -462,7 +462,7 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla } } } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) { - if (!class_exists(\SymfonyExcludeListSimplePhpunit::class, false)) { + if (!class_exists(SymfonyExcludeListSimplePhpunit::class, false)) { class SymfonyExcludeListSimplePhpunit { } diff --git a/bootstrap.php b/bootstrap.php index f11b7ab..5fddda1 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -21,7 +21,7 @@ } // Detect if we're loaded by an actual run of phpunit -if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists(\PHPUnit\TextUI\Command::class, false)) { +if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists(PHPUnit\TextUI\Command::class, false)) { return; } From 2eabda563921f21cbce1d1e3247b3c36568905e6 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 21 May 2025 14:00:46 +0200 Subject: [PATCH 08/40] [PhpUnitBridge] Fix cleaning up mocked features with attributes --- SymfonyExtension.php | 54 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/SymfonyExtension.php b/SymfonyExtension.php index f290a2c..05ff99a 100644 --- a/SymfonyExtension.php +++ b/SymfonyExtension.php @@ -26,6 +26,8 @@ use PHPUnit\Runner\Extension\Facade; use PHPUnit\Runner\Extension\ParameterCollection; use PHPUnit\TextUI\Configuration\Configuration; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\Extension\EnableClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterDnsMockSubscriber; @@ -50,35 +52,51 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete $facade->registerSubscriber(new RegisterClockMockSubscriber($reader)); $facade->registerSubscriber(new EnableClockMockSubscriber($reader)); - $facade->registerSubscriber(new class implements ErroredSubscriber { + $facade->registerSubscriber(new class($reader) implements ErroredSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Errored $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); - $facade->registerSubscriber(new class implements FinishedSubscriber { + $facade->registerSubscriber(new class($reader) implements FinishedSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Finished $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); - $facade->registerSubscriber(new class implements SkippedSubscriber { + $facade->registerSubscriber(new class($reader) implements SkippedSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Skipped $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); if (interface_exists(BeforeTestMethodErroredSubscriber::class)) { - $facade->registerSubscriber(new class implements BeforeTestMethodErroredSubscriber { + $facade->registerSubscriber(new class($reader) implements BeforeTestMethodErroredSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(BeforeTestMethodErrored $event): void { if (method_exists($event, 'test')) { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } else { ClockMock::withClockMock(false); DnsMock::withMockedHosts([]); @@ -99,9 +117,9 @@ public function notify(BeforeTestMethodErrored $event): void /** * @internal */ - public static function disableClockMock(Test $test): void + public static function disableClockMock(Test $test, AttributeReader $reader): void { - if (self::hasGroup($test, 'time-sensitive')) { + if (self::hasGroup($test, 'time-sensitive', $reader, TimeSensitive::class)) { ClockMock::withClockMock(false); } } @@ -109,9 +127,9 @@ public static function disableClockMock(Test $test): void /** * @internal */ - public static function disableDnsMock(Test $test): void + public static function disableDnsMock(Test $test, AttributeReader $reader): void { - if (self::hasGroup($test, 'dns-sensitive')) { + if (self::hasGroup($test, 'dns-sensitive', $reader, DnsSensitive::class)) { DnsMock::withMockedHosts([]); } } @@ -119,7 +137,7 @@ public static function disableDnsMock(Test $test): void /** * @internal */ - public static function hasGroup(Test $test, string $groupName): bool + public static function hasGroup(Test $test, string $groupName, AttributeReader $reader, string $attribute): bool { if (!$test instanceof TestMethod) { return false; @@ -131,6 +149,6 @@ public static function hasGroup(Test $test, string $groupName): bool } } - return false; + return [] !== $reader->forClassAndMethod($test->className(), $test->methodName(), $attribute); } } From 134e0b1d98c3ca3a9564c8c1e766d9dc8b2ce61e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 09/40] Allow Symfony ^8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index de9101f..169f0e6 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "symfony/deprecation-contracts": "^2.5|^3.0", - "symfony/error-handler": "^5.4|^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", "symfony/polyfill-php81": "^1.27" }, "conflict": { From b732d159fe96d122ed8248950de0a3366829e802 Mon Sep 17 00:00:00 2001 From: jprivet-dev Date: Thu, 15 May 2025 08:45:41 +0200 Subject: [PATCH 10/40] [PhpUnitBridge] Add `strtotime()` to `ClockMock` --- CHANGELOG.md | 5 +++++ ClockMock.php | 17 +++++++++++++++++ Tests/ClockMockTest.php | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b139af..579fd88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Add support for mocking the `strtotime()` function + 7.3 --- diff --git a/ClockMock.php b/ClockMock.php index 4cca8fc..7c76596 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -109,6 +109,18 @@ public static function hrtime($asNumber = false) return [(int) self::$now, (int) $ns]; } + /** + * @return false|int + */ + public static function strtotime(string $datetime, ?int $timestamp = null) + { + if (null === $timestamp) { + $timestamp = self::time(); + } + + return \strtotime($datetime, $timestamp); + } + public static function register($class): void { $self = static::class; @@ -161,6 +173,11 @@ function hrtime(\$asNumber = false) { return \\$self::hrtime(\$asNumber); } + +function strtotime(\$datetime, \$timestamp = null) +{ + return \\$self::strtotime(\$datetime, \$timestamp); +} EOPHP ); } diff --git a/Tests/ClockMockTest.php b/Tests/ClockMockTest.php index 7df7865..8424108 100644 --- a/Tests/ClockMockTest.php +++ b/Tests/ClockMockTest.php @@ -79,4 +79,9 @@ public function testHrTimeAsNumber() { $this->assertSame(1234567890125000000, hrtime(true)); } + + public function testStrToTime() + { + $this->assertSame(1234567890, strtotime('now')); + } } From ba6b753034e78f6316e47a2fbed1f4e6ad97d6e5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 10 Jul 2025 09:12:18 +0200 Subject: [PATCH 11/40] CS fixes --- DeprecationErrorHandler.php | 8 ++++---- DeprecationErrorHandler/Configuration.php | 14 +++++++------- DeprecationErrorHandler/Deprecation.php | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index c67eca0..49dbeb6 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -310,7 +310,7 @@ private function displayDeprecations($groups, $configuration) if ($configuration->shouldWriteToLogFile()) { if (false === $handle = @fopen($file = $configuration->getLogFile(), 'a')) { - throw new \InvalidArgumentException(sprintf('The configured log file "%s" is not writeable.', $file)); + throw new \InvalidArgumentException(\sprintf('The configured log file "%s" is not writeable.', $file)); } } else { $handle = fopen('php://output', 'w'); @@ -318,7 +318,7 @@ private function displayDeprecations($groups, $configuration) foreach ($groups as $group) { if ($this->deprecationGroups[$group]->count()) { - $deprecationGroupMessage = sprintf( + $deprecationGroupMessage = \sprintf( '%s deprecation notices (%d)', \in_array($group, ['direct', 'indirect', 'self'], true) ? "Remaining $group" : ucfirst($group), $this->deprecationGroups[$group]->count() @@ -337,7 +337,7 @@ private function displayDeprecations($groups, $configuration) uasort($notices, $cmp); foreach ($notices as $msg => $notice) { - fwrite($handle, sprintf("\n %sx: %s\n", $notice->count(), $msg)); + fwrite($handle, \sprintf("\n %sx: %s\n", $notice->count(), $msg)); $countsByCaller = $notice->getCountsByCaller(); arsort($countsByCaller); @@ -349,7 +349,7 @@ private function displayDeprecations($groups, $configuration) fwrite($handle, " ...\n"); break; } - fwrite($handle, sprintf(" %dx in %s\n", $count, preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method))); + fwrite($handle, \sprintf(" %dx in %s\n", $count, preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method))); } } } diff --git a/DeprecationErrorHandler/Configuration.php b/DeprecationErrorHandler/Configuration.php index 54182d2..108b637 100644 --- a/DeprecationErrorHandler/Configuration.php +++ b/DeprecationErrorHandler/Configuration.php @@ -76,10 +76,10 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput foreach ($thresholds as $group => $threshold) { if (!\in_array($group, $groups, true)) { - throw new \InvalidArgumentException(sprintf('Unrecognized threshold "%s", expected one of "%s".', $group, implode('", "', $groups))); + throw new \InvalidArgumentException(\sprintf('Unrecognized threshold "%s", expected one of "%s".', $group, implode('", "', $groups))); } if (!is_numeric($threshold)) { - throw new \InvalidArgumentException(sprintf('Threshold for group "%s" has invalid value "%s".', $group, $threshold)); + throw new \InvalidArgumentException(\sprintf('Threshold for group "%s" has invalid value "%s".', $group, $threshold)); } $this->thresholds[$group] = (int) $threshold; } @@ -111,17 +111,17 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput foreach ($verboseOutput as $group => $status) { if (!isset($this->verboseOutput[$group])) { - throw new \InvalidArgumentException(sprintf('Unsupported verbosity group "%s", expected one of "%s".', $group, implode('", "', array_keys($this->verboseOutput)))); + throw new \InvalidArgumentException(\sprintf('Unsupported verbosity group "%s", expected one of "%s".', $group, implode('", "', array_keys($this->verboseOutput)))); } $this->verboseOutput[$group] = $status; } if ($ignoreFile) { if (!is_file($ignoreFile)) { - throw new \InvalidArgumentException(sprintf('The ignoreFile "%s" does not exist.', $ignoreFile)); + throw new \InvalidArgumentException(\sprintf('The ignoreFile "%s" does not exist.', $ignoreFile)); } set_error_handler(static function ($t, $m) use ($ignoreFile, &$line) { - throw new \RuntimeException(sprintf('Invalid pattern found in "%s" on line "%d"', $ignoreFile, 1 + $line).substr($m, 12)); + throw new \RuntimeException(\sprintf('Invalid pattern found in "%s" on line "%d"', $ignoreFile, 1 + $line).substr($m, 12)); }); try { foreach (file($ignoreFile) as $line => $pattern) { @@ -147,7 +147,7 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput $this->baselineDeprecations[$baseline_deprecation->location][$baseline_deprecation->message] = $baseline_deprecation->count; } } else { - throw new \InvalidArgumentException(sprintf('The baselineFile "%s" does not exist.', $this->baselineFile)); + throw new \InvalidArgumentException(\sprintf('The baselineFile "%s" does not exist.', $this->baselineFile)); } } @@ -316,7 +316,7 @@ public static function fromUrlEncodedString($serializedConfiguration): self parse_str($serializedConfiguration, $normalizedConfiguration); foreach (array_keys($normalizedConfiguration) as $key) { if (!\in_array($key, ['max', 'disabled', 'verbose', 'quiet', 'ignoreFile', 'generateBaseline', 'baselineFile', 'logFile'], true)) { - throw new \InvalidArgumentException(sprintf('Unknown configuration option "%s".', $key)); + throw new \InvalidArgumentException(\sprintf('Unknown configuration option "%s".', $key)); } } diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php index 79cfa0c..f7a57f5 100644 --- a/DeprecationErrorHandler/Deprecation.php +++ b/DeprecationErrorHandler/Deprecation.php @@ -351,7 +351,7 @@ private function getPackage($path) } } - throw new \RuntimeException(sprintf('No vendors found for path "%s".', $path)); + throw new \RuntimeException(\sprintf('No vendors found for path "%s".', $path)); } /** From 0be807e438edb7f965f99786b6d18b4f75e9e400 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 10 Jul 2025 10:59:01 +0200 Subject: [PATCH 12/40] [PhpUnitBridge] Bump v7.4 to PHP >= 8.1 --- ClassExistsMock.php | 4 +- ClockMock.php | 2 +- ConstraintTrait.php | 7 +- CoverageListener.php | 8 +-- DeprecationErrorHandler.php | 4 +- DeprecationErrorHandler/Deprecation.php | 30 ++++----- DnsMock.php | 2 +- Legacy/{CommandForV7.php => CommandForV8.php} | 2 +- Legacy/ConstraintTraitForV7.php | 64 ------------------- Legacy/ExpectDeprecationTraitForV8_4.php | 6 +- Legacy/SymfonyTestsListenerTrait.php | 24 +++---- Tests/CoverageListenerTest.php | 2 +- .../ConfigurationTest.php | 8 +-- .../DeprecationGroupTest.php | 9 +++ .../DeprecationNoticeTest.php | 9 +++ .../DeprecationTest.php | 4 +- .../deprecation/deprecation.php | 9 +++ .../fake_app/AppService.php | 13 +++- .../fake_app/BarService.php | 9 +++ .../fake_app/ExtendsDeprecatedFromVendor.php | 9 +++ .../ExtendsDeprecatedClassFromOtherVendor.php | 9 +++ .../fake_vendor/acme/lib/PhpDeprecation.php | 9 +++ .../fake_vendor/acme/lib/SomeService.php | 13 +++- .../acme/lib/deprecation_riddled.php | 9 +++ .../fake_vendor/autoload.php | 9 +++ .../fake_vendor/bar/lib/AnotherService.php | 13 +++- .../fake_vendor/composer/autoload_real.php | 11 +++- .../fake_vendor/fcy/lib/DeprecatedClass.php | 9 +++ .../fake_vendor_bis/autoload.php | 9 +++ .../composer/autoload_real.php | 11 +++- .../foo/lib/SomeOtherService.php | 9 +++ .../DeprecationErrorHandler/generate_phar.php | 9 +++ .../php_deprecation_from_vendor_class.phpt | 2 - Tests/EnumExistsMockTest.php | 3 - Tests/Metadata/AttributeReaderTest.php | 5 +- TextUI/Command.php | 2 +- bin/simple-phpunit.php | 27 ++------ bootstrap.php | 14 ---- composer.json | 10 +-- 39 files changed, 229 insertions(+), 179 deletions(-) rename Legacy/{CommandForV7.php => CommandForV8.php} (97%) delete mode 100644 Legacy/ConstraintTraitForV7.php diff --git a/ClassExistsMock.php b/ClassExistsMock.php index 72ec51e..6158242 100644 --- a/ClassExistsMock.php +++ b/ClassExistsMock.php @@ -62,7 +62,7 @@ public static function trait_exists($name, $autoload = true): bool return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \trait_exists($name, $autoload); } - public static function enum_exists($name, $autoload = true):bool + public static function enum_exists($name, $autoload = true): bool { $name = ltrim($name, '\\'); @@ -77,7 +77,7 @@ public static function register($class): void if (0 < strpos($class, '\\Tests\\')) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); - } elseif (0 === strpos($class, 'Tests\\')) { + } elseif (str_starts_with($class, 'Tests\\')) { $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); } foreach ($mockedNs as $ns) { diff --git a/ClockMock.php b/ClockMock.php index 7c76596..9a9c910 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -129,7 +129,7 @@ public static function register($class): void if (0 < strpos($class, '\\Tests\\')) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); - } elseif (0 === strpos($class, 'Tests\\')) { + } elseif (str_starts_with($class, 'Tests\\')) { $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); } foreach ($mockedNs as $ns) { diff --git a/ConstraintTrait.php b/ConstraintTrait.php index ceb6041..9090cc4 100644 --- a/ConstraintTrait.php +++ b/ConstraintTrait.php @@ -14,12 +14,7 @@ use PHPUnit\Framework\Constraint\Constraint; $r = new \ReflectionClass(Constraint::class); -if ($r->getProperty('exporter')->isProtected()) { - trait ConstraintTrait - { - use Legacy\ConstraintTraitForV7; - } -} elseif (!$r->getMethod('evaluate')->hasReturnType()) { +if (!$r->getMethod('evaluate')->hasReturnType()) { trait ConstraintTrait { use Legacy\ConstraintTraitForV8; diff --git a/CoverageListener.php b/CoverageListener.php index 65d6aa9..c7c70c9 100644 --- a/CoverageListener.php +++ b/CoverageListener.php @@ -29,7 +29,7 @@ class CoverageListener implements TestListener public function __construct(?callable $sutFqcnResolver = null, bool $warningOnSutNotFound = false) { $this->sutFqcnResolver = $sutFqcnResolver ?? static function (Test $test): ?string { - $class = \get_class($test); + $class = $test::class; $sutFqcn = str_replace('\\Tests\\', '\\', $class); $sutFqcn = preg_replace('{Test$}', '', $sutFqcn); @@ -46,7 +46,7 @@ public function startTest(Test $test): void return; } - $annotations = TestUtil::parseTestMethodAnnotations(\get_class($test), $test->getName(false)); + $annotations = TestUtil::parseTestMethodAnnotations($test::class, $test->getName(false)); $ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing']; @@ -90,7 +90,7 @@ private function addCoversForClassToAnnotationCache(Test $test, array $covers): $cache = $r->getValue(); $cache = array_replace_recursive($cache, [ - \get_class($test) => [ + $test::class => [ 'covers' => $covers, ], ]); @@ -100,7 +100,7 @@ private function addCoversForClassToAnnotationCache(Test $test, array $covers): private function addCoversForDocBlockInsideRegistry(Test $test, array $covers): void { - $docBlock = Registry::getInstance()->forClassName(\get_class($test)); + $docBlock = Registry::getInstance()->forClassName($test::class); $symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations'); $symbolAnnotations->setAccessible(true); diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index e597908..01bb653 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -97,7 +97,7 @@ public static function collectDeprecations($outputFile) { $deprecations = []; $previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) { - if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) { + if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) { if ($previousErrorHandler) { return $previousErrorHandler($type, $msg, $file, $line, $context); } @@ -129,7 +129,7 @@ public static function collectDeprecations($outputFile) */ public function handleError($type, $msg, $file, $line, $context = []) { - if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) { + if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) { return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php index 822e980..6a1315f 100644 --- a/DeprecationErrorHandler/Deprecation.php +++ b/DeprecationErrorHandler/Deprecation.php @@ -99,7 +99,7 @@ public function __construct(string $message, array $trace, string $file, bool $l $this->getOriginalFilesStack(); array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]); - if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (false === strpos($message, '()" will return') && false === strpos($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) { + if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (!str_contains($message, '()" will return') && !str_contains($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) { $this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName(); array_unshift($this->originalFilesStack, $this->triggeringFile); } @@ -137,7 +137,7 @@ public function __construct(string $message, array $trace, string $file, bool $l return; } - if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) { + if (!isset($line['class'], $trace[$i - 2]['function']) || !str_starts_with($line['class'], SymfonyTestsListenerFor::class)) { $this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class']; $this->originMethod = $line['function']; @@ -147,7 +147,7 @@ public function __construct(string $message, array $trace, string $file, bool $l $test = $line['args'][0] ?? null; if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) { - $this->originClass = \get_class($test); + $this->originClass = $test::class; $this->originMethod = $test->getName(); } } @@ -159,7 +159,7 @@ private function lineShouldBeSkipped(array $line): bool } $class = $line['class']; - return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\'); + return 'ReflectionMethod' === $class || str_starts_with($class, 'PHPUnit\\'); } public function originatesFromDebugClassLoader(): bool @@ -189,7 +189,7 @@ public function originatingClass(): string $class = $this->originClass; - return false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class; + return str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class; } public function originatingMethod(): string @@ -215,9 +215,9 @@ public function isLegacy(): bool $method = $this->originatingMethod(); $groups = class_exists(Groups::class, false) ? [new Groups(), 'groups'] : [Test::class, 'getGroups']; - return 0 === strpos($method, 'testLegacy') - || 0 === strpos($method, 'provideLegacy') - || 0 === strpos($method, 'getLegacy') + return str_starts_with($method, 'testLegacy') + || str_starts_with($method, 'provideLegacy') + || str_starts_with($method, 'getLegacy') || strpos($this->originClass, '\Legacy') || \in_array('legacy', $groups($this->originClass, $method), true); } @@ -228,10 +228,10 @@ public function isMuted(): bool return false; } if (isset($this->trace[1]['class'])) { - return 0 === strpos($this->trace[1]['class'], 'PHPUnit\\'); + return str_starts_with($this->trace[1]['class'], 'PHPUnit\\'); } - return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR); + return str_contains($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR); } /** @@ -300,7 +300,7 @@ private function getPackage(string $path): string { $path = realpath($path) ?: $path; foreach (self::getVendors() as $vendorRoot) { - if (0 === strpos($path, $vendorRoot)) { + if (str_starts_with($path, $vendorRoot)) { $relativePath = substr($path, \strlen($vendorRoot) + 1); $vendor = strstr($relativePath, \DIRECTORY_SEPARATOR, true); if (false === $vendor) { @@ -326,7 +326,7 @@ private static function getVendors(): array self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName()); } foreach (get_declared_classes() as $class) { - if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { + if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) { $r = new \ReflectionClass($class); $v = \dirname($r->getFileName(), 2); if (file_exists($v.'/composer/installed.json')) { @@ -341,7 +341,7 @@ private static function getVendors(): array } foreach ($paths as $path) { foreach (self::$vendors as $vendor) { - if (0 !== strpos($path, $vendor)) { + if (!str_starts_with($path, $vendor)) { self::$internalPaths[] = $path; } } @@ -371,13 +371,13 @@ private function getPathType(string $path): string return self::PATH_TYPE_UNDETERMINED; } foreach (self::getVendors() as $vendor) { - if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { + if (str_starts_with($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { return self::PATH_TYPE_VENDOR; } } foreach (self::$internalPaths as $internalPath) { - if (0 === strpos($realPath, $internalPath)) { + if (str_starts_with($realPath, $internalPath)) { return self::PATH_TYPE_SELF; } } diff --git a/DnsMock.php b/DnsMock.php index 84251c1..bc2ac1a 100644 --- a/DnsMock.php +++ b/DnsMock.php @@ -170,7 +170,7 @@ public static function register($class): void if (0 < strpos($class, '\\Tests\\')) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); - } elseif (0 === strpos($class, 'Tests\\')) { + } elseif (str_starts_with($class, 'Tests\\')) { $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); } foreach ($mockedNs as $ns) { diff --git a/Legacy/CommandForV7.php b/Legacy/CommandForV8.php similarity index 97% rename from Legacy/CommandForV7.php rename to Legacy/CommandForV8.php index 99a1e68..ffeb2b8 100644 --- a/Legacy/CommandForV7.php +++ b/Legacy/CommandForV8.php @@ -19,7 +19,7 @@ /** * @internal */ -class CommandForV7 extends BaseCommand +class CommandForV8 extends BaseCommand { protected function createRunner(): BaseRunner { diff --git a/Legacy/ConstraintTraitForV7.php b/Legacy/ConstraintTraitForV7.php deleted file mode 100644 index b132f47..0000000 --- a/Legacy/ConstraintTraitForV7.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\PhpUnit\Legacy; - -use SebastianBergmann\Exporter\Exporter; - -/** - * @internal - */ -trait ConstraintTraitForV7 -{ - use ConstraintLogicTrait; - - /** - * @return bool|null - */ - public function evaluate($other, $description = '', $returnResult = false) - { - return $this->doEvaluate($other, $description, $returnResult); - } - - public function count(): int - { - return $this->doCount(); - } - - public function toString(): string - { - return $this->doToString(); - } - - protected function additionalFailureDescription($other): string - { - return $this->doAdditionalFailureDescription($other); - } - - protected function exporter(): Exporter - { - if (null === $this->exporter) { - $this->exporter = new Exporter(); - } - - return $this->exporter; - } - - protected function failureDescription($other): string - { - return $this->doFailureDescription($other); - } - - protected function matches($other): bool - { - return $this->doMatches($other); - } -} diff --git a/Legacy/ExpectDeprecationTraitForV8_4.php b/Legacy/ExpectDeprecationTraitForV8_4.php index d159635..95823c2 100644 --- a/Legacy/ExpectDeprecationTraitForV8_4.php +++ b/Legacy/ExpectDeprecationTraitForV8_4.php @@ -22,7 +22,7 @@ trait ExpectDeprecationTraitForV8_4 public function expectDeprecation(): void { if (1 > \func_num_args() || !\is_string($message = func_get_arg(0))) { - throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__)); + throw new \InvalidArgumentException(\sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__)); } // Expected deprecations set by isolated tests need to be written to a file @@ -52,7 +52,7 @@ public function expectDeprecation(): void */ public function expectDeprecationMessage(string $message): void { - throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__)); + throw new \BadMethodCallException(\sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__)); } /** @@ -60,6 +60,6 @@ public function expectDeprecationMessage(string $message): void */ public function expectDeprecationMessageMatches(string $regularExpression): void { - throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__)); + throw new \BadMethodCallException(\sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__)); } } diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 486d3bf..07c5264 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -57,7 +57,7 @@ public function __construct(array $mockedNamespaces = []) (new ExcludeList())->getExcludedDirectories(); ExcludeList::addDirectory(\dirname((new \ReflectionClass(__CLASS__))->getFileName(), 2)); } elseif (method_exists(Blacklist::class, 'addDirectory')) { - (new BlackList())->getBlacklistedDirectories(); + (new Blacklist())->getBlacklistedDirectories(); Blacklist::addDirectory(\dirname((new \ReflectionClass(__CLASS__))->getFileName(), 2)); } else { Blacklist::$blacklistedClassNames[__CLASS__] = 2; @@ -124,7 +124,7 @@ public function startTestSuite($suite): void if (!$test instanceof TestCase) { continue; } - if (null === Test::getPreserveGlobalStateSettings(\get_class($test), $test->getName(false))) { + if (null === Test::getPreserveGlobalStateSettings($test::class, $test->getName(false))) { $test->setPreserveGlobalState(false); } } @@ -181,7 +181,7 @@ public function startTestSuite($suite): void continue; } if ($test instanceof TestCase - && isset($this->wasSkipped[\get_class($test)][$test->getName()]) + && isset($this->wasSkipped[$test::class][$test->getName()]) ) { $skipped[] = $test; } @@ -196,10 +196,10 @@ public function addSkippedTest($test, \Exception $e, $time): void if (0 < $this->state) { if ($test instanceof DataProviderTestSuite) { foreach ($test->tests() as $testWithDataProvider) { - $this->isSkipped[\get_class($testWithDataProvider)][$testWithDataProvider->getName()] = 1; + $this->isSkipped[$testWithDataProvider::class][$testWithDataProvider->getName()] = 1; } } else { - $this->isSkipped[\get_class($test)][$test->getName()] = 1; + $this->isSkipped[$test::class][$test->getName()] = 1; } } } @@ -214,15 +214,15 @@ public function startTest($test): void putenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE='.tempnam(sys_get_temp_dir(), 'expectdeprec')); } - $groups = Test::getGroups(\get_class($test), $test->getName(false)); + $groups = Test::getGroups($test::class, $test->getName(false)); if (!$this->runsInSeparateProcess) { if (\in_array('time-sensitive', $groups, true)) { - ClockMock::register(\get_class($test)); + ClockMock::register($test::class); ClockMock::withClockMock(true); } if (\in_array('dns-sensitive', $groups, true)) { - DnsMock::register(\get_class($test)); + DnsMock::register($test::class); } } @@ -230,7 +230,7 @@ public function startTest($test): void return; } - $annotations = Test::parseTestMethodAnnotations(\get_class($test), $test->getName(false)); + $annotations = Test::parseTestMethodAnnotations($test::class, $test->getName(false)); if (isset($annotations['class']['expectedDeprecation'])) { $test->getTestResultObject()->addError($test, new AssertionFailedError('"@expectedDeprecation" annotations are not allowed at the class level.'), 0); @@ -268,14 +268,14 @@ public function endTest($test, $time): void DebugClassLoader::checkClasses(); } - $className = \get_class($test); + $className = $test::class; $groups = Test::getGroups($className, $test->getName(false)); if ($this->checkNumAssertions) { $assertions = \count(self::$expectedDeprecations) + $test->getNumAssertions(); if ($test->doesNotPerformAssertions() && $assertions > 0) { - $test->getTestResultObject()->addFailure($test, new RiskyTestError(sprintf('This test is annotated with "@doesNotPerformAssertions", but performed %s assertions', $assertions)), $time); - } elseif ($assertions === 0 && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) { + $test->getTestResultObject()->addFailure($test, new RiskyTestError(\sprintf('This test is annotated with "@doesNotPerformAssertions", but performed %s assertions', $assertions)), $time); + } elseif (0 === $assertions && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) { $test->getTestResultObject()->addFailure($test, new RiskyTestError('This test did not perform any assertions'), $time); } diff --git a/Tests/CoverageListenerTest.php b/Tests/CoverageListenerTest.php index 99d4a4b..54cfcdd 100644 --- a/Tests/CoverageListenerTest.php +++ b/Tests/CoverageListenerTest.php @@ -34,7 +34,7 @@ public function test() exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output); $output = implode("\n", $output); - if (false === strpos($output, 'FooCov')) { + if (!str_contains($output, 'FooCov')) { $this->addToAssertionCount(1); } else { $this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+0.00%[^\n]+Lines:\s+0.00%/', $output); diff --git a/Tests/DeprecationErrorHandler/ConfigurationTest.php b/Tests/DeprecationErrorHandler/ConfigurationTest.php index 7eec029..e9c83d2 100644 --- a/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -245,7 +245,7 @@ public function testToleratesForIndividualGroups(string $deprecationsHelper, arr $groups = $this->buildGroups($deprecationsPerType); foreach ($expected as $groupName => $tolerates) { - $this->assertSame($tolerates, $configuration->toleratesForGroup($groupName, $groups), sprintf('Deprecation type "%s" is %s', $groupName, $tolerates ? 'tolerated' : 'not tolerated')); + $this->assertSame($tolerates, $configuration->toleratesForGroup($groupName, $groups), \sprintf('Deprecation type "%s" is %s', $groupName, $tolerates ? 'tolerated' : 'not tolerated')); } } @@ -515,7 +515,7 @@ public function testBaselineFileException() $filename = $this->createFile(); unlink($filename); $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf('The baselineFile "%s" does not exist.', $filename)); + $this->expectExceptionMessage(\sprintf('The baselineFile "%s" does not exist.', $filename)); Configuration::fromUrlEncodedString('baselineFile='.urlencode($filename)); } @@ -529,7 +529,7 @@ public function testBaselineFileWriteError() $this->expectExceptionMessageMatches('/[Ff]ailed to open stream: Permission denied/'); set_error_handler(static function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null): bool { - if ($errno & (E_WARNING | E_WARNING)) { + if ($errno & (\E_WARNING | \E_WARNING)) { throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); } @@ -595,7 +595,7 @@ public function testIgnoreFileException() $filename = $this->createFile(); unlink($filename); $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf('The ignoreFile "%s" does not exist.', $filename)); + $this->expectExceptionMessage(\sprintf('The ignoreFile "%s" does not exist.', $filename)); Configuration::fromUrlEncodedString('ignoreFile='.urlencode($filename)); } diff --git a/Tests/DeprecationErrorHandler/DeprecationGroupTest.php b/Tests/DeprecationErrorHandler/DeprecationGroupTest.php index df746e5..6b55820 100644 --- a/Tests/DeprecationErrorHandler/DeprecationGroupTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationGroupTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler; use PHPUnit\Framework\TestCase; diff --git a/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php b/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php index c0a88c4..fe4c456 100644 --- a/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler; use PHPUnit\Framework\TestCase; diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 4c17a80..0b7fa17 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -28,7 +28,7 @@ private static function getVendorDir() } foreach (get_declared_classes() as $class) { - if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { + if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) { $r = new \ReflectionClass($class); $vendorDir = \dirname($r->getFileName(), 2); if (file_exists($vendorDir.'/composer/installed.json') && @mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true)) { @@ -268,7 +268,7 @@ private static function removeDir($dir) public static function setUpBeforeClass(): void { foreach (get_declared_classes() as $class) { - if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { + if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) { $r = new \ReflectionClass($class); $v = \dirname($r->getFileName(), 2); if (file_exists($v.'/composer/installed.json')) { diff --git a/Tests/DeprecationErrorHandler/deprecation/deprecation.php b/Tests/DeprecationErrorHandler/deprecation/deprecation.php index 92efd95..0ea3e5c 100644 --- a/Tests/DeprecationErrorHandler/deprecation/deprecation.php +++ b/Tests/DeprecationErrorHandler/deprecation/deprecation.php @@ -1,3 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + @trigger_error('I come from… afar! :D', \E_USER_DEPRECATED); diff --git a/Tests/DeprecationErrorHandler/fake_app/AppService.php b/Tests/DeprecationErrorHandler/fake_app/AppService.php index 2b6cb31..b8f6dc2 100644 --- a/Tests/DeprecationErrorHandler/fake_app/AppService.php +++ b/Tests/DeprecationErrorHandler/fake_app/AppService.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace App\Services; use acme\lib\SomeService; @@ -20,9 +29,9 @@ public function selfDeprecation(bool $useContracts = false) { $args = [__FUNCTION__, __FUNCTION__]; if ($useContracts) { - trigger_deprecation('App', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args)); + trigger_deprecation('App', '3.0', \sprintf('%s is deprecated, use %s_new instead.', ...$args)); } else { - @trigger_error(sprintf('Since App 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); + @trigger_error(\sprintf('Since App 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); } } diff --git a/Tests/DeprecationErrorHandler/fake_app/BarService.php b/Tests/DeprecationErrorHandler/fake_app/BarService.php index 868de5b..5e0d66c 100644 --- a/Tests/DeprecationErrorHandler/fake_app/BarService.php +++ b/Tests/DeprecationErrorHandler/fake_app/BarService.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace App\Services; use acme\lib\ExtendsDeprecatedClassFromOtherVendor; diff --git a/Tests/DeprecationErrorHandler/fake_app/ExtendsDeprecatedFromVendor.php b/Tests/DeprecationErrorHandler/fake_app/ExtendsDeprecatedFromVendor.php index b4305e0..2105c3c 100644 --- a/Tests/DeprecationErrorHandler/fake_app/ExtendsDeprecatedFromVendor.php +++ b/Tests/DeprecationErrorHandler/fake_app/ExtendsDeprecatedFromVendor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace App\Services; use fcy\lib\DeprecatedClass; diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/ExtendsDeprecatedClassFromOtherVendor.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/ExtendsDeprecatedClassFromOtherVendor.php index f748109..600faca 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/ExtendsDeprecatedClassFromOtherVendor.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/ExtendsDeprecatedClassFromOtherVendor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace acme\lib; use fcy\lib\DeprecatedClass; diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/PhpDeprecation.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/PhpDeprecation.php index 26a3237..e38211b 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/PhpDeprecation.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/PhpDeprecation.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace acme\lib; class PhpDeprecation implements \Serializable diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/SomeService.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/SomeService.php index cc237e6..6064426 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/SomeService.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/SomeService.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace acme\lib; use bar\lib\AnotherService; @@ -10,9 +19,9 @@ public function deprecatedApi(bool $useContracts = false) { $args = [__FUNCTION__, __FUNCTION__]; if ($useContracts) { - trigger_deprecation('acme/lib', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args)); + trigger_deprecation('acme/lib', '3.0', \sprintf('%s is deprecated, use %s_new instead.', ...$args)); } else { - @trigger_error(sprintf('Since acme/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); + @trigger_error(\sprintf('Since acme/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); } } diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php index c6507d7..5784566 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + eval(<<<'EOPHP' namespace PHPUnit\Util; diff --git a/Tests/DeprecationErrorHandler/fake_vendor/autoload.php b/Tests/DeprecationErrorHandler/fake_vendor/autoload.php index 3c4471b..68db330 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/autoload.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/autoload.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + require_once __DIR__.'/composer/autoload_real.php'; return ComposerAutoloaderInitFake::getLoader(); diff --git a/Tests/DeprecationErrorHandler/fake_vendor/bar/lib/AnotherService.php b/Tests/DeprecationErrorHandler/fake_vendor/bar/lib/AnotherService.php index 2e2f0f9..2724186 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/bar/lib/AnotherService.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/bar/lib/AnotherService.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace bar\lib; class AnotherService @@ -8,9 +17,9 @@ public function deprecatedApi(bool $useContracts = false) { $args = [__FUNCTION__, __FUNCTION__]; if ($useContracts) { - trigger_deprecation('bar/lib', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args)); + trigger_deprecation('bar/lib', '3.0', \sprintf('%s is deprecated, use %s_new instead.', ...$args)); } else { - @trigger_error(sprintf('Since bar/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); + @trigger_error(\sprintf('Since bar/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED); } } } diff --git a/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php b/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php index 4b80d96..231ae4f 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + class ComposerLoaderFake { public function getPrefixes() @@ -27,7 +36,7 @@ public function loadClass($className) public function findFile($class) { foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) { - if (0 !== strpos($class, $prefix)) { + if (!str_starts_with($class, $prefix)) { continue; } diff --git a/Tests/DeprecationErrorHandler/fake_vendor/fcy/lib/DeprecatedClass.php b/Tests/DeprecationErrorHandler/fake_vendor/fcy/lib/DeprecatedClass.php index f6672ce..16edcaf 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/fcy/lib/DeprecatedClass.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/fcy/lib/DeprecatedClass.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace fcy\lib; /** diff --git a/Tests/DeprecationErrorHandler/fake_vendor_bis/autoload.php b/Tests/DeprecationErrorHandler/fake_vendor_bis/autoload.php index c1c9639..f1aec32 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor_bis/autoload.php +++ b/Tests/DeprecationErrorHandler/fake_vendor_bis/autoload.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + require_once __DIR__.'/composer/autoload_real.php'; return ComposerAutoloaderInitFakeBis::getLoader(); diff --git a/Tests/DeprecationErrorHandler/fake_vendor_bis/composer/autoload_real.php b/Tests/DeprecationErrorHandler/fake_vendor_bis/composer/autoload_real.php index aabb103..2a52065 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor_bis/composer/autoload_real.php +++ b/Tests/DeprecationErrorHandler/fake_vendor_bis/composer/autoload_real.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + class ComposerLoaderFakeBis { public function getPrefixes() @@ -17,7 +26,7 @@ public function getPrefixesPsr4() public function loadClass($className) { foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) { - if (0 !== strpos($className, $prefix)) { + if (!str_starts_with($className, $prefix)) { continue; } diff --git a/Tests/DeprecationErrorHandler/fake_vendor_bis/foo/lib/SomeOtherService.php b/Tests/DeprecationErrorHandler/fake_vendor_bis/foo/lib/SomeOtherService.php index 8ab3230..d9c67b1 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor_bis/foo/lib/SomeOtherService.php +++ b/Tests/DeprecationErrorHandler/fake_vendor_bis/foo/lib/SomeOtherService.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace foo\lib; class SomeOtherService diff --git a/Tests/DeprecationErrorHandler/generate_phar.php b/Tests/DeprecationErrorHandler/generate_phar.php index 75125d5..df87511 100644 --- a/Tests/DeprecationErrorHandler/generate_phar.php +++ b/Tests/DeprecationErrorHandler/generate_phar.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + $phar = new Phar(__DIR__.\DIRECTORY_SEPARATOR.'deprecation.phar', 0, 'deprecation.phar'); $phar->buildFromDirectory(__DIR__.\DIRECTORY_SEPARATOR.'deprecation'); diff --git a/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt b/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt index 1ead2ef..3048efb 100644 --- a/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt +++ b/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt @@ -1,7 +1,5 @@ --TEST-- Test that a PHP deprecation from a vendor class autoload is considered indirect. ---SKIPIF-- - --FILE-- = 80000) { - $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6'; -} else { - $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.5') ?: '8.5'; -} +$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6'; $MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false); @@ -178,7 +174,7 @@ $prevCacheDir = false; } } -$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : '')); +$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'); $SYMFONY_PHPUNIT_REQUIRE = $getEnvVar('SYMFONY_PHPUNIT_REQUIRE', ''); $configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, $SYMFONY_PHPUNIT_REQUIRE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT])); $PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT); @@ -240,9 +236,6 @@ if ($SYMFONY_PHPUNIT_REQUIRE) { $passthruOrFail("$COMPOSER require --no-update ".$SYMFONY_PHPUNIT_REQUIRE); } - if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { - $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); - } if (preg_match('{\^((\d++\.)\d++)[\d\.]*$}', $info['requires']['php'], $phpVersion) && version_compare($phpVersion[2].'99', \PHP_VERSION, '<')) { $passthruOrFail("$COMPOSER config platform.php \"$phpVersion[1].99\""); @@ -267,9 +260,8 @@ } $prevRoot = getenv('COMPOSER_ROOT_VERSION'); putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); - $q = '\\' === \DIRECTORY_SEPARATOR && \PHP_VERSION_ID < 80000 ? '"' : ''; // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS - $exit = proc_close(proc_open("$q$COMPOSER update --no-dev --prefer-dist --no-progress $q", [], $p, getcwd())); + $exit = proc_close(proc_open("$COMPOSER update --no-dev --prefer-dist --no-progress", [], $p, getcwd())); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($prevCacheDir) { putenv("COMPOSER_CACHE_DIR=$prevCacheDir"); @@ -340,16 +332,7 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla } chdir($oldPwd); -if ($PHPUNIT_VERSION < 8.0) { - $argv = array_filter($argv, function ($v) use (&$argc) { - if ('--do-not-cache-result' !== $v) { - return true; - } - --$argc; - - return false; - }); -} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) { +if (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) { $argv[] = '--do-not-cache-result'; ++$argc; } diff --git a/bootstrap.php b/bootstrap.php index 24d5934..5540904 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Deprecations\Deprecation; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; @@ -35,19 +34,6 @@ if (class_exists(Deprecation::class)) { Deprecation::withoutDeduplication(); - - if (\PHP_VERSION_ID < 80000) { - // Ignore deprecations about the annotation mapping driver when it's not possible to move to the attribute driver yet - Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issues/10098'); - } -} - -if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) { - if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { - AnnotationRegistry::registerUniqueLoader('class_exists'); - } elseif (method_exists(AnnotationRegistry::class, 'registerLoader')) { - AnnotationRegistry::registerLoader('class_exists'); - } } if ( diff --git a/composer.json b/composer.json index 169f0e6..b9dda6b 100644 --- a/composer.json +++ b/composer.json @@ -18,17 +18,13 @@ } ], "require": { - "php": ">=7.2.5 EVEN ON LATEST SYMFONY VERSIONS TO ALLOW USING", + "php": ">=8.1.0 EVEN ON LATEST SYMFONY VERSIONS TO ALLOW USING", "php": "THIS BRIDGE WHEN TESTING LOWEST SYMFONY VERSIONS.", - "php": ">=7.2.5" + "php": ">=8.1.0" }, "require-dev": { "symfony/deprecation-contracts": "^2.5|^3.0", - "symfony/error-handler": "^6.4|^7.0|^8.0", - "symfony/polyfill-php81": "^1.27" - }, - "conflict": { - "phpunit/phpunit": "<7.5|9.1.2" + "symfony/error-handler": "^6.4.3|^7.0.3|^8.0" }, "autoload": { "files": [ "bootstrap.php" ], From 2d07490a989904860949068924c75b74e3dbf949 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Wed, 23 Jul 2025 01:48:30 +0700 Subject: [PATCH 13/40] [Form][PhpUnitBridge] Remove usage of noop `ReflectionProperty::setAccessible()` --- CoverageListener.php | 2 -- DeprecationErrorHandler/Deprecation.php | 1 - Legacy/SymfonyTestsListenerTrait.php | 1 - Tests/DeprecationErrorHandler/DeprecationTest.php | 1 - 4 files changed, 5 deletions(-) diff --git a/CoverageListener.php b/CoverageListener.php index 65d6aa9..e9fea92 100644 --- a/CoverageListener.php +++ b/CoverageListener.php @@ -86,7 +86,6 @@ public function startTest(Test $test): void private function addCoversForClassToAnnotationCache(Test $test, array $covers): void { $r = new \ReflectionProperty(TestUtil::class, 'annotationCache'); - $r->setAccessible(true); $cache = $r->getValue(); $cache = array_replace_recursive($cache, [ @@ -103,7 +102,6 @@ private function addCoversForDocBlockInsideRegistry(Test $test, array $covers): $docBlock = Registry::getInstance()->forClassName(\get_class($test)); $symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations'); - $symbolAnnotations->setAccessible(true); // Exclude internal classes; PHPUnit 9.1+ is picky about tests covering, say, a \RuntimeException $covers = array_filter($covers, function (string $class) { diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php index f7a57f5..710ef60 100644 --- a/DeprecationErrorHandler/Deprecation.php +++ b/DeprecationErrorHandler/Deprecation.php @@ -437,7 +437,6 @@ public function toString() { $exception = new \Exception($this->message); $reflection = new \ReflectionProperty($exception, 'trace'); - $reflection->setAccessible(true); $reflection->setValue($exception, $this->trace); return ($this->originatesFromAnObject() ? 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().":\n" : '') diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 2b45051..d058d9b 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -357,7 +357,6 @@ private function willBeIsolated(TestCase $test): bool } $r = new \ReflectionProperty($test, 'runTestInSeparateProcess'); - $r->setAccessible(true); return $r->getValue($test) ?? false; } diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 4c17a80..85e0104 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -275,7 +275,6 @@ public static function setUpBeforeClass(): void $loader = require $v.'/autoload.php'; $reflection = new \ReflectionClass($loader); $prop = $reflection->getProperty('prefixDirsPsr4'); - $prop->setAccessible(true); $currentValue = $prop->getValue($loader); self::$prefixDirsPsr4[] = [$prop, $loader, $currentValue]; $currentValue['Symfony\\Bridge\\PhpUnit\\'] = [realpath(__DIR__.'/../..')]; From c7bd97db095cb2f560b675e3fa0ae5ca6a2e5f59 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 24 Jul 2025 13:44:59 +0200 Subject: [PATCH 14/40] add back setAccessible() for PHP 7 compatibility --- CoverageListener.php | 2 ++ DeprecationErrorHandler/Deprecation.php | 1 + Legacy/SymfonyTestsListenerTrait.php | 1 + Tests/DeprecationErrorHandler/DeprecationTest.php | 1 + 4 files changed, 5 insertions(+) diff --git a/CoverageListener.php b/CoverageListener.php index e9fea92..65d6aa9 100644 --- a/CoverageListener.php +++ b/CoverageListener.php @@ -86,6 +86,7 @@ public function startTest(Test $test): void private function addCoversForClassToAnnotationCache(Test $test, array $covers): void { $r = new \ReflectionProperty(TestUtil::class, 'annotationCache'); + $r->setAccessible(true); $cache = $r->getValue(); $cache = array_replace_recursive($cache, [ @@ -102,6 +103,7 @@ private function addCoversForDocBlockInsideRegistry(Test $test, array $covers): $docBlock = Registry::getInstance()->forClassName(\get_class($test)); $symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations'); + $symbolAnnotations->setAccessible(true); // Exclude internal classes; PHPUnit 9.1+ is picky about tests covering, say, a \RuntimeException $covers = array_filter($covers, function (string $class) { diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php index 710ef60..f7a57f5 100644 --- a/DeprecationErrorHandler/Deprecation.php +++ b/DeprecationErrorHandler/Deprecation.php @@ -437,6 +437,7 @@ public function toString() { $exception = new \Exception($this->message); $reflection = new \ReflectionProperty($exception, 'trace'); + $reflection->setAccessible(true); $reflection->setValue($exception, $this->trace); return ($this->originatesFromAnObject() ? 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().":\n" : '') diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index d058d9b..2b45051 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -357,6 +357,7 @@ private function willBeIsolated(TestCase $test): bool } $r = new \ReflectionProperty($test, 'runTestInSeparateProcess'); + $r->setAccessible(true); return $r->getValue($test) ?? false; } diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 85e0104..4c17a80 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -275,6 +275,7 @@ public static function setUpBeforeClass(): void $loader = require $v.'/autoload.php'; $reflection = new \ReflectionClass($loader); $prop = $reflection->getProperty('prefixDirsPsr4'); + $prop->setAccessible(true); $currentValue = $prop->getValue($loader); self::$prefixDirsPsr4[] = [$prop, $loader, $currentValue]; $currentValue['Symfony\\Bridge\\PhpUnit\\'] = [realpath(__DIR__.'/../..')]; From 6f802233b486131d8c23d3d88e6e6a9e091a133b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Oct 2024 11:06:51 +0200 Subject: [PATCH 15/40] run tests using PHPUnit 11.5 --- Tests/CoverageListenerTest.php | 5 ++--- Tests/DeprecationErrorHandler/ConfigurationTest.php | 5 ++--- Tests/ExpectDeprecationTraitTest.php | 5 ++--- Tests/ExpectedDeprecationAnnotationTest.php | 5 ++--- Tests/FailTests/ExpectDeprecationTraitTestFail.php | 4 ++-- Tests/FailTests/NoAssertionsTestNotRisky.php | 4 ++-- Tests/FailTests/NoAssertionsTestRisky.php | 4 ++-- Tests/ProcessIsolationTest.php | 4 ++-- phpunit.xml.dist | 7 ++++--- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Tests/CoverageListenerTest.php b/Tests/CoverageListenerTest.php index 54cfcdd..9d6e26e 100644 --- a/Tests/CoverageListenerTest.php +++ b/Tests/CoverageListenerTest.php @@ -11,11 +11,10 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; -/** - * @requires PHPUnit < 10 - */ +#[RequiresPhpunit('<10')] class CoverageListenerTest extends TestCase { public function test() diff --git a/Tests/DeprecationErrorHandler/ConfigurationTest.php b/Tests/DeprecationErrorHandler/ConfigurationTest.php index e9c83d2..741c1a5 100644 --- a/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -11,12 +11,14 @@ namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup; use Symfony\Component\ErrorHandler\DebugClassLoader; +#[RequiresPhpunit('<10')] class ConfigurationTest extends TestCase { private $files; @@ -463,9 +465,6 @@ public function testExistingBaselineAndGeneration() $this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename)); } - /** - * @requires PHPUnit < 10 - */ public function testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader() { $filename = $this->createFile(); diff --git a/Tests/ExpectDeprecationTraitTest.php b/Tests/ExpectDeprecationTraitTest.php index 9adeca4..142d3f8 100644 --- a/Tests/ExpectDeprecationTraitTest.php +++ b/Tests/ExpectDeprecationTraitTest.php @@ -11,12 +11,11 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; -/** - * @requires PHPUnit < 10 - */ +#[RequiresPhpunit('<10')] final class ExpectDeprecationTraitTest extends TestCase { use ExpectDeprecationTrait; diff --git a/Tests/ExpectedDeprecationAnnotationTest.php b/Tests/ExpectedDeprecationAnnotationTest.php index 1db5448..6e7ba0b 100644 --- a/Tests/ExpectedDeprecationAnnotationTest.php +++ b/Tests/ExpectedDeprecationAnnotationTest.php @@ -11,11 +11,10 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; -/** - * @requires PHPUnit < 10 - */ +#[RequiresPhpunit('<10')] final class ExpectedDeprecationAnnotationTest extends TestCase { /** diff --git a/Tests/FailTests/ExpectDeprecationTraitTestFail.php b/Tests/FailTests/ExpectDeprecationTraitTestFail.php index 7bf40df..a43fe30 100644 --- a/Tests/FailTests/ExpectDeprecationTraitTestFail.php +++ b/Tests/FailTests/ExpectDeprecationTraitTestFail.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests\FailTests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; @@ -19,9 +20,8 @@ * * This class is deliberately suffixed with *TestFail.php so that it is ignored * by PHPUnit. This test is designed to fail. See ../expectdeprecationfail.phpt. - * - * @requires PHPUnit < 10 */ +#[RequiresPhpunit('<10')] final class ExpectDeprecationTraitTestFail extends TestCase { use ExpectDeprecationTrait; diff --git a/Tests/FailTests/NoAssertionsTestNotRisky.php b/Tests/FailTests/NoAssertionsTestNotRisky.php index 8008287..bd259a5 100644 --- a/Tests/FailTests/NoAssertionsTestNotRisky.php +++ b/Tests/FailTests/NoAssertionsTestNotRisky.php @@ -11,15 +11,15 @@ namespace Symfony\Bridge\PhpUnit\Tests\FailTests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * This class is deliberately suffixed with *TestRisky.php so that it is ignored * by PHPUnit. This test is designed to fail. See ../expectnotrisky.phpt. - * - * @requires PHPUnit < 10 */ +#[RequiresPhpunit('<10')] final class NoAssertionsTestNotRisky extends TestCase { use ExpectDeprecationTrait; diff --git a/Tests/FailTests/NoAssertionsTestRisky.php b/Tests/FailTests/NoAssertionsTestRisky.php index 5ec1375..601506a 100644 --- a/Tests/FailTests/NoAssertionsTestRisky.php +++ b/Tests/FailTests/NoAssertionsTestRisky.php @@ -11,15 +11,15 @@ namespace Symfony\Bridge\PhpUnit\Tests\FailTests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * This class is deliberately suffixed with *TestRisky.php so that it is ignored * by PHPUnit. This test is designed to fail. See ../expectrisky.phpt. - * - * @requires PHPUnit < 10 */ +#[RequiresPhpunit('<10')] final class NoAssertionsTestRisky extends TestCase { use ExpectDeprecationTrait; diff --git a/Tests/ProcessIsolationTest.php b/Tests/ProcessIsolationTest.php index 07fb9a2..b517fe5 100644 --- a/Tests/ProcessIsolationTest.php +++ b/Tests/ProcessIsolationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; /** @@ -19,9 +20,8 @@ * @group legacy * * @runTestsInSeparateProcesses - * - * @requires PHPUnit < 10 */ +#[RequiresPhpunit('<10')] class ProcessIsolationTest extends TestCase { /** diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cde576e..7e31059 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -19,7 +20,7 @@ - + ./ @@ -27,5 +28,5 @@ ./Tests ./vendor - + From ddce87db4f5c12fcff191f294f3b70125b333038 Mon Sep 17 00:00:00 2001 From: W0rma Date: Sat, 2 Aug 2025 13:32:54 +0200 Subject: [PATCH 16/40] Reflection*::setAccessible() has no effect as of PHP 8.1 --- CoverageListener.php | 8 ++++++-- DeprecationErrorHandler/Deprecation.php | 4 +++- Legacy/SymfonyTestsListenerTrait.php | 4 +++- Tests/DeprecationErrorHandler/DeprecationTest.php | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CoverageListener.php b/CoverageListener.php index 65d6aa9..f1a89ff 100644 --- a/CoverageListener.php +++ b/CoverageListener.php @@ -86,7 +86,9 @@ public function startTest(Test $test): void private function addCoversForClassToAnnotationCache(Test $test, array $covers): void { $r = new \ReflectionProperty(TestUtil::class, 'annotationCache'); - $r->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $r->setAccessible(true); + } $cache = $r->getValue(); $cache = array_replace_recursive($cache, [ @@ -103,7 +105,9 @@ private function addCoversForDocBlockInsideRegistry(Test $test, array $covers): $docBlock = Registry::getInstance()->forClassName(\get_class($test)); $symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations'); - $symbolAnnotations->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $symbolAnnotations->setAccessible(true); + } // Exclude internal classes; PHPUnit 9.1+ is picky about tests covering, say, a \RuntimeException $covers = array_filter($covers, function (string $class) { diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php index f7a57f5..082509f 100644 --- a/DeprecationErrorHandler/Deprecation.php +++ b/DeprecationErrorHandler/Deprecation.php @@ -437,7 +437,9 @@ public function toString() { $exception = new \Exception($this->message); $reflection = new \ReflectionProperty($exception, 'trace'); - $reflection->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $reflection->setAccessible(true); + } $reflection->setValue($exception, $this->trace); return ($this->originatesFromAnObject() ? 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().":\n" : '') diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 2b45051..13d9abc 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -357,7 +357,9 @@ private function willBeIsolated(TestCase $test): bool } $r = new \ReflectionProperty($test, 'runTestInSeparateProcess'); - $r->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $r->setAccessible(true); + } return $r->getValue($test) ?? false; } diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 4c17a80..2a7643a 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -275,7 +275,9 @@ public static function setUpBeforeClass(): void $loader = require $v.'/autoload.php'; $reflection = new \ReflectionClass($loader); $prop = $reflection->getProperty('prefixDirsPsr4'); - $prop->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $prop->setAccessible(true); + } $currentValue = $prop->getValue($loader); self::$prefixDirsPsr4[] = [$prop, $loader, $currentValue]; $currentValue['Symfony\\Bridge\\PhpUnit\\'] = [realpath(__DIR__.'/../..')]; From 1bd1a50b2cd9e5dd9e445363e3847b25770066dd Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 31 Jul 2025 14:36:46 +0200 Subject: [PATCH 17/40] replace PHPUnit annotations with attributes --- Tests/ClockMockTest.php | 2 ++ Tests/DeprecationErrorHandler/ConfigurationTest.php | 3 +++ Tests/DeprecationErrorHandler/DeprecationTest.php | 4 ++++ Tests/ExpectDeprecationTraitTest.php | 8 ++++++++ Tests/ExpectedDeprecationAnnotationTest.php | 3 +++ Tests/FailTests/NoAssertionsTestRisky.php | 2 ++ Tests/Fixtures/coverage/tests/CoversDefaultClassTest.php | 2 ++ Tests/Fixtures/coverage/tests/CoversNothingTest.php | 2 ++ Tests/Fixtures/coverage/tests/CoversTest.php | 8 +++++--- Tests/Metadata/AttributeReaderTest.php | 2 ++ Tests/OnlyExpectingDeprecationSkippedTest.php | 4 ++++ Tests/ProcessIsolationTest.php | 2 ++ 12 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Tests/ClockMockTest.php b/Tests/ClockMockTest.php index 8424108..95c354e 100644 --- a/Tests/ClockMockTest.php +++ b/Tests/ClockMockTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ClockMock; @@ -19,6 +20,7 @@ * * @covers \Symfony\Bridge\PhpUnit\ClockMock */ +#[CoversClass(ClockMock::class)] class ClockMockTest extends TestCase { public static function setUpBeforeClass(): void diff --git a/Tests/DeprecationErrorHandler/ConfigurationTest.php b/Tests/DeprecationErrorHandler/ConfigurationTest.php index 741c1a5..3faadf3 100644 --- a/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration; @@ -194,6 +195,7 @@ public static function provideItCanBeDisabled(): array /** * @dataProvider provideItCanBeDisabled */ + #[DataProvider('provideItCanBeDisabled')] public function testItCanBeDisabled(string $encodedString, bool $expectedEnabled) { $configuration = Configuration::fromUrlEncodedString($encodedString); @@ -240,6 +242,7 @@ public function testOutputIsNotVerboseInWeakMode() /** * @dataProvider provideDataForToleratesForGroup */ + #[DataProvider('provideDataForToleratesForGroup')] public function testToleratesForIndividualGroups(string $deprecationsHelper, array $deprecationsPerType, array $expected) { $configuration = Configuration::fromUrlEncodedString($deprecationsHelper); diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 1519b83..337fbd1 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation; @@ -88,6 +89,7 @@ public function testItRulesOutFilesOutsideVendorsAsIndirect() /** * @dataProvider mutedProvider */ + #[DataProvider('mutedProvider')] public function testItMutesOnlySpecificErrorMessagesWhenTheCallingCodeIsInPhpunit($muted, $callingClass, $message) { $trace = $this->debugBacktrace(); @@ -170,6 +172,7 @@ public static function providerGetTypeDetectsSelf(): array /** * @dataProvider providerGetTypeDetectsSelf */ + #[DataProvider('providerGetTypeDetectsSelf')] public function testGetTypeDetectsSelf(string $expectedType, string $message, string $traceClass, string $file) { $trace = [ @@ -233,6 +236,7 @@ public static function providerGetTypeUsesRightTrace(): array /** * @dataProvider providerGetTypeUsesRightTrace */ + #[DataProvider('providerGetTypeUsesRightTrace')] public function testGetTypeUsesRightTrace(string $expectedType, string $message, array $trace) { $deprecation = new Deprecation( diff --git a/Tests/ExpectDeprecationTraitTest.php b/Tests/ExpectDeprecationTraitTest.php index 142d3f8..0a4854d 100644 --- a/Tests/ExpectDeprecationTraitTest.php +++ b/Tests/ExpectDeprecationTraitTest.php @@ -11,7 +11,9 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; @@ -25,6 +27,7 @@ final class ExpectDeprecationTraitTest extends TestCase * * @group legacy */ + #[Group('legacy')] public function testOne() { $this->expectDeprecation('foo'); @@ -38,6 +41,8 @@ public function testOne() * * @runInSeparateProcess */ + #[Group('legacy')] + #[RunInSeparateProcess] public function testOneInIsolation() { $this->expectDeprecation('foo'); @@ -49,6 +54,7 @@ public function testOneInIsolation() * * @group legacy */ + #[Group('legacy')] public function testMany() { $this->expectDeprecation('foo'); @@ -64,6 +70,7 @@ public function testMany() * * @expectedDeprecation foo */ + #[Group('legacy')] public function testOneWithAnnotation() { $this->expectDeprecation('bar'); @@ -79,6 +86,7 @@ public function testOneWithAnnotation() * @expectedDeprecation foo * @expectedDeprecation bar */ + #[Group('legacy')] public function testManyWithAnnotation() { $this->expectDeprecation('ccc'); diff --git a/Tests/ExpectedDeprecationAnnotationTest.php b/Tests/ExpectedDeprecationAnnotationTest.php index 6e7ba0b..a3112cf 100644 --- a/Tests/ExpectedDeprecationAnnotationTest.php +++ b/Tests/ExpectedDeprecationAnnotationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; @@ -24,6 +25,7 @@ final class ExpectedDeprecationAnnotationTest extends TestCase * * @expectedDeprecation foo */ + #[Group('legacy')] public function testOne() { @trigger_error('foo', \E_USER_DEPRECATED); @@ -37,6 +39,7 @@ public function testOne() * @expectedDeprecation foo * @expectedDeprecation bar */ + #[Group('legacy')] public function testMany() { @trigger_error('foo', \E_USER_DEPRECATED); diff --git a/Tests/FailTests/NoAssertionsTestRisky.php b/Tests/FailTests/NoAssertionsTestRisky.php index 601506a..559b86b 100644 --- a/Tests/FailTests/NoAssertionsTestRisky.php +++ b/Tests/FailTests/NoAssertionsTestRisky.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests\FailTests; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; @@ -29,6 +30,7 @@ final class NoAssertionsTestRisky extends TestCase * * @group legacy */ + #[Group('legacy')] public function testOne() { $this->expectNotToPerformAssertions(); diff --git a/Tests/Fixtures/coverage/tests/CoversDefaultClassTest.php b/Tests/Fixtures/coverage/tests/CoversDefaultClassTest.php index d764638..503d675 100644 --- a/Tests/Fixtures/coverage/tests/CoversDefaultClassTest.php +++ b/Tests/Fixtures/coverage/tests/CoversDefaultClassTest.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \DateTime */ +#[CoversClass(DateTime::class)] class CoversDefaultClassTest extends TestCase { public function test() diff --git a/Tests/Fixtures/coverage/tests/CoversNothingTest.php b/Tests/Fixtures/coverage/tests/CoversNothingTest.php index e60ea97..8e3cb0a 100644 --- a/Tests/Fixtures/coverage/tests/CoversNothingTest.php +++ b/Tests/Fixtures/coverage/tests/CoversNothingTest.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; /** * @coversNothing */ +#[CoversNothing] class CoversNothingTest extends TestCase { public function test() diff --git a/Tests/Fixtures/coverage/tests/CoversTest.php b/Tests/Fixtures/coverage/tests/CoversTest.php index f6d3406..67ac74d 100644 --- a/Tests/Fixtures/coverage/tests/CoversTest.php +++ b/Tests/Fixtures/coverage/tests/CoversTest.php @@ -9,13 +9,15 @@ * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +/** + * @covers \DateTime + */ +#[CoversClass(DateTime::class)] class CoversTest extends TestCase { - /** - * @covers \DateTime - */ public function test() { $this->assertTrue(true); diff --git a/Tests/Metadata/AttributeReaderTest.php b/Tests/Metadata/AttributeReaderTest.php index d34208d..eb3a776 100644 --- a/Tests/Metadata/AttributeReaderTest.php +++ b/Tests/Metadata/AttributeReaderTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests\Metadata; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; @@ -22,6 +23,7 @@ class AttributeReaderTest extends TestCase /** * @dataProvider provideReadCases */ + #[DataProvider('provideReadCases')] public function testAttributesAreRead(string $method, string $attributeClass, array $expected) { $reader = new AttributeReader(); diff --git a/Tests/OnlyExpectingDeprecationSkippedTest.php b/Tests/OnlyExpectingDeprecationSkippedTest.php index 593e0b4..aede756 100644 --- a/Tests/OnlyExpectingDeprecationSkippedTest.php +++ b/Tests/OnlyExpectingDeprecationSkippedTest.php @@ -11,6 +11,8 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; /** @@ -18,6 +20,7 @@ * * @requires extension ext-dummy */ +#[RequiresPhpExtension('ext-dummy')] final class OnlyExpectingDeprecationSkippedTest extends TestCase { /** @@ -27,6 +30,7 @@ final class OnlyExpectingDeprecationSkippedTest extends TestCase * * @expectedDeprecation unreachable */ + #[Group('legacy')] public function testExpectingOnlyDeprecations() { $this->fail('should never be ran.'); diff --git a/Tests/ProcessIsolationTest.php b/Tests/ProcessIsolationTest.php index b517fe5..9e043d0 100644 --- a/Tests/ProcessIsolationTest.php +++ b/Tests/ProcessIsolationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit\Tests; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; @@ -22,6 +23,7 @@ * @runTestsInSeparateProcesses */ #[RequiresPhpunit('<10')] +#[Group('legacy')] class ProcessIsolationTest extends TestCase { /** From 7d3233ff7f91585f519b3d538fca5475984ae47b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 4 Aug 2025 10:15:34 +0200 Subject: [PATCH 18/40] CS --- Tests/FailTests/ExpectDeprecationTraitTestFail.php | 5 +++++ Tests/ProcessIsolationTest.php | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/FailTests/ExpectDeprecationTraitTestFail.php b/Tests/FailTests/ExpectDeprecationTraitTestFail.php index a43fe30..10da25f 100644 --- a/Tests/FailTests/ExpectDeprecationTraitTestFail.php +++ b/Tests/FailTests/ExpectDeprecationTraitTestFail.php @@ -11,7 +11,9 @@ namespace Symfony\Bridge\PhpUnit\Tests\FailTests; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; @@ -31,6 +33,7 @@ final class ExpectDeprecationTraitTestFail extends TestCase * * @group legacy */ + #[Group('legacy')] public function testOne() { $this->expectDeprecation('foo'); @@ -44,6 +47,8 @@ public function testOne() * * @runInSeparateProcess */ + #[Group('legacy')] + #[RunInSeparateProcess] public function testOneInIsolation() { $this->expectDeprecation('foo'); diff --git a/Tests/ProcessIsolationTest.php b/Tests/ProcessIsolationTest.php index 9e043d0..d86e2db 100644 --- a/Tests/ProcessIsolationTest.php +++ b/Tests/ProcessIsolationTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhpunit; +use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; /** @@ -37,7 +38,7 @@ public function testIsolation() public function testCallingOtherErrorHandler() { - $this->expectException(\PHPUnit\Framework\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.'); trigger_error('Test that PHPUnit\'s error handler fires.', \E_USER_WARNING); From d30926f3b246cfb469984cd46c18bb1f7e93f3f7 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 10 Aug 2025 00:28:14 +0200 Subject: [PATCH 19/40] chore: heredoc indentation as of PHP 7.3 https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc --- bin/simple-phpunit.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index 8a018c4..e56ceb8 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -285,30 +285,30 @@ file_put_contents($alteredFile, $alteredCode); file_put_contents('phpunit', <<<'EOPHP' -getExcludedDirectories(); - PHPUnit\Util\ExcludeList::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListPhpunit::class))->getFileName())); - class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\ExcludeList::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListSimplePhpunit::class))->getFileName())); -} elseif (method_exists(\PHPUnit\Util\Blacklist::class, 'addDirectory')) { - (new PHPUnit\Util\BlackList())->getBlacklistedDirectories(); - PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListPhpunit::class))->getFileName())); - class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListSimplePhpunit::class))->getFileName())); -} else { - PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyExcludeListPhpunit'] = 1; - PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyExcludeListSimplePhpunit'] = 1; -} + if (!class_exists(\SymfonyExcludeListPhpunit::class, false)) { + class SymfonyExcludeListPhpunit {} + } + if (method_exists(\PHPUnit\Util\ExcludeList::class, 'addDirectory')) { + (new PHPUnit\Util\Excludelist())->getExcludedDirectories(); + PHPUnit\Util\ExcludeList::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListPhpunit::class))->getFileName())); + class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\ExcludeList::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListSimplePhpunit::class))->getFileName())); + } elseif (method_exists(\PHPUnit\Util\Blacklist::class, 'addDirectory')) { + (new PHPUnit\Util\BlackList())->getBlacklistedDirectories(); + PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListPhpunit::class))->getFileName())); + class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass(\SymfonyExcludeListSimplePhpunit::class))->getFileName())); + } else { + PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyExcludeListPhpunit'] = 1; + PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyExcludeListSimplePhpunit'] = 1; + } -Symfony\Bridge\PhpUnit\TextUI\Command::main(); + Symfony\Bridge\PhpUnit\TextUI\Command::main(); -EOPHP + EOPHP ); } From 0235d5a69c96b4122cc442441ac11ece8ba795f6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 1 Aug 2025 14:58:41 +0200 Subject: [PATCH 20/40] run tests with PHPUnit 12.3 --- Tests/symfonyextensionnotregistered.phpt | 150 +++++++++++------------ 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/Tests/symfonyextensionnotregistered.phpt b/Tests/symfonyextensionnotregistered.phpt index e66b677..0a14077 100644 --- a/Tests/symfonyextensionnotregistered.phpt +++ b/Tests/symfonyextensionnotregistered.phpt @@ -23,451 +23,451 @@ Expected deprecation with message "The "Symfony\Bridge\PhpUnit\Tests\Fixtures\sy %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testTimeMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testMicrotimeMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testSleepMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testUsleepMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDateMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGmdateMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testHrtimeMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testCheckdnsrrMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsCheckRecordMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGetmxrrMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetMxMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbyaddrMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynameMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testGethostbynamelMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "test class namespace" ('Symfony\Bridge\PhpUnit\Tests') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered%stest class namespace%s ('Symfony\Bridge\PhpUnit\Tests') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "namespace derived from test namespace" ('Symfony\Bridge\PhpUnit') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered%snamespace derived from test namespace%s ('Symfony\Bridge\PhpUnit') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "explicitly configured namespace" ('App') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered%sexplicitly configured namespace%s ('App') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "explicitly configured namespace through attribute on class" ('App\Foo') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered%sexplicitly configured namespace through attribute on class%s ('App\Foo') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d %s/.phpunit/phpunit-%s/phpunit:%d -%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered with data set "explicitly configured namespace through attribute on method" ('App\Bar') +%d) Symfony\Bridge\PhpUnit\Tests\SymfonyExtension::testDnsGetRecordMockIsRegistered%sexplicitly configured namespace through attribute on method%s ('App\Bar') Failed asserting that false is true. %s/src/Symfony/Bridge/PhpUnit/Tests/SymfonyExtension.php:%d From 404547d2b4741b002a5646a80225598c21238f22 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sat, 9 Aug 2025 23:58:04 +0200 Subject: [PATCH 21/40] chore: PHP CS Fixer - restore PHP / PHPUnit rulesets --- bin/simple-phpunit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index 8a018c4..ee8a053 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -165,7 +165,7 @@ $prevCacheDir = getenv('COMPOSER_CACHE_DIR'); if ($prevCacheDir) { if (false === $absoluteCacheDir = realpath($prevCacheDir)) { - @mkdir($prevCacheDir, 0777, true); + @mkdir($prevCacheDir, 0o777, true); $absoluteCacheDir = realpath($prevCacheDir); } if ($absoluteCacheDir) { @@ -181,7 +181,7 @@ if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationHash !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION_DIR.md5")) { // Build a standalone phpunit without symfony/yaml nor prophecy by default - @mkdir($PHPUNIT_DIR, 0777, true); + @mkdir($PHPUNIT_DIR, 0o777, true); chdir($PHPUNIT_DIR); if (file_exists("$PHPUNIT_VERSION_DIR")) { passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s 2> NUL' : 'rm -rf %s', escapeshellarg("$PHPUNIT_VERSION_DIR.old"))); From 1bda29e68efe64c16d19338cd465d79bfb3dac4f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Aug 2025 09:36:33 +0200 Subject: [PATCH 22/40] Replace __sleep/wakeup() by __(un)serialize() when BC isn't a concern --- Legacy/SymfonyTestsListenerTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index c7156c9..5547a91 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -93,12 +93,12 @@ public function __construct(array $mockedNamespaces = []) } } - public function __sleep() + public function __serialize(): array { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } - public function __wakeup() + public function __unserialize(array $data): void { throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); } From bcc204fed472aaead478a1158447d2292caec0d4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Aug 2025 16:45:04 +0200 Subject: [PATCH 23/40] [Mime] Deprecate implementing `__sleep/wakeup()` on `AbstractPart` implementations --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b9dda6b..d1e6c3b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=8.1.0" }, "require-dev": { - "symfony/deprecation-contracts": "^2.5|^3.0", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/error-handler": "^6.4.3|^7.0.3|^8.0" }, "autoload": { From 88a4dfe6551c9e18a18e3d074c6f3bc1bd6effe0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Aug 2025 09:54:15 +0200 Subject: [PATCH 24/40] [PhpUnitBridge] Patch phpunit to clear php8.5 deprecation --- bin/simple-phpunit.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index fb6286a..6c6bed1 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -270,6 +270,12 @@ exit($exit); } + $alteredCode = file_get_contents($alteredFile = './src/Runner/PhptTestCase.php'); + if (str_contains($alteredCode, " 'report_memleaks=0',\n")) { + $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); + file_put_contents($alteredFile, $alteredCode); + } + // Mutate TestCase code if (version_compare($PHPUNIT_VERSION, '11.0', '<')) { $alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php'); From c36f7dcb211a7824df6fd9b202ba8b80de3b9bf5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Aug 2025 10:50:15 +0200 Subject: [PATCH 25/40] [PhpUnitBridge] Code cleanup --- Legacy/PolyfillTestCaseTrait.php | 116 ------------------------------- bin/simple-phpunit.php | 5 +- 2 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 Legacy/PolyfillTestCaseTrait.php diff --git a/Legacy/PolyfillTestCaseTrait.php b/Legacy/PolyfillTestCaseTrait.php deleted file mode 100644 index 8673bdc..0000000 --- a/Legacy/PolyfillTestCaseTrait.php +++ /dev/null @@ -1,116 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\PhpUnit\Legacy; - -use PHPUnit\Framework\Error\Error; -use PHPUnit\Framework\Error\Notice; -use PHPUnit\Framework\Error\Warning; - -/** - * This trait is @internal. - */ -trait PolyfillTestCaseTrait -{ - /** - * @param string $messageRegExp - * - * @return void - */ - public function expectExceptionMessageMatches($messageRegExp) - { - $this->expectExceptionMessageRegExp($messageRegExp); - } - - /** - * @return void - */ - public function expectNotice() - { - $this->expectException(Notice::class); - } - - /** - * @param string $message - * - * @return void - */ - public function expectNoticeMessage($message) - { - $this->expectExceptionMessage($message); - } - - /** - * @param string $regularExpression - * - * @return void - */ - public function expectNoticeMessageMatches($regularExpression) - { - $this->expectExceptionMessageMatches($regularExpression); - } - - /** - * @return void - */ - public function expectWarning() - { - $this->expectException(Warning::class); - } - - /** - * @param string $message - * - * @return void - */ - public function expectWarningMessage($message) - { - $this->expectExceptionMessage($message); - } - - /** - * @param string $regularExpression - * - * @return void - */ - public function expectWarningMessageMatches($regularExpression) - { - $this->expectExceptionMessageMatches($regularExpression); - } - - /** - * @return void - */ - public function expectError() - { - $this->expectException(Error::class); - } - - /** - * @param string $message - * - * @return void - */ - public function expectErrorMessage($message) - { - $this->expectExceptionMessage($message); - } - - /** - * @param string $regularExpression - * - * @return void - */ - public function expectErrorMessageMatches($regularExpression) - { - $this->expectExceptionMessageMatches($regularExpression); - } -} diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index 6c6bed1..cf37fac 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -270,7 +270,8 @@ exit($exit); } - $alteredCode = file_get_contents($alteredFile = './src/Runner/PhptTestCase.php'); + // Mutate PhptTestCase code + $alteredCode = file_get_contents($alteredFile = is_file('./src/Runner/PHPT/PhptTestCase.php') ? './src/Runner/PHPT/PhptTestCase.php' : './src/Runner/PhptTestCase.php'); if (str_contains($alteredCode, " 'report_memleaks=0',\n")) { $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); file_put_contents($alteredFile, $alteredCode); @@ -282,8 +283,6 @@ if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) { $alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); } - $alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1); - file_put_contents($alteredFile, $alteredCode); // Mutate Assert code $alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php'); From ed8f2e89eb1af209f62ef9d0f65aa9082d02cd5e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Aug 2025 11:07:33 +0200 Subject: [PATCH 26/40] [PhpUnitBridge] Fix detecting TestCase.php for phpt files --- bin/simple-phpunit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index cf37fac..eb4ba10 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -271,8 +271,8 @@ } // Mutate PhptTestCase code - $alteredCode = file_get_contents($alteredFile = is_file('./src/Runner/PHPT/PhptTestCase.php') ? './src/Runner/PHPT/PhptTestCase.php' : './src/Runner/PhptTestCase.php'); - if (str_contains($alteredCode, " 'report_memleaks=0',\n")) { + $alteredFile = defined('GLOB_BRACE') ? glob('./src/Runner/{Phpt/,PHPT/Phpt,Phpt}TestCase.php', GLOB_BRACE) : false; + if ($alteredFile && str_contains($alteredCode = file_get_contents($alteredFile)[0], " 'report_memleaks=0',\n")) { $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); file_put_contents($alteredFile, $alteredCode); } From 6345f0a2fe59a8250dc718c179e224480447a26b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Aug 2025 11:11:25 +0200 Subject: [PATCH 27/40] Fix typo --- bin/simple-phpunit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index eb4ba10..a3363f3 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -272,7 +272,7 @@ // Mutate PhptTestCase code $alteredFile = defined('GLOB_BRACE') ? glob('./src/Runner/{Phpt/,PHPT/Phpt,Phpt}TestCase.php', GLOB_BRACE) : false; - if ($alteredFile && str_contains($alteredCode = file_get_contents($alteredFile)[0], " 'report_memleaks=0',\n")) { + if ($alteredFile && str_contains($alteredCode = file_get_contents($alteredFile[0]), " 'report_memleaks=0',\n")) { $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); file_put_contents($alteredFile, $alteredCode); } From 9f4f26c679107f746c9b71c0e3428eb04da19fa3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Aug 2025 11:14:13 +0200 Subject: [PATCH 28/40] Fix typo (bis) --- bin/simple-phpunit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index a3363f3..de3f847 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -274,7 +274,7 @@ $alteredFile = defined('GLOB_BRACE') ? glob('./src/Runner/{Phpt/,PHPT/Phpt,Phpt}TestCase.php', GLOB_BRACE) : false; if ($alteredFile && str_contains($alteredCode = file_get_contents($alteredFile[0]), " 'report_memleaks=0',\n")) { $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); - file_put_contents($alteredFile, $alteredCode); + file_put_contents($alteredFile[0], $alteredCode); } // Mutate TestCase code From 86465d6494876ed8d3c1f1bc7ecc175b255f88b3 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 20 Aug 2025 22:30:05 +0200 Subject: [PATCH 29/40] revert patching of PHPUnit about memleak reports The corresponding patch has been released for all relevant PHPUnit versions. --- bin/simple-phpunit.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index de3f847..b4b348c 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -270,13 +270,6 @@ exit($exit); } - // Mutate PhptTestCase code - $alteredFile = defined('GLOB_BRACE') ? glob('./src/Runner/{Phpt/,PHPT/Phpt,Phpt}TestCase.php', GLOB_BRACE) : false; - if ($alteredFile && str_contains($alteredCode = file_get_contents($alteredFile[0]), " 'report_memleaks=0',\n")) { - $alteredCode = str_replace(" 'report_memleaks=0',\n", '', $alteredCode); - file_put_contents($alteredFile[0], $alteredCode); - } - // Mutate TestCase code if (version_compare($PHPUNIT_VERSION, '11.0', '<')) { $alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php'); From 0dc1578ab40e728450012b8d2996253a0ba563b1 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 4 Sep 2025 10:05:05 +0200 Subject: [PATCH 30/40] Replace backtick operator, deprecated in PHP 8.5, with shell_exec() These two are exactly equivalent. https://github.com/php/php-src/blob/d246584ae7d2d778b204e0a179840fdf237f3b97/Zend/zend_compile.c#L10924C25-L10927 https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_backticks_as_an_alias_for_shell_exec --- bin/simple-phpunit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit.php b/bin/simple-phpunit.php index c021a4e..c6b162d 100644 --- a/bin/simple-phpunit.php +++ b/bin/simple-phpunit.php @@ -191,7 +191,7 @@ } $info = []; - foreach (explode("\n", `$COMPOSER info --no-ansi -a -n phpunit/phpunit "$PHPUNIT_VERSION.*"`) as $line) { + foreach (explode("\n", shell_exec("$COMPOSER info --no-ansi -a -n phpunit/phpunit \"$PHPUNIT_VERSION.*\"")) as $line) { $line = rtrim($line); if (!$info && preg_match('/^versions +: /', $line)) { From 8ca9c9a75d8aaba5003fc8f170ab1303285933e6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 4 Sep 2025 09:21:33 +0200 Subject: [PATCH 31/40] run PhpUnitBridge tests with PHPUnit 11.5 --- Tests/DeprecationErrorHandler/ConfigurationTest.php | 6 +++--- Tests/DeprecationErrorHandler/DeprecationGroupTest.php | 3 +++ Tests/DeprecationErrorHandler/DeprecationNoticeTest.php | 3 +++ Tests/DeprecationErrorHandler/DeprecationTest.php | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Tests/DeprecationErrorHandler/ConfigurationTest.php b/Tests/DeprecationErrorHandler/ConfigurationTest.php index 7eec029..0cb74fc 100644 --- a/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -17,6 +17,9 @@ use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup; use Symfony\Component\ErrorHandler\DebugClassLoader; +/** + * @requires PHPUnit < 10 + */ class ConfigurationTest extends TestCase { private $files; @@ -463,9 +466,6 @@ public function testExistingBaselineAndGeneration() $this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename)); } - /** - * @requires PHPUnit < 10 - */ public function testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader() { $filename = $this->createFile(); diff --git a/Tests/DeprecationErrorHandler/DeprecationGroupTest.php b/Tests/DeprecationErrorHandler/DeprecationGroupTest.php index df746e5..f6198f4 100644 --- a/Tests/DeprecationErrorHandler/DeprecationGroupTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationGroupTest.php @@ -5,6 +5,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup; +/** + * @requires PHPUnit < 10 + */ final class DeprecationGroupTest extends TestCase { public function testItGroupsByMessage() diff --git a/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php b/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php index c0a88c4..c6e2cce 100644 --- a/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php @@ -5,6 +5,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationNotice; +/** + * @requires PHPUnit < 10 + */ final class DeprecationNoticeTest extends TestCase { public function testItGroupsByCaller() diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index 2a7643a..eb8d44a 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -16,6 +16,9 @@ use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation; use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7; +/** + * @requires PHPUnit < 10 + */ class DeprecationTest extends TestCase { private static $vendorDir; From 20cd2aca94113de6945fac186d0663154fb9109e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Sep 2025 10:16:56 +0200 Subject: [PATCH 32/40] Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages --- Legacy/SymfonyTestsListenerTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 13d9abc..63e4098 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -93,12 +93,12 @@ public function __construct(array $mockedNamespaces = []) } } - public function __sleep() + public function __serialize(): array { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } - public function __wakeup() + public function __unserialize(array $data): void { throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); } From b1c8134511a7c8f48bcf405b2b8b74e980df9f47 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Sep 2025 13:41:52 +0200 Subject: [PATCH 33/40] [PhpUnitBridge] Silence deprecation of __sleep/wakeup() --- DeprecationErrorHandler.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 49dbeb6..8b78ca7 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -171,6 +171,13 @@ public function handleError($type, $msg, $file, $line, $context = []) exit(1); } + if (\PHP_VERSION_ID >= 80500 && \in_array($msg, [ + 'The __sleep() serialization magic method has been deprecated. Implement __serialize() instead (or in addition, if support for old PHP versions is necessary)', + 'The __wakeup() serialization magic method has been deprecated. Implement __unserialize() instead (or in addition, if support for old PHP versions is necessary)', + ], true)) { + return null; + } + if ('legacy' === $group) { $this->deprecationGroups[$group]->addNotice(); } elseif ($deprecation->originatesFromAnObject()) { From 0206787ec1d9887aa92fc7f77b7afe40b6dfeee8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Sep 2025 16:32:46 +0200 Subject: [PATCH 34/40] [PhpUnitBridge] Fix gathering deprecation in phpt --- Legacy/SymfonyTestsListenerTrait.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 63e4098..67811e0 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; use PHPUnit\Runner\BaseTestRunner; +use PHPUnit\Runner\PhptTestCase; use PHPUnit\Util\Blacklist; use PHPUnit\Util\ExcludeList; use PHPUnit\Util\Test; @@ -206,6 +207,12 @@ public function addSkippedTest($test, \Exception $e, $time): void public function startTest($test): void { + if (-2 < $this->state && $test instanceof PhptTestCase) { + $this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec'); + putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess); + putenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE='.tempnam(sys_get_temp_dir(), 'expectdeprec')); + } + if (-2 < $this->state && $test instanceof TestCase) { // This event is triggered before the test is re-run in isolation if ($this->willBeIsolated($test)) { From 3f1039b962feb109eae28a060a9b2e383e34f5ca Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Sep 2025 16:50:36 +0200 Subject: [PATCH 35/40] [PhpUnitBridge] Fix tests --- Legacy/SymfonyTestsListenerTrait.php | 2 +- Tests/DeprecationErrorHandler/baseline.phpt | 1 + Tests/DeprecationErrorHandler/baseline2.phpt | 1 + Tests/DeprecationErrorHandler/baseline3.phpt | 1 + Tests/DeprecationErrorHandler/debug_class_loader_autoload.phpt | 1 + .../DeprecationErrorHandler/debug_class_loader_deprecation.phpt | 1 + Tests/DeprecationErrorHandler/default.phpt | 1 + Tests/DeprecationErrorHandler/deprecated_regexp.phpt | 1 + Tests/DeprecationErrorHandler/disabled.phpt | 1 + Tests/DeprecationErrorHandler/disabled_1.phpt | 1 + Tests/DeprecationErrorHandler/eval_not_self.phpt | 1 + Tests/DeprecationErrorHandler/generate_baseline.phpt | 1 + Tests/DeprecationErrorHandler/ignore.phpt | 1 + Tests/DeprecationErrorHandler/lagging_vendor.phpt | 1 + Tests/DeprecationErrorHandler/log_file.phpt | 1 + Tests/DeprecationErrorHandler/multiple_autoloads.phpt | 1 + Tests/DeprecationErrorHandler/partially_quiet.phpt | 1 + Tests/DeprecationErrorHandler/partially_quiet2.phpt | 1 + .../php_deprecation_from_vendor_class.phpt | 1 + Tests/DeprecationErrorHandler/quiet.phpt | 1 + Tests/DeprecationErrorHandler/quiet_but_failing.phpt | 1 + Tests/DeprecationErrorHandler/self_on_non_vendor.phpt | 1 + Tests/DeprecationErrorHandler/shutdown_deprecations.phpt | 1 + Tests/DeprecationErrorHandler/trigger_deprecation_types.phpt | 1 + Tests/DeprecationErrorHandler/trigger_error_types.phpt | 1 + Tests/DeprecationErrorHandler/weak.phpt | 1 + .../weak_vendors_on_eval_d_deprecation.phpt | 1 + Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt | 1 + .../weak_vendors_on_phar_deprecation.phpt | 1 + Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt | 1 + 30 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 67811e0..47c0881 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -306,7 +306,7 @@ public function endTest($test, $time): void } if (self::$expectedDeprecations) { - if (!\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) { + if (!$test instanceof TestCase || !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) { $test->addToAssertionCount(\count(self::$expectedDeprecations)); } diff --git a/Tests/DeprecationErrorHandler/baseline.phpt b/Tests/DeprecationErrorHandler/baseline.phpt index 83d448e..598e785 100644 --- a/Tests/DeprecationErrorHandler/baseline.phpt +++ b/Tests/DeprecationErrorHandler/baseline.phpt @@ -26,6 +26,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'baselineFile=' . urlencode($filename)) putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/baseline2.phpt b/Tests/DeprecationErrorHandler/baseline2.phpt index 925d5c2..48818aa 100644 --- a/Tests/DeprecationErrorHandler/baseline2.phpt +++ b/Tests/DeprecationErrorHandler/baseline2.phpt @@ -16,6 +16,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'baselineFile=' . urlencode($filename)) putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/baseline3.phpt b/Tests/DeprecationErrorHandler/baseline3.phpt index d814c02..dc9af7e 100644 --- a/Tests/DeprecationErrorHandler/baseline3.phpt +++ b/Tests/DeprecationErrorHandler/baseline3.phpt @@ -16,6 +16,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'baselineFile=' . urlencode($filename)) putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/debug_class_loader_autoload.phpt b/Tests/DeprecationErrorHandler/debug_class_loader_autoload.phpt index 04e64d3..0270672 100644 --- a/Tests/DeprecationErrorHandler/debug_class_loader_autoload.phpt +++ b/Tests/DeprecationErrorHandler/debug_class_loader_autoload.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/debug_class_loader_deprecation.phpt b/Tests/DeprecationErrorHandler/debug_class_loader_deprecation.phpt index a6b0133..019aa9c 100644 --- a/Tests/DeprecationErrorHandler/debug_class_loader_deprecation.phpt +++ b/Tests/DeprecationErrorHandler/debug_class_loader_deprecation.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index 7b46259..22268f1 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -9,6 +9,7 @@ putenv($k); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/deprecated_regexp.phpt b/Tests/DeprecationErrorHandler/deprecated_regexp.phpt index 58f2acb..f2d5a6f 100644 --- a/Tests/DeprecationErrorHandler/deprecated_regexp.phpt +++ b/Tests/DeprecationErrorHandler/deprecated_regexp.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = '/foo/'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/disabled.phpt b/Tests/DeprecationErrorHandler/disabled.phpt index 674fb6f..c86162e 100644 --- a/Tests/DeprecationErrorHandler/disabled.phpt +++ b/Tests/DeprecationErrorHandler/disabled.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'disabled'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/disabled_1.phpt b/Tests/DeprecationErrorHandler/disabled_1.phpt index acb5f09..b9f9410 100644 --- a/Tests/DeprecationErrorHandler/disabled_1.phpt +++ b/Tests/DeprecationErrorHandler/disabled_1.phpt @@ -9,6 +9,7 @@ putenv($k); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/eval_not_self.phpt b/Tests/DeprecationErrorHandler/eval_not_self.phpt index 5701f75..7c0af44 100644 --- a/Tests/DeprecationErrorHandler/eval_not_self.phpt +++ b/Tests/DeprecationErrorHandler/eval_not_self.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/generate_baseline.phpt b/Tests/DeprecationErrorHandler/generate_baseline.phpt index 5b80791..cc6c9ae 100644 --- a/Tests/DeprecationErrorHandler/generate_baseline.phpt +++ b/Tests/DeprecationErrorHandler/generate_baseline.phpt @@ -10,6 +10,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'generateBaseline=true&baselineFile=' . putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/ignore.phpt b/Tests/DeprecationErrorHandler/ignore.phpt index 44d8620..bab9612 100644 --- a/Tests/DeprecationErrorHandler/ignore.phpt +++ b/Tests/DeprecationErrorHandler/ignore.phpt @@ -17,6 +17,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'ignoreFile=' . urlencode($filename)); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/lagging_vendor.phpt b/Tests/DeprecationErrorHandler/lagging_vendor.phpt index b5253df..2dfa51a 100644 --- a/Tests/DeprecationErrorHandler/lagging_vendor.phpt +++ b/Tests/DeprecationErrorHandler/lagging_vendor.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&max[direct]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/log_file.phpt b/Tests/DeprecationErrorHandler/log_file.phpt index 51f8d6c..de0f4e2 100644 --- a/Tests/DeprecationErrorHandler/log_file.phpt +++ b/Tests/DeprecationErrorHandler/log_file.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'logFile='.$filename); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/multiple_autoloads.phpt b/Tests/DeprecationErrorHandler/multiple_autoloads.phpt index edf9f4f..bba85fd 100644 --- a/Tests/DeprecationErrorHandler/multiple_autoloads.phpt +++ b/Tests/DeprecationErrorHandler/multiple_autoloads.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/partially_quiet.phpt b/Tests/DeprecationErrorHandler/partially_quiet.phpt index 83b135b..e3f8be4 100644 --- a/Tests/DeprecationErrorHandler/partially_quiet.phpt +++ b/Tests/DeprecationErrorHandler/partially_quiet.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&quiet[]=unsilenced&quiet[] putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/partially_quiet2.phpt b/Tests/DeprecationErrorHandler/partially_quiet2.phpt index 4d0d6c3..65edfb2 100644 --- a/Tests/DeprecationErrorHandler/partially_quiet2.phpt +++ b/Tests/DeprecationErrorHandler/partially_quiet2.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&max[direct]=0&quiet[]=unsi putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt b/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt index 1ead2ef..38bf7ce 100644 --- a/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt +++ b/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt @@ -10,6 +10,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/quiet.phpt b/Tests/DeprecationErrorHandler/quiet.phpt index 5b6e325..78bbafb 100644 --- a/Tests/DeprecationErrorHandler/quiet.phpt +++ b/Tests/DeprecationErrorHandler/quiet.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=3&verbose=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/quiet_but_failing.phpt b/Tests/DeprecationErrorHandler/quiet_but_failing.phpt index 8d8f8b4..2ada89f 100644 --- a/Tests/DeprecationErrorHandler/quiet_but_failing.phpt +++ b/Tests/DeprecationErrorHandler/quiet_but_failing.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0&verbose=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/self_on_non_vendor.phpt b/Tests/DeprecationErrorHandler/self_on_non_vendor.phpt index 42a6c0d..5b3b089 100644 --- a/Tests/DeprecationErrorHandler/self_on_non_vendor.phpt +++ b/Tests/DeprecationErrorHandler/self_on_non_vendor.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt index 48049c0..fb6963e 100644 --- a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt +++ b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt @@ -9,6 +9,7 @@ putenv($k); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/trigger_deprecation_types.phpt b/Tests/DeprecationErrorHandler/trigger_deprecation_types.phpt index 261b6ec..c509fc2 100644 --- a/Tests/DeprecationErrorHandler/trigger_deprecation_types.phpt +++ b/Tests/DeprecationErrorHandler/trigger_deprecation_types.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/trigger_error_types.phpt b/Tests/DeprecationErrorHandler/trigger_error_types.phpt index 4dd6bda..1870f30 100644 --- a/Tests/DeprecationErrorHandler/trigger_error_types.phpt +++ b/Tests/DeprecationErrorHandler/trigger_error_types.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/weak.phpt b/Tests/DeprecationErrorHandler/weak.phpt index 1922e47..e3120c4 100644 --- a/Tests/DeprecationErrorHandler/weak.phpt +++ b/Tests/DeprecationErrorHandler/weak.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'weak'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_eval_d_deprecation.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_eval_d_deprecation.phpt index d1be3e9..8b8cdbd 100644 --- a/Tests/DeprecationErrorHandler/weak_vendors_on_eval_d_deprecation.phpt +++ b/Tests/DeprecationErrorHandler/weak_vendors_on_eval_d_deprecation.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt index 9c72a8e..c6cd1d1 100644 --- a/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt +++ b/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_phar_deprecation.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_phar_deprecation.phpt index 7bf5428..0094fea 100644 --- a/Tests/DeprecationErrorHandler/weak_vendors_on_phar_deprecation.phpt +++ b/Tests/DeprecationErrorHandler/weak_vendors_on_phar_deprecation.phpt @@ -9,6 +9,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt index c9b323f..93f2c40 100644 --- a/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt +++ b/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt @@ -8,6 +8,7 @@ putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0'); putenv('ANSICON'); putenv('ConEmuANSI'); putenv('TERM'); +putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { From 90860ac70bfa7eb41043e971766cdf3103a1c347 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Sep 2025 17:38:57 +0200 Subject: [PATCH 36/40] Fix --- Legacy/SymfonyTestsListenerTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 47c0881..a638f0c 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -306,7 +306,7 @@ public function endTest($test, $time): void } if (self::$expectedDeprecations) { - if (!$test instanceof TestCase || !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) { + if ($test instanceof TestCase && !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) { $test->addToAssertionCount(\count(self::$expectedDeprecations)); } From 406aa80401bf960e7a173a3ccf268ae82b6bc93f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 12 Sep 2025 10:04:19 +0200 Subject: [PATCH 37/40] do not try to modify the result of a PhptTestCase --- Legacy/SymfonyTestsListenerTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index a638f0c..4e591c7 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -280,9 +280,9 @@ public function endTest($test, $time): void if ($this->checkNumAssertions) { $assertions = \count(self::$expectedDeprecations) + $test->getNumAssertions(); - if ($test->doesNotPerformAssertions() && $assertions > 0) { + if ($test instanceof TestCase && $test->doesNotPerformAssertions() && $assertions > 0) { $test->getTestResultObject()->addFailure($test, new RiskyTestError(sprintf('This test is annotated with "@doesNotPerformAssertions", but performed %s assertions', $assertions)), $time); - } elseif ($assertions === 0 && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) { + } elseif ($test instanceof TestCase && $assertions === 0 && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) { $test->getTestResultObject()->addFailure($test, new RiskyTestError('This test did not perform any assertions'), $time); } @@ -312,9 +312,9 @@ public function endTest($test, $time): void restore_error_handler(); - if (!\in_array('legacy', $groups, true)) { + if ($test instanceof TestCase && !\in_array('legacy', $groups, true)) { $test->getTestResultObject()->addError($test, new AssertionFailedError('Only tests with the "@group legacy" annotation can expect a deprecation.'), 0); - } elseif (!\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR], true)) { + } elseif ($test instanceof TestCase && !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR], true)) { try { $prefix = "@expectedDeprecation:\n"; $test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", self::$expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", self::$gatheredDeprecations)."\n"); From 8988172769ef5219b7cf477f9de7a5e537e04822 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 15 Sep 2025 09:59:31 +0200 Subject: [PATCH 38/40] use a compatible config file when running tests with PHPUnit 9.6 --- .gitattributes | 1 + phpunit-9.6.xml.dist | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 phpunit-9.6.xml.dist diff --git a/.gitattributes b/.gitattributes index 14c3c35..0a9dafc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ /Tests export-ignore /phpunit.xml.dist export-ignore +/phpunit-9.6.xml.dist export-ignore /.git* export-ignore diff --git a/phpunit-9.6.xml.dist b/phpunit-9.6.xml.dist new file mode 100644 index 0000000..6f9542e --- /dev/null +++ b/phpunit-9.6.xml.dist @@ -0,0 +1,31 @@ + + + + + + + + + + ./Tests/ + ./Tests/DeprecationErrorHandler/ + + + + + + ./ + + + ./Tests + ./vendor + + + From f943689b4a81e2215063f3dde455a67e02c7426a Mon Sep 17 00:00:00 2001 From: HypeMC Date: Fri, 26 Sep 2025 23:59:12 +0200 Subject: [PATCH 39/40] [PhpUnitBridge] Move Doctrine deprecations setup to extension --- SymfonyExtension.php | 5 +++++ bootstrap.php | 17 +++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/SymfonyExtension.php b/SymfonyExtension.php index 05ff99a..a4f28a7 100644 --- a/SymfonyExtension.php +++ b/SymfonyExtension.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\PhpUnit; +use Doctrine\Deprecations\Deprecation; use PHPUnit\Event\Code\Test; use PHPUnit\Event\Code\TestMethod; use PHPUnit\Event\Test\BeforeTestMethodErrored; @@ -42,6 +43,10 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete DebugClassLoader::enable(); } + if (class_exists(Deprecation::class)) { + Deprecation::withoutDeduplication(); + } + $reader = new AttributeReader(); if ($parameters->has('clock-mock-namespaces')) { diff --git a/bootstrap.php b/bootstrap.php index 5540904..e29ad90 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -12,12 +12,13 @@ use Doctrine\Deprecations\Deprecation; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; +// Skip if we're using PHPUnit >=10 +if (class_exists(PHPUnit\Metadata\Metadata::class, false)) { + return; +} + // Detect if we need to serialize deprecations to a file. -if ( - // Skip if we're using PHPUnit >=10 - !class_exists(PHPUnit\Metadata\Metadata::class) - && in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE') -) { +if (in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { DeprecationErrorHandler::collectDeprecations($file); return; @@ -36,10 +37,6 @@ Deprecation::withoutDeduplication(); } -if ( - // Skip if we're using PHPUnit >=10 - !class_exists(PHPUnit\Metadata\Metadata::class, false) - && 'disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER') -) { +if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) { DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER')); } From 059b051b38f2138ef104dd848fa48f0cbbb7d78b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 28 Oct 2025 23:44:23 +0100 Subject: [PATCH 40/40] Fix the initialization of the phpunit bridge --- bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.php b/bootstrap.php index e29ad90..5191bef 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -13,7 +13,7 @@ use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; // Skip if we're using PHPUnit >=10 -if (class_exists(PHPUnit\Metadata\Metadata::class, false)) { +if (class_exists(PHPUnit\Metadata\Metadata::class)) { return; }