From 8fd16a6beef97910b6e2bf0d10547b31a314adc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 6 Aug 2019 22:56:33 +0200 Subject: [PATCH] Fix deprecation on 4.3 --- .travis.yml | 3 + .../PhpDumper/Fixtures/proxy-implem.php | 74 +++--- .../LazyProxy/PhpDumper/ProxyDumperTest.php | 6 +- .../Functional/ContainerDebugCommandTest.php | 6 +- .../UserPasswordEncoderCommandTest.php | 2 +- .../Cache/Tests/Adapter/AdapterTestCase.php | 12 +- .../Definition/Builder/NodeDefinitionTest.php | 31 ++- .../Tests/Compiler/AutowirePassTest.php | 215 +++++++++++------- .../Tests/Loader/FileLoaderTest.php | 4 + .../Extension/Core/Type/CountryTypeTest.php | 10 +- .../Extension/Core/Type/CurrencyTypeTest.php | 6 +- .../Extension/Core/Type/LanguageTypeTest.php | 8 +- .../Extension/Core/Type/LocaleTypeTest.php | 6 +- .../Tests/Transport/AbstractTransportTest.php | 12 +- .../Tests/Handler/HandlersLocatorTest.php | 15 +- .../Middleware/ActivationMiddlewareTest.php | 9 +- .../HandleMessageMiddlewareTest.php | 15 +- .../Transport/Doctrine/DoctrineSenderTest.php | 2 +- .../Serialization/PhpSerializerTest.php | 4 +- .../Serialization/SerializerTest.php | 2 +- .../Transport/Sync/SyncTransport.php | 2 +- .../VarDumper/Tests/Cloner/VarClonerTest.php | 2 + .../VarExporter/Tests/VarExporterTest.php | 8 + 23 files changed, 278 insertions(+), 176 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f4eda2ae16b..55c134dc0964 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,9 @@ matrix: env: deps=high - php: 7.3 env: deps=low + - php: 7.4snapshot + allow_failures: + - php: 7.4snapshot fast_finish: true cache: diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php index 165b0db0cc4a..3362aab9fb5e 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php @@ -1,21 +1,21 @@ initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, 'dummy', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'dummy', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - if ($this->valueHolder1eff735 === $returnValue = $this->valueHolder1eff735->dummy()) { + if ($this->valueHolder%s === $returnValue = $this->valueHolder%s->dummy()) { $returnValue = $this; } @@ -24,9 +24,9 @@ public function dummy() public function & dummyRef() { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, 'dummyRef', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'dummyRef', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - if ($this->valueHolder1eff735 === $returnValue = &$this->valueHolder1eff735->dummyRef()) { + if ($this->valueHolder%s === $returnValue = &$this->valueHolder%s->dummyRef()) { $returnValue = $this; } @@ -35,9 +35,9 @@ public function & dummyRef() public function sunny() { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, 'sunny', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'sunny', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - if ($this->valueHolder1eff735 === $returnValue = $this->valueHolder1eff735->sunny()) { + if ($this->valueHolder%s === $returnValue = $this->valueHolder%s->sunny()) { $returnValue = $this; } @@ -49,9 +49,9 @@ public static function staticProxyConstructor($initializer) static $reflection; $reflection = $reflection ?? new \ReflectionClass(__CLASS__); - $instance = $reflection->newInstanceWithoutConstructor(); + $instance%w= $reflection->newInstanceWithoutConstructor(); - $instance->initializer1eff735 = $initializer; + $instance->initializer%s = $initializer; return $instance; } @@ -60,21 +60,21 @@ public function __construct() { static $reflection; - if (! $this->valueHolder1eff735) { + if (! $this->valueHolder%s) { $reflection = $reflection ?? new \ReflectionClass(__CLASS__); - $this->valueHolder1eff735 = $reflection->newInstanceWithoutConstructor(); + $this->valueHolder%s = $reflection->newInstanceWithoutConstructor(); } } public function & __get($name) { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__get', ['name' => $name], $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__get', ['name' => $name], $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - if (isset(self::$publicProperties1eff735[$name])) { - return $this->valueHolder1eff735->$name; + if (isset(self::$publicProperties%s[$name])) { + return $this->valueHolder%s->$name; } - $targetObject = $this->valueHolder1eff735; + $targetObject = $this->valueHolder%s; $backtrace = debug_backtrace(false); trigger_error( @@ -92,27 +92,27 @@ public function & __get($name) public function __set($name, $value) { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__set', array('name' => $name, 'value' => $value), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__set', array('name' => $name, 'value' => $value), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - $targetObject = $this->valueHolder1eff735; + $targetObject = $this->valueHolder%s; return $targetObject->$name = $value; } public function __isset($name) { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__isset', array('name' => $name), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__isset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - $targetObject = $this->valueHolder1eff735; + $targetObject = $this->valueHolder%s; return isset($targetObject->$name); } public function __unset($name) { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__unset', array('name' => $name), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__unset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - $targetObject = $this->valueHolder1eff735; + $targetObject = $this->valueHolder%s; unset($targetObject->$name); return; @@ -120,45 +120,45 @@ public function __unset($name) public function __clone() { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__clone', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__clone', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - $this->valueHolder1eff735 = clone $this->valueHolder1eff735; + $this->valueHolder%s = clone $this->valueHolder%s; } public function __sleep() { - $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, '__sleep', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__sleep', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - return array('valueHolder1eff735'); + return array('valueHolder%s'); } public function __wakeup() { } - public function setProxyInitializer(\Closure $initializer = null) + public function setProxyInitializer(\Closure $initializer = null)%S { - $this->initializer1eff735 = $initializer; + $this->initializer%s = $initializer; } - public function getProxyInitializer() + public function getProxyInitializer()%S { - return $this->initializer1eff735; + return $this->initializer%s; } public function initializeProxy() : bool { - return $this->initializer1eff735 && ($this->initializer1eff735->__invoke($valueHolder1eff735, $this, 'initializeProxy', array(), $this->initializer1eff735) || 1) && $this->valueHolder1eff735 = $valueHolder1eff735; + return $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'initializeProxy', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; } public function isProxyInitialized() : bool { - return null !== $this->valueHolder1eff735; + return null !== $this->valueHolder%s; } - public function getWrappedValueHolderValue() + public function getWrappedValueHolderValue()%S { - return $this->valueHolder1eff735; + return $this->valueHolder%s; } diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php index abb0c8abbfa7..416b51cfa3b5 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php @@ -168,12 +168,12 @@ protected function createProxy(\$class, \Closure \$factory) EOPHP; $implem = preg_replace('#\n /\*\*.*?\*/#s', '', $implem); - $implem = str_replace('getWrappedValueHolderValue() : ?object', 'getWrappedValueHolderValue()', $implem); $implem = str_replace("array(\n \n );", "[\n \n ];", $implem); - $this->assertStringEqualsFile(__DIR__.'/Fixtures/proxy-implem.php', $implem); + + $this->assertStringMatchesFormatFile(__DIR__.'/Fixtures/proxy-implem.php', $implem); $this->assertStringEqualsFile(__DIR__.'/Fixtures/proxy-factory.php', $factory); - require_once __DIR__.'/Fixtures/proxy-implem.php'; + eval(preg_replace('/^<\?php/', '', $implem)); $factory = require __DIR__.'/Fixtures/proxy-factory.php'; $foo = $factory->getFooService(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php index aeb7f44410fe..b7b1420e41ee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php @@ -57,8 +57,8 @@ public function testPrivateAlias() $tester = new ApplicationTester($application); $tester->run(['command' => 'debug:container', '--show-hidden' => true]); - $this->assertNotContains('public', $tester->getDisplay()); - $this->assertNotContains('private_alias', $tester->getDisplay()); + $this->assertStringNotContainsString('public', $tester->getDisplay()); + $this->assertStringNotContainsString('private_alias', $tester->getDisplay()); $tester->run(['command' => 'debug:container']); $this->assertStringContainsString('public', $tester->getDisplay()); @@ -77,7 +77,7 @@ public function testIgnoreBackslashWhenFindingService(string $validServiceId) $tester = new ApplicationTester($application); $tester->run(['command' => 'debug:container', 'name' => $validServiceId]); - $this->assertNotContains('No services found', $tester->getDisplay()); + $this->assertStringNotContainsString('No services found', $tester->getDisplay()); } public function testDescribeEnvVars() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php index 55064d863a19..e925807e22d9 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php @@ -227,7 +227,7 @@ public function testEncodePasswordSodiumOutput() 'user-class' => 'Custom\Class\Sodium\User', ], ['interactive' => false]); - $this->assertNotContains(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay()); + $this->assertStringNotContainsString(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay()); } public function testEncodePasswordNoConfigForGivenUserClass() diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php index 93318ffd481f..1b225e83eb3f 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php @@ -13,6 +13,7 @@ use Cache\IntegrationTests\CachePoolTest; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Warning; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\CacheItem; @@ -120,7 +121,7 @@ public function testGetMetadata() CacheItem::METADATA_EXPIRY => 9.5 + time(), CacheItem::METADATA_CTIME => 1000, ]; - $this->assertEquals($expected, $item->getMetadata(), 'Item metadata should embed expiry and ctime.', .6); + $this->assertEqualsWithDelta($expected, $item->getMetadata(), .6, 'Item metadata should embed expiry and ctime.'); } public function testDefaultLifeTime() @@ -252,6 +253,15 @@ public function testPrune() $this->assertFalse($this->isPruned($cache, 'foo')); $this->assertTrue($this->isPruned($cache, 'qux')); } + + public function testSavingObject() + { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + + parent::testSavingObject(); + } } class NotUnserializable diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/NodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/NodeDefinitionTest.php index fba713386a0a..68c1ddff00d9 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/NodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/NodeDefinitionTest.php @@ -14,26 +14,25 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition; class NodeDefinitionTest extends TestCase { - public function testDefaultPathSeparatorIsDot() - { - $node = $this->getMockForAbstractClass(NodeDefinition::class, ['foo']); - - $this->assertAttributeSame('.', 'pathSeparator', $node); - } - public function testSetPathSeparatorChangesChildren() { - $node = new ArrayNodeDefinition('foo'); - $scalar = new ScalarNodeDefinition('bar'); - $node->append($scalar); - - $node->setPathSeparator('/'); - - $this->assertAttributeSame('/', 'pathSeparator', $node); - $this->assertAttributeSame('/', 'pathSeparator', $scalar); + $parentNode = new ArrayNodeDefinition('name'); + $childNode = $this->createMock(NodeDefinition::class); + + $childNode + ->expects($this->once()) + ->method('setPathSeparator') + ->with('/'); + $childNode + ->expects($this->once()) + ->method('setParent') + ->with($parentNode) + ->willReturn($childNode); + $parentNode->append($childNode); + + $parentNode->setPathSeparator('/'); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 39b3a93889d9..f3365a012885 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -53,8 +53,6 @@ public function testProcess() public function testProcessNotExistingActionParam() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\CompilerEslaAction": argument "$notExisting" of method "Symfony\Component\DependencyInjection\Tests\Compiler\ElsaAction::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotExisting" but this class was not found.'); $container = new ContainerBuilder(); $container->register(Foo::class); @@ -62,7 +60,12 @@ public function testProcessNotExistingActionParam() $barDefinition->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\CompilerEslaAction": argument "$notExisting" of method "Symfony\Component\DependencyInjection\Tests\Compiler\ElsaAction::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotExisting" but this class was not found.', (string) $e->getMessage()); + } } public function testProcessVariadic() @@ -81,8 +84,6 @@ public function testProcessVariadic() public function testProcessAutowireParent() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); - $this->expectExceptionMessage('Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.'); $container = new ContainerBuilder(); $container->register(B::class); @@ -90,16 +91,16 @@ public function testProcessAutowireParent() $cDefinition->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); - - $this->assertCount(1, $container->getDefinition('c')->getArguments()); - $this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0)); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.', (string) $e->getMessage()); + } } public function testProcessAutowireInterface() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); - $this->expectExceptionMessage('Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.'); $container = new ContainerBuilder(); $container->register(F::class); @@ -107,12 +108,12 @@ public function testProcessAutowireInterface() $gDefinition->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); - - $this->assertCount(3, $container->getDefinition('g')->getArguments()); - $this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(0)); - $this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(1)); - $this->assertEquals(F::class, (string) $container->getDefinition('g')->getArgument(2)); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.', (string) $e->getMessage()); + } } public function testCompleteExistingDefinition() @@ -151,20 +152,21 @@ public function testCompleteExistingDefinitionWithNotDefinedArguments() public function testPrivateConstructorThrowsAutowireException() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.'); $container = new ContainerBuilder(); $container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor'); $pass = new AutowirePass(true); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.', (string) $e->getMessage()); + } } public function testTypeCollision() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".'); $container = new ContainerBuilder(); $container->register('c1', __NAMESPACE__.'\CollisionA'); @@ -174,13 +176,16 @@ public function testTypeCollision() $aDefinition->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".', (string) $e->getMessage()); + } } public function testTypeNotGuessable() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".'); $container = new ContainerBuilder(); $container->register('a1', __NAMESPACE__.'\Foo'); @@ -189,13 +194,16 @@ public function testTypeNotGuessable() $aDefinition->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".', (string) $e->getMessage()); + } } public function testTypeNotGuessableWithSubclass() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".'); $container = new ContainerBuilder(); $container->register('a1', __NAMESPACE__.'\B'); @@ -204,20 +212,28 @@ public function testTypeNotGuessableWithSubclass() $aDefinition->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".', (string) $e->getMessage()); + } } public function testTypeNotGuessableNoServicesFound() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists.'); $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); $aDefinition->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. Did you create a class that implements this interface?', (string) $e->getMessage()); + } } public function testTypeNotGuessableWithTypeSet() @@ -256,15 +272,18 @@ public function testWithTypeSet() public function testServicesAreNotAutoCreated() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "coop_tilleuls": argument "$j" of method "Symfony\Component\DependencyInjection\Tests\Compiler\LesTilleuls::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas" but no such service exists.'); $container = new ContainerBuilder(); $coopTilleulsDefinition = $container->register('coop_tilleuls', __NAMESPACE__.'\LesTilleuls'); $coopTilleulsDefinition->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "coop_tilleuls": argument "$j" of method "Symfony\Component\DependencyInjection\Tests\Compiler\LesTilleuls::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas" but no such service exists.', (string) $e->getMessage()); + } } public function testResolveParameter() @@ -315,8 +334,6 @@ public function testDontTriggerAutowiring() public function testClassNotFoundThrowsException() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'); $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument'); @@ -325,13 +342,16 @@ public function testClassNotFoundThrowsException() $container->register(Dunglas::class, Dunglas::class); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.', (string) $e->getMessage()); + } } public function testParentClassNotFoundThrowsException() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } @@ -344,13 +364,16 @@ public function testParentClassNotFoundThrowsException() $container->register(Dunglas::class, Dunglas::class); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).', (string) $e->getMessage()); + } } public function testDontUseAbstractServices() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.'); $container = new ContainerBuilder(); $container->register(Foo::class)->setAbstract(true); @@ -358,7 +381,12 @@ public function testDontUseAbstractServices() $container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.', (string) $e->getMessage()); + } } public function testSomeSpecificArgumentsAreSet() @@ -394,8 +422,6 @@ public function testSomeSpecificArgumentsAreSet() public function testScalarArgsCannotBeAutowired() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.'); $container = new ContainerBuilder(); $container->register(A::class); @@ -405,13 +431,16 @@ public function testScalarArgsCannotBeAutowired() ->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.', (string) $e->getMessage()); + } } public function testNoTypeArgsCannotBeAutowired() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.'); $container = new ContainerBuilder(); $container->register(A::class); @@ -420,7 +449,12 @@ public function testNoTypeArgsCannotBeAutowired() ->setAutowired(true); (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.', (string) $e->getMessage()); + } } public function testOptionalScalarNotReallyOptionalUsesDefaultValue() @@ -544,7 +578,7 @@ public function testSetterInjection() */ public function testWithNonExistingSetterAndAutowiring() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(RuntimeException::class); $container = new ContainerBuilder(); $definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true); @@ -629,17 +663,14 @@ public function testSetterInjectionCollisionThrowsException() try { $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', (string) $e->getMessage()); } - - $this->assertNotNull($e); - $this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', (string) $e->getMessage()); } public function testInterfaceWithNoImplementationSuggestToWriteOne() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?'); $container = new ContainerBuilder(); $aDefinition = $container->register('my_service', K::class); @@ -648,20 +679,28 @@ public function testInterfaceWithNoImplementationSuggestToWriteOne() (new AutowireRequiredMethodsPass())->process($container); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?', (string) $e->getMessage()); + } } public function testProcessDoesNotTriggerDeprecations() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.'); $container = new ContainerBuilder(); $container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true); $container->register('foo', __NAMESPACE__.'\Foo'); $container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.', (string) $e->getMessage()); + } $this->assertTrue($container->hasDefinition('deprecated')); $this->assertTrue($container->hasDefinition('foo')); @@ -704,7 +743,6 @@ public function testWithFactory() */ public function testNotWireableCalls($method, $expectedMsg) { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); $container = new ContainerBuilder(); $foo = $container->register('foo', NotWireable::class)->setAutowired(true) @@ -718,12 +756,14 @@ public function testNotWireableCalls($method, $expectedMsg) $foo->addMethodCall($method, []); } - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage($expectedMsg); - (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should throw a RuntimeException.'); + } catch (RuntimeException $e) { + $this->assertSame($expectedMsg, (string) $e->getMessage()); + } } public function provideNotWireableCalls() @@ -737,8 +777,6 @@ public function provideNotWireableCalls() public function testSuggestRegisteredServicesWithSimilarCase() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "foo": argument "$sam" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireableBecauseOfATypo()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\lesTilleuls" but no such service exists. Did you mean "Symfony\Component\DependencyInjection\Tests\Compiler\LesTilleuls"?'); $container = new ContainerBuilder(); $container->register(LesTilleuls::class, LesTilleuls::class); @@ -748,13 +786,16 @@ public function testSuggestRegisteredServicesWithSimilarCase() (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "foo": argument "$sam" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireableBecauseOfATypo()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\lesTilleuls" but no such service exists. Did you mean "Symfony\Component\DependencyInjection\Tests\Compiler\LesTilleuls"?', (string) $e->getMessage()); + } } public function testByIdAlternative() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.'); $container = new ContainerBuilder(); $container->setAlias(IInterface::class, 'i'); @@ -763,13 +804,16 @@ public function testByIdAlternative() ->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.', (string) $e->getMessage()); + } } public function testExceptionWhenAliasExists() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.'); $container = new ContainerBuilder(); // multiple I services... but there *is* IInterface available @@ -781,13 +825,16 @@ public function testExceptionWhenAliasExists() ->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.', (string) $e->getMessage()); + } } public function testExceptionWhenAliasDoesNotExist() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } @@ -802,7 +849,12 @@ public function testExceptionWhenAliasDoesNotExist() ->setAutowired(true); $pass = new AutowirePass(); - $pass->process($container); + try { + $pass->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".', (string) $e->getMessage()); + } } public function testInlineServicesAreNotCandidates() @@ -878,8 +930,6 @@ public function testAutowireDecoratorRenamedId() public function testDoNotAutowireDecoratorWhenSeveralArgumentOfTheType() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator": argument "$decorated1" of method "__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratorInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator", "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator.inner".'); $container = new ContainerBuilder(); $container->register(LoggerInterface::class, NullLogger::class); $container->register(Decorated::class, Decorated::class); @@ -890,7 +940,12 @@ public function testDoNotAutowireDecoratorWhenSeveralArgumentOfTheType() ; (new DecoratorServicePass())->process($container); - (new AutowirePass())->process($container); + try { + (new AutowirePass())->process($container); + $this->fail('AutowirePass should have thrown an exception'); + } catch (AutowiringFailedException $e) { + $this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator": argument "$decorated1" of method "__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratorInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator", "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator.inner".', (string) $e->getMessage()); + } } public function testErroredServiceLocator() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php index 0a8085de0e23..929ff1fab017 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php @@ -142,6 +142,10 @@ public function testRegisterClassesWithExclude() public function testRegisterClassesWithExcludeAsArray() { + 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('sub_dir', 'Sub'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index 9cadc9cd745f..55dbbb28b64a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -51,11 +51,11 @@ public function testChoiceTranslationLocaleOption() ->createView()->vars['choices']; // Don't check objects for identity - $this->assertContains(new ChoiceView('DE', 'DE', 'Німеччина'), $choices, '', false, false); - $this->assertContains(new ChoiceView('GB', 'GB', 'Велика Британія'), $choices, '', false, false); - $this->assertContains(new ChoiceView('US', 'US', 'Сполучені Штати'), $choices, '', false, false); - $this->assertContains(new ChoiceView('FR', 'FR', 'Франція'), $choices, '', false, false); - $this->assertContains(new ChoiceView('MY', 'MY', 'Малайзія'), $choices, '', false, false); + $this->assertContainsEquals(new ChoiceView('DE', 'DE', 'Німеччина'), $choices); + $this->assertContainsEquals(new ChoiceView('GB', 'GB', 'Велика Британія'), $choices); + $this->assertContainsEquals(new ChoiceView('US', 'US', 'Сполучені Штати'), $choices); + $this->assertContainsEquals(new ChoiceView('FR', 'FR', 'Франція'), $choices); + $this->assertContainsEquals(new ChoiceView('MY', 'MY', 'Малайзія'), $choices); } public function testUnknownCountryIsNotIncluded() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php index 7a8c1509ba7e..b21aa73d0bab 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php @@ -48,9 +48,9 @@ public function testChoiceTranslationLocaleOption() ->createView()->vars['choices']; // Don't check objects for identity - $this->assertContains(new ChoiceView('EUR', 'EUR', 'євро'), $choices, '', false, false); - $this->assertContains(new ChoiceView('USD', 'USD', 'долар США'), $choices, '', false, false); - $this->assertContains(new ChoiceView('SIT', 'SIT', 'словенський толар'), $choices, '', false, false); + $this->assertContainsEquals(new ChoiceView('EUR', 'EUR', 'євро'), $choices); + $this->assertContainsEquals(new ChoiceView('USD', 'USD', 'долар США'), $choices); + $this->assertContainsEquals(new ChoiceView('SIT', 'SIT', 'словенський толар'), $choices); } public function testSubmitNull($expected = null, $norm = null, $view = null) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index 960aef1994b9..a27399519cd9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -50,10 +50,10 @@ public function testChoiceTranslationLocaleOption() ->createView()->vars['choices']; // Don't check objects for identity - $this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false); - $this->assertContains(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices, '', false, false); - $this->assertContains(new ChoiceView('fr', 'fr', 'французька'), $choices, '', false, false); - $this->assertContains(new ChoiceView('my', 'my', 'бірманська'), $choices, '', false, false); + $this->assertContainsEquals(new ChoiceView('en', 'en', 'англійська'), $choices); + $this->assertContainsEquals(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices); + $this->assertContainsEquals(new ChoiceView('fr', 'fr', 'французька'), $choices); + $this->assertContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices); } public function testMultipleLanguagesIsNotIncluded() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php index c5ba0da6917d..b7103b635a48 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php @@ -48,9 +48,9 @@ public function testChoiceTranslationLocaleOption() ->createView()->vars['choices']; // Don't check objects for identity - $this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false); - $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'англійська (Велика Британія)'), $choices, '', false, false); - $this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'китайська (традиційна, Макао, О.А.Р Китаю)'), $choices, '', false, false); + $this->assertContainsEquals(new ChoiceView('en', 'en', 'англійська'), $choices); + $this->assertContainsEquals(new ChoiceView('en_GB', 'en_GB', 'англійська (Велика Британія)'), $choices); + $this->assertContainsEquals(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'китайська (традиційна, Макао, О.А.Р Китаю)'), $choices); } public function testSubmitNull($expected = null, $norm = null, $view = null) diff --git a/src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php index d3d8e438bd3f..1d0bee96f646 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php @@ -31,19 +31,19 @@ public function testThrottling() $start = time(); $transport->send($message, $envelope); - $this->assertEquals(0, time() - $start, '', 1); + $this->assertEqualsWithDelta(0, time() - $start, 1); $transport->send($message, $envelope); - $this->assertEquals(5, time() - $start, '', 1); + $this->assertEqualsWithDelta(5, time() - $start, 1); $transport->send($message, $envelope); - $this->assertEquals(10, time() - $start, '', 1); + $this->assertEqualsWithDelta(10, time() - $start, 1); $transport->send($message, $envelope); - $this->assertEquals(15, time() - $start, '', 1); + $this->assertEqualsWithDelta(15, time() - $start, 1); $start = time(); $transport->setMaxPerSecond(-3); $transport->send($message, $envelope); - $this->assertEquals(0, time() - $start, '', 1); + $this->assertEqualsWithDelta(0, time() - $start, 1); $transport->send($message, $envelope); - $this->assertEquals(0, time() - $start, '', 1); + $this->assertEqualsWithDelta(0, time() - $start, 1); } } diff --git a/src/Symfony/Component/Messenger/Tests/Handler/HandlersLocatorTest.php b/src/Symfony/Component/Messenger/Tests/Handler/HandlersLocatorTest.php index 48e546afa1a8..1c00a751e9d0 100644 --- a/src/Symfony/Component/Messenger/Tests/Handler/HandlersLocatorTest.php +++ b/src/Symfony/Component/Messenger/Tests/Handler/HandlersLocatorTest.php @@ -22,7 +22,7 @@ class HandlersLocatorTest extends TestCase { public function testItYieldsHandlerDescriptors() { - $handler = $this->createPartialMock(\stdClass::class, ['__invoke']); + $handler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']); $locator = new HandlersLocator([ DummyMessage::class => [$handler], ]); @@ -32,13 +32,13 @@ public function testItYieldsHandlerDescriptors() public function testItReturnsOnlyHandlersMatchingTransport() { - $firstHandler = $this->createPartialMock(\stdClass::class, ['__invoke']); - $secondHandler = $this->createPartialMock(\stdClass::class, ['__invoke']); + $firstHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']); + $secondHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']); $locator = new HandlersLocator([ DummyMessage::class => [ $first = new HandlerDescriptor($firstHandler, ['alias' => 'one']), - new HandlerDescriptor($this->createPartialMock(\stdClass::class, ['__invoke']), ['from_transport' => 'ignored', 'alias' => 'two']), + new HandlerDescriptor($this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']), ['from_transport' => 'ignored', 'alias' => 'two']), $second = new HandlerDescriptor($secondHandler, ['from_transport' => 'transportName', 'alias' => 'three']), ], ]); @@ -51,3 +51,10 @@ public function testItReturnsOnlyHandlersMatchingTransport() ))); } } + +class HandlersLocatorTestCallable +{ + public function __invoke() + { + } +} diff --git a/src/Symfony/Component/Messenger/Tests/Middleware/ActivationMiddlewareTest.php b/src/Symfony/Component/Messenger/Tests/Middleware/ActivationMiddlewareTest.php index 5c28c0de7cd0..192e5714c660 100644 --- a/src/Symfony/Component/Messenger/Tests/Middleware/ActivationMiddlewareTest.php +++ b/src/Symfony/Component/Messenger/Tests/Middleware/ActivationMiddlewareTest.php @@ -42,7 +42,7 @@ public function testExecuteMiddlewareOnActivatedWithCallable() $message = new DummyMessage('Hello'); $envelope = new Envelope($message); - $activated = $this->createPartialMock(\stdClass::class, ['__invoke']); + $activated = $this->createPartialMock(ActivationMiddlewareTestCallable::class, ['__invoke']); $activated->expects($this->once())->method('__invoke')->with($envelope)->willReturn(true); $stack = $this->getStackMock(false); @@ -68,3 +68,10 @@ public function testExecuteMiddlewareOnDeactivated() $decorator->handle($envelope, $this->getStackMock()); } } + +class ActivationMiddlewareTestCallable +{ + public function __invoke() + { + } +} diff --git a/src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php b/src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php index 667f4f696194..3ed20e06016f 100644 --- a/src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php +++ b/src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php @@ -28,7 +28,7 @@ public function testItCallsTheHandlerAndNextMiddleware() $message = new DummyMessage('Hey'); $envelope = new Envelope($message); - $handler = $this->createPartialMock(\stdClass::class, ['__invoke']); + $handler = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']); $middleware = new HandleMessageMiddleware(new HandlersLocator([ DummyMessage::class => [$handler], @@ -62,15 +62,15 @@ public function testItAddsHandledStamps(array $handlers, array $expectedStamps, public function itAddsHandledStampsProvider() { - $first = $this->createPartialMock(\stdClass::class, ['__invoke']); + $first = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']); $first->method('__invoke')->willReturn('first result'); $firstClass = \get_class($first); - $second = $this->createPartialMock(\stdClass::class, ['__invoke']); + $second = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']); $second->method('__invoke')->willReturn(null); $secondClass = \get_class($second); - $failing = $this->createPartialMock(\stdClass::class, ['__invoke']); + $failing = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']); $failing->method('__invoke')->will($this->throwException(new \Exception('handler failed.'))); yield 'A stamp is added' => [ @@ -129,3 +129,10 @@ public function testAllowNoHandlers() $this->assertInstanceOf(Envelope::class, $middleware->handle(new Envelope(new DummyMessage('Hey')), new StackMiddleware())); } } + +class HandleMessageMiddlewareTestCallable +{ + public function __invoke() + { + } +} diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php index c65c72ecf439..cb2d194ae1a2 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineSenderTest.php @@ -28,7 +28,7 @@ public function testSend() $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]]; $connection = $this->createMock(Connection::class); - $connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'])->willReturn(15); + $connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'])->willReturn('15'); $serializer = $this->createMock(SerializerInterface::class); $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded); diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php index c146d2619df5..6439873fe94c 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php @@ -27,7 +27,7 @@ public function testEncodedIsDecodable() $envelope = new Envelope(new DummyMessage('Hello')); $encoded = $serializer->encode($envelope); - $this->assertNotContains("\0", $encoded['body'], 'Does not contain the binary characters'); + $this->assertStringNotContainsString("\0", $encoded['body'], 'Does not contain the binary characters'); $this->assertEquals($envelope, $serializer->decode($encoded)); } @@ -74,7 +74,7 @@ public function testEncodedSkipsNonEncodeableStamps() ]); $encoded = $serializer->encode($envelope); - $this->assertNotContains('DummyPhpSerializerNonSendableStamp', $encoded['body']); + $this->assertStringNotContainsString('DummyPhpSerializerNonSendableStamp', $encoded['body']); } } diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php index 897e4b10e0f1..73cbfb6cb957 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php @@ -205,7 +205,7 @@ public function testEncodedSkipsNonEncodeableStamps() ]); $encoded = $serializer->encode($envelope); - $this->assertNotContains('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true)); + $this->assertStringNotContainsString('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true)); } } class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface diff --git a/src/Symfony/Component/Messenger/Transport/Sync/SyncTransport.php b/src/Symfony/Component/Messenger/Transport/Sync/SyncTransport.php index 0553f839393e..72f84fafb67c 100644 --- a/src/Symfony/Component/Messenger/Transport/Sync/SyncTransport.php +++ b/src/Symfony/Component/Messenger/Transport/Sync/SyncTransport.php @@ -58,7 +58,7 @@ public function send(Envelope $envelope): Envelope { /** @var SentStamp|null $sentStamp */ $sentStamp = $envelope->last(SentStamp::class); - $alias = null === $sentStamp ? 'sync' : $sentStamp->getSenderAlias() ?: $sentStamp->getSenderClass(); + $alias = null === $sentStamp ? 'sync' : ($sentStamp->getSenderAlias() ?: $sentStamp->getSenderClass()); $envelope = $envelope->with(new ReceivedStamp($alias)); diff --git a/src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php b/src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php index 9c84f898bbe0..334d5879d499 100644 --- a/src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php @@ -466,6 +466,8 @@ public function testPhp74() [position] => 1 [attr] => Array ( + [file] => %s + [line] => 5 ) ) diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index 51f58c54c986..a069bcf42132 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\VarExporter\Tests; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; use Symfony\Component\VarExporter\Internal\Registry; use Symfony\Component\VarExporter\VarExporter; @@ -75,6 +76,13 @@ public function provideFailingSerialization() */ public function testExport(string $testName, $value, bool $staticValueExpected = false) { + if (\PHP_VERSION_ID >= 70400 && 'datetime' === $testName) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78383.'); + } + if (\PHP_VERSION_ID >= 70400 && \in_array($testName, ['spl-object-storage', 'array-object-custom', 'array-iterator', 'array-object', 'final-array-iterator'])) { + throw new Warning('PHP 7.4 breaks this test.'); + } + $dumpedValue = $this->getDump($value); $isStaticValue = true; $marshalledValue = VarExporter::export($value, $isStaticValue);