From c2c7ba82df194a0b42d57d47f21db725001433f3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 14:16:51 +0200 Subject: [PATCH 1/3] Skip tests that fatal-error on PHP 7.4 because of missing parent classes --- .../Tests/CacheWarmer/ValidatorCacheWarmerTest.php | 5 +++++ .../Tests/Resource/ClassExistenceResourceTest.php | 9 +++++++++ .../Tests/Compiler/AutowirePassTest.php | 13 +++++++++++++ .../Tests/Compiler/ResolveBindingsPassTest.php | 5 +++++ .../Tests/Dumper/PhpDumperTest.php | 5 +++++ .../Tests/Loader/FileLoaderTest.php | 13 +++++++++++++ 6 files changed, 50 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php index 868bd83cf7..416f4b6123 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; +use PHPUnit\Framework\Warning; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; @@ -26,6 +27,10 @@ class ValidatorCacheWarmerTest extends TestCase public function testWarmUp() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $validatorBuilder = new ValidatorBuilder(); $validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml'); $validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml'); diff --git a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php index 79bc64d69b..5612e7ca24 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Tests\Resource; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\Config\Resource\ClassExistenceResource; use Symfony\Component\Config\Tests\Fixtures\BadParent; use Symfony\Component\Config\Tests\Fixtures\Resource\ConditionalClass; @@ -77,6 +78,10 @@ EOF public function testBadParentWithTimestamp() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $res = new ClassExistenceResource(BadParent::class, false); $this->assertTrue($res->isFresh(time())); } @@ -87,6 +92,10 @@ EOF */ public function testBadParentWithNoTimestamp() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $res = new ClassExistenceResource(BadParent::class, false); $res->isFresh(0); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 31fa665ae7..85979f367e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; @@ -395,6 +396,10 @@ class AutowirePassTest extends TestCase */ public function testParentClassNotFoundThrowsException() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument'); @@ -707,6 +712,10 @@ class AutowirePassTest extends TestCase public function testIgnoreServiceWithClassNotExisting() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass'); @@ -917,6 +926,10 @@ class AutowirePassTest extends TestCase */ public function testExceptionWhenAliasDoesNotExist() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); // multiple I instances... but no IInterface alias diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php index 7bbecf6207..303e3abd49 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; @@ -69,6 +70,10 @@ class ResolveBindingsPassTest extends TestCase */ public function testMissingParent() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $definition = $container->register(ParentNotExists::class, ParentNotExists::class); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index b4e3610773..6a5cff1089 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; @@ -906,6 +907,10 @@ class PhpDumperTest extends TestCase public function testHotPathOptimizations() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = include self::$fixturesPath.'/containers/container_inline_requires.php'; $container->setParameter('inline_requires', true); $container->compile(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php index ee102c75bb..8493642b4c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface as PsrContainerInterface; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; @@ -112,6 +113,10 @@ class FileLoaderTest extends TestCase public function testRegisterClassesWithExclude() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->setParameter('other_dir', 'OtherDir'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -141,6 +146,10 @@ class FileLoaderTest extends TestCase public function testNestedRegisterClasses() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -169,6 +178,10 @@ class FileLoaderTest extends TestCase public function testMissingParentClass() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->setParameter('bad_classes_dir', 'BadClasses'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); From abcd45a5877f7526c1c8e4b464a8e6e18365295d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 14:45:14 +0200 Subject: [PATCH 2/3] Add polyfill for TestCase::createMock() --- .../Bridge/PhpUnit/ForwardCompatTestTrait.php | 11 ++++-- .../Legacy/ForwardCompatTestTraitForV5.php | 21 +++++++++++ .../Legacy/ForwardCompatTestTraitForV7.php | 35 +++++++++++++++++++ .../ValidatorDataCollectorTest.php | 8 ++--- .../Validator/TraceableValidatorTest.php | 8 ++--- 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php diff --git a/src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php b/src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php index bdff8c1882..29597bbe10 100644 --- a/src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php +++ b/src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php @@ -15,7 +15,14 @@ use PHPUnit\Framework\TestCase; // A trait to provide forward compatibility with newest PHPUnit versions -if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { +$r = new \ReflectionClass(TestCase::class); + +if (\PHP_VERSION_ID < 70000 || !$r->hasMethod('createMock') || !$r->getMethod('createMock')->hasReturnType()) { + trait ForwardCompatTestTrait + { + use Legacy\ForwardCompatTestTraitForV5; + } +} elseif ($r->getMethod('tearDown')->hasReturnType()) { trait ForwardCompatTestTrait { use Legacy\ForwardCompatTestTraitForV8; @@ -23,6 +30,6 @@ if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \Reflection } else { trait ForwardCompatTestTrait { - use Legacy\ForwardCompatTestTraitForV5; + use Legacy\ForwardCompatTestTraitForV7; } } diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php b/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php index 5ef837434a..36db32e55f 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php @@ -11,6 +11,8 @@ namespace Symfony\Bridge\PhpUnit\Legacy; +use PHPUnit\Framework\MockObject\MockObject; + /** * @internal */ @@ -80,6 +82,25 @@ trait ForwardCompatTestTraitForV5 parent::tearDown(); } + /** + * @param string $originalClassName + * + * @return MockObject + */ + protected function createMock($originalClassName) + { + $mock = $this->getMockBuilder($originalClassName) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning(); + + if (method_exists($mock, 'disallowMockingUnknownTypes')) { + $mock = $mock->disallowMockingUnknownTypes(); + } + + return $mock->getMock(); + } + /** * @param string $message * diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php b/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php new file mode 100644 index 0000000000..84a26faebe --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php @@ -0,0 +1,35 @@ + + * + * 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\MockObject\MockObject; + +/** + * @internal + */ +trait ForwardCompatTestTraitForV7 +{ + use ForwardCompatTestTraitForV5; + + /** + * @param string|string[] $originalClassName + */ + protected function createMock($originalClassName): MockObject + { + return $this->getMockBuilder($originalClassName) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning() + ->disallowMockingUnknownTypes() + ->getMock(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/DataCollector/ValidatorDataCollectorTest.php b/src/Symfony/Component/Validator/Tests/DataCollector/ValidatorDataCollectorTest.php index f32acf228b..00407b3ab0 100644 --- a/src/Symfony/Component/Validator/Tests/DataCollector/ValidatorDataCollectorTest.php +++ b/src/Symfony/Component/Validator/Tests/DataCollector/ValidatorDataCollectorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Tests\DataCollector; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\DataCollector\ValidatorDataCollector; @@ -20,6 +21,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; class ValidatorDataCollectorTest extends TestCase { + use ForwardCompatTestTrait; + public function testCollectsValidatorCalls() { $originalValidator = $this->createMock(ValidatorInterface::class); @@ -71,9 +74,4 @@ class ValidatorDataCollectorTest extends TestCase $this->assertCount(0, $collector->getCalls()); $this->assertSame(0, $collector->getViolationsCount()); } - - protected function createMock($classname) - { - return $this->getMockBuilder($classname)->disableOriginalConstructor()->getMock(); - } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/TraceableValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/TraceableValidatorTest.php index b80efed27e..2e76466b1c 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/TraceableValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/TraceableValidatorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Tests\Validator; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -23,6 +24,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; class TraceableValidatorTest extends TestCase { + use ForwardCompatTestTrait; + public function testValidate() { $originalValidator = $this->createMock(ValidatorInterface::class); @@ -95,9 +98,4 @@ class TraceableValidatorTest extends TestCase $expects('validatePropertyValue')->willReturn($expected = new ConstraintViolationList()); $this->assertSame($expected, $validator->validatePropertyValue(new \stdClass(), 'property', 'value'), 'returns original validator validatePropertyValue() result'); } - - protected function createMock($classname) - { - return $this->getMockBuilder($classname)->disableOriginalConstructor()->getMock(); - } } From 9f40b100e5f0abc8ab1bfba6d63918027f6ef9f9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 14:52:58 +0200 Subject: [PATCH 3/3] [Yaml] fix test for PHP 7.4 --- src/Symfony/Component/Yaml/Tests/ParserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index d3217b6302..1a60f7979a 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -25,12 +25,12 @@ class ParserTest extends TestCase /** @var Parser */ protected $parser; - protected function setUp() + private function doSetUp() { $this->parser = new Parser(); } - protected function tearDown() + private function doTearDown() { $this->parser = null;