diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php index 2318c2da62..7518cf4242 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php @@ -39,6 +39,11 @@ class CachePoolsTest extends WebTestCase { try { $this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class); + } catch (\PHPUnit\Framework\Error\Warning $e) { + if (0 !== strpos($e->getMessage(), 'unable to connect to')) { + throw $e; + } + $this->markTestSkipped($e->getMessage()); } catch (\PHPUnit_Framework_Error_Warning $e) { if (0 !== strpos($e->getMessage(), 'unable to connect to')) { throw $e; @@ -59,6 +64,11 @@ class CachePoolsTest extends WebTestCase { try { $this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class); + } catch (\PHPUnit\Framework\Error\Warning $e) { + if (0 !== strpos($e->getMessage(), 'unable to connect to')) { + throw $e; + } + $this->markTestSkipped($e->getMessage()); } catch (\PHPUnit_Framework_Error_Warning $e) { if (0 !== strpos($e->getMessage(), 'unable to connect to')) { throw $e; diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php index 35d8980f3f..b0d2b9cb8a 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php @@ -23,7 +23,7 @@ class PdoAdapterTest extends AdapterTestCase public static function setupBeforeClass() { if (!extension_loaded('pdo_sqlite')) { - throw new \PHPUnit_Framework_SkippedTestError('Extension pdo_sqlite required.'); + self::markTestSkipped('Extension pdo_sqlite required.'); } self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php index fd1c1794db..b9c396fdc5 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php @@ -24,7 +24,7 @@ class PdoDbalAdapterTest extends AdapterTestCase public static function setupBeforeClass() { if (!extension_loaded('pdo_sqlite')) { - throw new \PHPUnit_Framework_SkippedTestError('Extension pdo_sqlite required.'); + self::markTestSkipped('Extension pdo_sqlite required.'); } self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php index 9b2b647a7b..65722f4fde 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php @@ -112,7 +112,12 @@ class FactoryReturnTypePassTest extends TestCase $factory->setFactory(array(FactoryDummy::class, 'createFactory')); if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { - $this->setExpectedException(\RuntimeException::class, 'Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.'); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.'); + } else { + $this->setExpectedException(\RuntimeException::class, 'Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.'); + } } $container->compile(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ParameterBag/ParameterBagTest.php b/src/Symfony/Component/DependencyInjection/Tests/ParameterBag/ParameterBagTest.php index b95c2e082b..391e0eb3ff 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ParameterBag/ParameterBagTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ParameterBag/ParameterBagTest.php @@ -84,7 +84,12 @@ class ParameterBagTest extends TestCase 'fiz' => array('bar' => array('boo' => 12)), )); - $this->setExpectedException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException', $exceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException(ParameterNotFoundException::class); + $this->expectExceptionMessage($exceptionMessage); + } else { + $this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage); + } $bag->get($parameterKey); } diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php index 57ce78be6b..447316111b 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php @@ -75,7 +75,7 @@ class ParserCacheAdapterTest extends TestCase { $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->getItems(); } @@ -85,7 +85,7 @@ class ParserCacheAdapterTest extends TestCase $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $key = 'key'; $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->hasItem($key); } @@ -94,7 +94,7 @@ class ParserCacheAdapterTest extends TestCase { $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->clear(); } @@ -104,7 +104,7 @@ class ParserCacheAdapterTest extends TestCase $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $key = 'key'; $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->deleteItem($key); } @@ -114,7 +114,7 @@ class ParserCacheAdapterTest extends TestCase $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $keys = array('key'); $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->deleteItems($keys); } @@ -124,7 +124,7 @@ class ParserCacheAdapterTest extends TestCase $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $parserCacheAdapter = new ParserCacheAdapter($poolMock); $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock(); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->saveDeferred($cacheItemMock); } @@ -133,7 +133,7 @@ class ParserCacheAdapterTest extends TestCase { $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $parserCacheAdapter = new ParserCacheAdapter($poolMock); - $this->setExpectedException(\BadMethodCallException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class); $parserCacheAdapter->commit(); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php index 488ea3c06b..25ad31f866 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer; +use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Form\Exception\UnexpectedTypeException; /** * @author Steffen Roßkamp @@ -159,7 +161,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase { $transformer = new DateIntervalToArrayTransformer(); $this->assertNull($transformer->reverseTransform(null)); - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class); $transformer->reverseTransform('12345'); } @@ -167,7 +169,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase { $transformer = new DateIntervalToArrayTransformer(); $input = array('years' => '1'); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class); $transformer->reverseTransform($input); } @@ -179,7 +181,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '', 'seconds' => '6', ); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException', 'This amount of "minutes" is invalid'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'This amount of "minutes" is invalid'); $transformer->reverseTransform($input); } @@ -189,7 +191,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase $input = array( 'invert' => '1', ); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException', 'The value of "invert" must be boolean'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'The value of "invert" must be boolean'); $transformer->reverseTransform($input); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToStringTransformerTest.php index 9815b70bff..9b831118c2 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToStringTransformerTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer; +use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Form\Exception\UnexpectedTypeException; /** * @author Steffen Roßkamp @@ -73,7 +75,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase public function testTransformExpectsDateTime() { $transformer = new DateIntervalToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class); $transformer->transform('1234'); } @@ -94,7 +96,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase { $reverseTransformer = new DateIntervalToStringTransformer($format, true); $interval = new \DateInterval($output); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class); $this->assertDateIntervalEquals($interval, $reverseTransformer->reverseTransform($input)); } @@ -107,14 +109,14 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase public function testReverseTransformExpectsString() { $reverseTransformer = new DateIntervalToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class); $reverseTransformer->reverseTransform(1234); } public function testReverseTransformExpectsValidIntervalString() { $reverseTransformer = new DateIntervalToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class); $reverseTransformer->reverseTransform('10Y'); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php index c771b5a06c..5ce7fb44d2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -74,6 +74,8 @@ class ClientTest extends TestCase $domResponse = $m->invoke($client, $response); try { $this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie')); + } catch (\PHPUnit\Framework\ExpectationFailedException $e) { + $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); } @@ -84,11 +86,15 @@ class ClientTest extends TestCase $domResponse = $m->invoke($client, $response); try { $this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie')); + } catch (\PHPUnit\Framework\ExpectationFailedException $e) { + $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); } try { $this->assertEquals($expected31, $domResponse->getHeader('Set-Cookie', false)); + } catch (\PHPUnit\Framework\ExpectationFailedException $e) { + $this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false)); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false)); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php index 006f2027c2..190e15ad67 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php @@ -118,7 +118,12 @@ class ControllerResolverTest extends TestCase public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null) { $resolver = $this->createControllerResolver(); - $this->setExpectedException($exceptionName, $exceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException($exceptionName); + $this->expectExceptionMessage($exceptionMessage); + } else { + $this->setExpectedException($exceptionName, $exceptionMessage); + } $request = Request::create('/'); $request->attributes->set('_controller', $controller); diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php index a1a80231bd..2abd21c8a9 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php @@ -73,7 +73,7 @@ class AdapterTest extends LdapTestCase public function testLdapQueryWithoutBind() { $ldap = new Adapter($this->getLdapConfig()); - $this->setExpectedException(NotBoundException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class); $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); $query->execute(); } diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php index 846d6a313d..3f741cb5ae 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php @@ -59,7 +59,7 @@ class LdapManagerTest extends LdapTestCase */ public function testLdapAddInvalidEntry() { - $this->setExpectedException(LdapException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(LdapException::class); $this->executeSearchQuery(1); // The entry is missing a subject name @@ -105,7 +105,7 @@ class LdapManagerTest extends LdapTestCase public function testLdapUnboundAdd() { $this->adapter = new Adapter($this->getLdapConfig()); - $this->setExpectedException(NotBoundException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class); $em = $this->adapter->getEntryManager(); $em->add(new Entry('')); } @@ -116,7 +116,7 @@ class LdapManagerTest extends LdapTestCase public function testLdapUnboundRemove() { $this->adapter = new Adapter($this->getLdapConfig()); - $this->setExpectedException(NotBoundException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class); $em = $this->adapter->getEntryManager(); $em->remove(new Entry('')); } @@ -127,7 +127,7 @@ class LdapManagerTest extends LdapTestCase public function testLdapUnboundUpdate() { $this->adapter = new Adapter($this->getLdapConfig()); - $this->setExpectedException(NotBoundException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class); $em = $this->adapter->getEntryManager(); $em->update(new Entry('')); } diff --git a/src/Symfony/Component/Ldap/Tests/LdapTest.php b/src/Symfony/Component/Ldap/Tests/LdapTest.php index 1b5ca4703e..17184323f4 100644 --- a/src/Symfony/Component/Ldap/Tests/LdapTest.php +++ b/src/Symfony/Component/Ldap/Tests/LdapTest.php @@ -78,7 +78,7 @@ class LdapTest extends TestCase public function testCreateWithInvalidAdapterName() { - $this->setExpectedException(DriverNotFoundException::class); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(DriverNotFoundException::class); Ldap::create('foo'); } } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 022cabbea5..e111ae2485 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -41,7 +41,11 @@ class ParserTest extends TestCase if (E_USER_DEPRECATED !== $type) { restore_error_handler(); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); + if (class_exists('PHPUnit_Util_ErrorHandler')) { + return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); + } + + return call_user_func_array('PHPUnit\Util\ErrorHandler::handleError', func_get_args()); } $deprecations[] = $msg;