diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php index ef920a1fe097c..ac7dc543a1d8a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php @@ -105,7 +105,7 @@ public function testRefreshUserRequiresId() $user1 = new User(null, null, 'user1'); $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name'); - $this->setExpectedException( + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( 'InvalidArgumentException', 'You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine' ); @@ -125,7 +125,7 @@ public function testRefreshInvalidUser() $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name'); $user2 = new User(1, 2, 'user2'); - $this->setExpectedException( + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( 'Symfony\Component\Security\Core\Exception\UsernameNotFoundException', 'User with id {"id1":1,"id2":2} not found' ); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php index 685b250559cd4..61e041d4d4c14 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php @@ -46,7 +46,13 @@ public function testUnknownFragmentRenderer() ; $renderer = new FragmentHandler(array(), false, $context); - $this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.'); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The "inline" renderer does not exist.'); + } else { + $this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.'); + } + $renderer->render('/foo'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerResolverTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerResolverTest.php index 36e8ed90a7117..fdd88aec0ad52 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerResolverTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerResolverTest.php @@ -141,7 +141,12 @@ public function testGetControllerInvokableServiceWithClassNameAsName() */ public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null) { - $this->setExpectedException($exceptionName, $exceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException($exceptionName); + $this->expectExceptionMessage($exceptionMessage); + } else { + $this->setExpectedException($exceptionName, $exceptionMessage); + } parent::testGetControllerOnNonUndefinedFunction($controller); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php index 813fb9f6028d8..b9907d7322039 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php @@ -11,12 +11,13 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; +use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Translation\TranslatorInterface; -class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase +class DataCollectorTranslatorPassTest extends TestCase { private $container; private $dataCollectorTranslatorPass; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php index 3637330ed5028..e064ce9f17f02 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php @@ -41,7 +41,7 @@ public function testTemplateNoIdThrowsException() $builder = $this->createContainerMock($services); - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $profilerPass = new ProfilerPass(); $profilerPass->process($builder); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php index f1e29fca51828..0df5bfd7cd866 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php @@ -36,7 +36,7 @@ public function testThrowExceptionWhenNoNormalizers() ->with('serializer.normalizer') ->will($this->returnValue(array())); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $serializerPass = new SerializerPass(); $serializerPass->process($container); @@ -63,7 +63,7 @@ public function testThrowExceptionWhenNoEncoders() ->method('getDefinition') ->will($this->returnValue($definition)); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $serializerPass = new SerializerPass(); $serializerPass->process($container); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php index 9a7c44d850d9b..361bcf001b560 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php @@ -101,7 +101,7 @@ public function testTransWithCachingWithInvalidLocale() $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale'); $translator->setLocale('invalid locale'); - $this->setExpectedException('\InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException'); $translator->trans('foo'); } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php index 86a69fdb7624c..2b444b14ef362 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php @@ -129,7 +129,12 @@ public function testEncodePasswordBcryptOutput() public function testEncodePasswordNoConfigForGivenUserClass() { - $this->setExpectedException('\RuntimeException', 'No encoder has been configured for account "Foo\Bar\User".'); + if (method_exists($this, 'expectException')) { + $this->expectException('\RuntimeException'); + $this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".'); + } else { + $this->setExpectedException('\RuntimeException', 'No encoder has been configured for account "Foo\Bar\User".'); + } $this->passwordEncoderCommandTester->execute(array( 'command' => 'security:encode-password', diff --git a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php index 12ca705b57a4d..38ea81220bb2c 100644 --- a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php @@ -85,7 +85,7 @@ public function testFromStringWithUrl() public function testFromStringThrowsAnExceptionIfCookieIsNotValid() { - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); Cookie::fromString('foo'); } @@ -98,7 +98,7 @@ public function testFromStringIgnoresInvalidExpiresDate() public function testFromStringThrowsAnExceptionIfUrlIsNotValid() { - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); Cookie::fromString('foo=bar', 'foobar'); } diff --git a/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php index 1bc31b7c12d12..a402a61ef951d 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php @@ -63,7 +63,12 @@ public function testNormalizeThrowsExceptionWithoutHint() { $node = new ScalarNode('test'); - $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', 'Invalid type for path "test". Expected scalar, but got array.'); + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); + $this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.'); + } else { + $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', 'Invalid type for path "test". Expected scalar, but got array.'); + } $node->normalize(array()); } @@ -73,7 +78,12 @@ public function testNormalizeThrowsExceptionWithErrorMessage() $node = new ScalarNode('test'); $node->setInfo('"the test value"'); - $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', "Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\""); + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); + $this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\""); + } else { + $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', "Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\""); + } $node->normalize(array()); } diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php index 09a826586dbf7..29d64dba84205 100644 --- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php +++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php @@ -151,7 +151,14 @@ public function getDataForPhpize() public function testLoadEmptyXmlFile() { $file = __DIR__.'/../Fixtures/foo.xml'; - $this->setExpectedException('InvalidArgumentException', sprintf('File %s does not contain valid XML, it is empty.', $file)); + + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file)); + } else { + $this->setExpectedException('InvalidArgumentException', sprintf('File %s does not contain valid XML, it is empty.', $file)); + } + XmlUtils::loadFile($file); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 78cc918ae0227..223a68bfc8e29 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -266,7 +266,12 @@ public function testFind() */ public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage) { - $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage($expectedExceptionMessage); + } else { + $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); + } $application = new Application(); $application->add(new \FooCommand()); @@ -954,7 +959,12 @@ public function testRunDispatchesAllEventsWithException() public function testRunWithError() { - $this->setExpectedException('Exception', 'dymerr'); + if (method_exists($this, 'expectException')) { + $this->expectException('Exception'); + $this->expectExceptionMessage('dymerr'); + } else { + $this->setExpectedException('Exception', 'dymerr'); + } $application = new Application(); $application->setAutoExit(false); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 92b40b35c2394..e1290295e205a 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -110,7 +110,12 @@ public function testGetNamespaceGetNameSetName() */ public function testInvalidCommandNames($name) { - $this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name)); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name)); + } else { + $this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name)); + } $command = new \TestCommand(); $command->setName($name); @@ -168,7 +173,7 @@ public function testGetSetAliases() public function testSetAliasesNull() { $command = new \TestCommand(); - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $command->setAliases(null); } diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php index f183450e44fad..ddf77902c90e9 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php @@ -41,7 +41,7 @@ public function testForeground() $style->setForeground('default'); $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo')); - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $style->setForeground('undefined-color'); } @@ -58,7 +58,7 @@ public function testBackground() $style->setBackground('default'); $this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo')); - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $style->setBackground('undefined-color'); } diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index 66d63e4d3855c..1fe21d0f6c1a8 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -164,7 +164,12 @@ public function provideOptions() */ public function testInvalidInput($argv, $definition, $expectedExceptionMessage) { - $this->setExpectedException('RuntimeException', $expectedExceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException('RuntimeException'); + $this->expectExceptionMessage($expectedExceptionMessage); + } else { + $this->setExpectedException('RuntimeException', $expectedExceptionMessage); + } $input = new ArgvInput($argv); $input->bind($definition); diff --git a/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php index 37e396a8ca145..06e65f7398bdc 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php @@ -100,7 +100,12 @@ public function provideOptions() */ public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage) { - $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage($expectedExceptionMessage); + } else { + $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); + } new ArrayInput($parameters, $definition); } diff --git a/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php b/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php index 0a62d98a4a4c3..66af98b33b666 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php @@ -42,7 +42,12 @@ public function testModes() */ public function testInvalidModes($mode) { - $this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode)); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('Argument mode "%s" is not valid.', $mode)); + } else { + $this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode)); + } new InputArgument('foo', $mode); } diff --git a/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php b/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php index 9c4df742d501a..943bf607f5e5a 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php @@ -78,7 +78,12 @@ public function testModes() */ public function testInvalidModes($mode) { - $this->setExpectedException('InvalidArgumentException', sprintf('Option mode "%s" is not valid.', $mode)); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('Option mode "%s" is not valid.', $mode)); + } else { + $this->setExpectedException('InvalidArgumentException', sprintf('Option mode "%s" is not valid.', $mode)); + } new InputOption('foo', 'f', $mode); } diff --git a/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php b/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php index 0844709d96548..37a3ef1d58def 100644 --- a/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php @@ -89,7 +89,7 @@ public function testParseSeriesException($series) /** @var FunctionNode $function */ $function = $selectors[0]->getTree(); - $this->setExpectedException('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); Parser::parseSeries($function->getArguments()); } diff --git a/src/Symfony/Component/CssSelector/Tests/Parser/TokenStreamTest.php b/src/Symfony/Component/CssSelector/Tests/Parser/TokenStreamTest.php index d6ff1132e607d..44c751ac865d2 100644 --- a/src/Symfony/Component/CssSelector/Tests/Parser/TokenStreamTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Parser/TokenStreamTest.php @@ -53,7 +53,7 @@ public function testGetNextIdentifier() public function testFailToGetNextIdentifier() { - $this->setExpectedException('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); $stream = new TokenStream(); $stream->push(new Token(Token::TYPE_DELIMITER, '.', 2)); @@ -73,7 +73,7 @@ public function testGetNextIdentifierOrStar() public function testFailToGetNextIdentifierOrStar() { - $this->setExpectedException('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException'); $stream = new TokenStream(); $stream->push(new Token(Token::TYPE_DELIMITER, '.', 2)); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 192abb7092c02..cefe0a02aa829 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -621,7 +621,7 @@ public function testExtension() $container->registerExtension($extension = new \ProjectExtension()); $this->assertTrue($container->getExtension('project') === $extension, '->registerExtension() registers an extension'); - $this->setExpectedException('LogicException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException'); $container->getExtension('no_registered'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 8ca51c0b6efe5..2e5e345c16046 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -59,7 +59,14 @@ public function testSetGetDecoratedService() $this->assertNull($def->getDecoratedService()); $def = new Definition('stdClass'); - $this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.'); + + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.'); + } else { + $this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.'); + } + $def->setDecoratedService('foo', 'foo'); } diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index 8e34a361580a9..bfd9527a05c83 100755 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -886,6 +886,8 @@ public function testChildren() $crawler = new Crawler('
'); $crawler->filter('p')->children(); $this->assertTrue(true, '->children() does not trigger a notice if the node has no children'); + } catch (\PHPUnit\Framework\Error\Notice $e) { + $this->fail('->children() does not trigger a notice if the node has no children'); } catch (\PHPUnit_Framework_Error_Notice $e) { $this->fail('->children() does not trigger a notice if the node has no children'); } diff --git a/src/Symfony/Component/EventDispatcher/Tests/GenericEventTest.php b/src/Symfony/Component/EventDispatcher/Tests/GenericEventTest.php index bbb459fb34940..c84d3ac24c3b1 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/GenericEventTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/GenericEventTest.php @@ -96,7 +96,7 @@ public function testOffsetGet() $this->assertEquals('Event', $this->event['name']); // test getting invalid arg - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $this->assertFalse($this->event['nameNotExist']); } diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index a17d199597ea8..28bb4dbdbb699 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -689,6 +689,10 @@ public function testAccessDeniedException() $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString())); } + if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) { + $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString())); + } + $this->assertInstanceOf($expectedExceptionClass, $e); } } diff --git a/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php index c78e76169266a..5afac54d3ecc3 100644 --- a/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php +++ b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php @@ -103,7 +103,7 @@ public function testInsDuplicateLabelException() $cmd = Command::create()->add('--force'); $cmd->ins('label'); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $cmd->ins('label'); } @@ -119,7 +119,7 @@ public function testEndNoParentException() { $cmd = Command::create(); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $cmd->end(); } @@ -127,7 +127,7 @@ public function testGetMissingLabelException() { $cmd = Command::create(); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $cmd->get('invalid'); } diff --git a/src/Symfony/Component/Form/Test/DeprecationErrorHandler.php b/src/Symfony/Component/Form/Test/DeprecationErrorHandler.php index a88ec7921465e..520567b506bb2 100644 --- a/src/Symfony/Component/Form/Test/DeprecationErrorHandler.php +++ b/src/Symfony/Component/Form/Test/DeprecationErrorHandler.php @@ -24,7 +24,11 @@ public static function handle($errorNumber, $message, $file, $line, $context) return true; } - return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line); + if (class_exists('PHPUnit_Util_ErrorHandler')) { + return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line); + } + + return \PHPUnit\Util\ErrorHandler::handleError($errorNumber, $message, $file, $line); } public static function handleBC($errorNumber, $message, $file, $line, $context) diff --git a/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php b/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php index 5b2b2659a33c8..15df850796ae8 100644 --- a/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php @@ -53,7 +53,7 @@ public function getInvalidNames() */ public function testInvalidNames($name) { - $this->setExpectedException( + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( '\Symfony\Component\Form\Exception\InvalidArgumentException', 'Buttons cannot have empty names.' ); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index a023f6cf4e7af..33e056d49b351 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -190,7 +190,7 @@ public function testTransformWrapsIntlErrors() // HOW TO REPRODUCE? - //$this->setExpectedException('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException'); + //$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException'); //$transformer->transform(1.5); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php index b70ad71230cb2..883634985a2f8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php @@ -112,7 +112,7 @@ public function testTransformExpectsDateTime() { $transformer = new DateTimeToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->transform('1234'); } @@ -163,7 +163,7 @@ public function testReverseTransformExpectsString() { $reverseTransformer = new DateTimeToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $reverseTransformer->reverseTransform(1234); } @@ -172,7 +172,7 @@ public function testReverseTransformExpectsValidDateString() { $reverseTransformer = new DateTimeToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $reverseTransformer->reverseTransform('2010-2010-2010'); } @@ -181,7 +181,7 @@ public function testReverseTransformWithNonExistingDate() { $reverseTransformer = new DateTimeToStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $reverseTransformer->reverseTransform('2010-04-31'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php index a96e3522b3f79..44c37723cabf9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php @@ -74,7 +74,7 @@ public function testTransformExpectsDateTime() { $transformer = new DateTimeToTimestampTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->transform('1234'); } @@ -111,7 +111,7 @@ public function testReverseTransformExpectsValidTimestamp() { $reverseTransformer = new DateTimeToTimestampTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $reverseTransformer->reverseTransform('2010-2010-2010'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php index 5a3417e4d2034..68face130b535 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php @@ -33,7 +33,7 @@ public function testTransformExpectsNumeric() { $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->transform('abcd'); } @@ -61,7 +61,7 @@ public function testReverseTransformExpectsString() { $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->reverseTransform(12345); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php index 93fe38def89fc..abcc72e2315f8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php @@ -106,7 +106,7 @@ public function testTransformExpectsNumeric() { $transformer = new PercentToLocalizedStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->transform('foo'); } @@ -115,7 +115,7 @@ public function testReverseTransformExpectsString() { $transformer = new PercentToLocalizedStringTransformer(); - $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->reverseTransform(1); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index c69679a475045..27237f3e66c28 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -59,7 +59,7 @@ public function testThrowsExceptionIfObjectIsNotTraversable() $form = $this->factory->create('collection', null, array( 'type' => 'text', )); - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException'); $form->setData(new \stdClass()); } diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 214313cba1b5f..fae2b1623dbf8 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -49,13 +49,13 @@ public function testNoSetName() public function testAddNameNoStringAndNoInteger() { - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException'); $this->builder->add(true); } public function testAddTypeNoString() { - $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException'); $this->builder->add('foo', 1234); } @@ -165,7 +165,13 @@ public function testAddButton() public function testGetUnknown() { - $this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.'); + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The child with the name "foo" does not exist.'); + } else { + $this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.'); + } + $this->builder->get('foo'); } diff --git a/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php index fb2bc47ef1c86..052821c39dfec 100644 --- a/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php @@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase */ public function testTranslationFileIsValid($filePath) { - \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + if (class_exists('PHPUnit_Util_XML')) { + \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + } else { + \PHPUnit\Util\XML::loadfile($filePath, false, false, true); + } } public function provideTranslationFiles() diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php index eea437f13e5fe..dbd9c44bd802c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php @@ -64,7 +64,7 @@ public function testGuessExtensionWithReset() public function testConstructWhenFileNotExists() { - $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); new File(__DIR__.'/Fixtures/not_here'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php index 3fb15e9c8ac42..5a2b7a21c325e 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php @@ -29,7 +29,7 @@ public function testGuessImageWithoutExtension() public function testGuessImageWithDirectory() { - $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory'); } @@ -53,7 +53,7 @@ public function testGuessFileWithUnknownExtension() public function testGuessWithIncorrectPath() { - $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here'); } @@ -72,7 +72,7 @@ public function testGuessWithNonReadablePath() @chmod($path, 0333); if (substr(sprintf('%o', fileperms($path)), -4) == '0333') { - $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException'); MimeTypeGuesser::getInstance()->guess($path); } else { $this->markTestSkipped('Can not verify chmod operations, change of file permissions failed'); diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php index eafeb4fb6d619..36f122fe79223 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php @@ -25,7 +25,7 @@ protected function setUp() public function testConstructWhenFileNotExists() { - $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); new UploadedFile( __DIR__.'/Fixtures/not_here', diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 47c435f24b113..9000eb622b118 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1897,7 +1897,13 @@ public function testHostValidity($host, $isValid, $expectedHost = null, $expecte $this->assertSame($expectedPort, $request->getPort()); } } else { - $this->setExpectedException('UnexpectedValueException', 'Invalid Host'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + $this->expectExceptionMessage('Invalid Host'); + } else { + $this->setExpectedException('UnexpectedValueException', 'Invalid Host'); + } + $request->getHost(); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php index 8559e6791187c..b15fbcebcc147 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php @@ -34,7 +34,7 @@ protected function setUp() public function testIncompleteOptions() { - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $storage = new LegacyPdoSessionHandler($this->pdo, array()); } @@ -44,21 +44,21 @@ public function testWrongPdoErrMode() $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); $pdo->exec('CREATE TABLE sessions (sess_id VARCHAR(128) PRIMARY KEY, sess_data TEXT, sess_time INTEGER)'); - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $storage = new LegacyPdoSessionHandler($pdo, array('db_table' => 'sessions')); } public function testWrongTableOptionsWrite() { $storage = new LegacyPdoSessionHandler($this->pdo, array('db_table' => 'bad_name')); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $storage->write('foo', 'bar'); } public function testWrongTableOptionsRead() { $storage = new LegacyPdoSessionHandler($this->pdo, array('db_table' => 'bad_name')); - $this->setExpectedException('RuntimeException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException'); $storage->read('foo'); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Config/FileLocatorTest.php b/src/Symfony/Component/HttpKernel/Tests/Config/FileLocatorTest.php index 397edbc8a71d3..6265f0275560a 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Config/FileLocatorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Config/FileLocatorTest.php @@ -30,7 +30,7 @@ public function testLocate() $kernel ->expects($this->never()) ->method('locateResource'); - $this->setExpectedException('LogicException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException'); $locator->locate('/some/path'); } diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php index abe061b5f2fd4..cfe9a1854674f 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php @@ -104,6 +104,8 @@ public function testHandleRestoresThePreviousRequestOnException($type) try { $kernel->handle($request, $type); $this->fail('->handle() suppresses the controller exception'); + } catch (\PHPUnit\Framework\Exception $e) { + throw $e; } catch (\PHPUnit_Framework_Exception $e) { throw $e; } catch (\Exception $e) { diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 8ba2be2e23ca5..336cd50d9851e 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -306,10 +306,17 @@ public function formatTypeDoubleWithCurrencyStyleProvider() /** * @dataProvider formatTypeCurrencyProvider - * @expectedException \PHPUnit_Framework_Error_Warning */ public function testFormatTypeCurrency($formatter, $value) { + $exceptionCode = 'PHPUnit\Framework\Error\Warning'; + + if (class_exists('PHPUnit_Framework_Error_Warning')) { + $exceptionCode = 'PHPUnit_Framework_Error_Warning'; + } + + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode); + $formatter->format($value, NumberFormatter::TYPE_CURRENCY); } @@ -641,11 +648,16 @@ public function parseProvider() ); } - /** - * @expectedException \PHPUnit_Framework_Error_Warning - */ public function testParseTypeDefault() { + $exceptionCode = 'PHPUnit\Framework\Error\Warning'; + + if (class_exists('PHPUnit_Framework_Error_Warning')) { + $exceptionCode = 'PHPUnit_Framework_Error_Warning'; + } + + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode); + $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL); $formatter->parse('1', NumberFormatter::TYPE_DEFAULT); } @@ -782,11 +794,16 @@ public function parseTypeDoubleProvider() ); } - /** - * @expectedException \PHPUnit_Framework_Error_Warning - */ public function testParseTypeCurrency() { + $exceptionCode = 'PHPUnit\Framework\Error\Warning'; + + if (class_exists('PHPUnit_Framework_Error_Warning')) { + $exceptionCode = 'PHPUnit_Framework_Error_Warning'; + } + + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode); + $formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL); $formatter->parse('1', NumberFormatter::TYPE_CURRENCY); } diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 6d9ddaf5713c3..109454e56ff62 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -507,7 +507,14 @@ public function testResolveFailsIfInvalidType($actualType, $allowedType, $except { $this->resolver->setDefined('option'); $this->resolver->setAllowedTypes('option', $allowedType); - $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage); + + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); + $this->expectExceptionMessage($exceptionMessage); + } else { + $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage); + } + $this->resolver->resolve(array('option' => $actualType)); } diff --git a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php index 11f2779420ce3..401ae7d9d2b3d 100644 --- a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php @@ -29,7 +29,7 @@ public function testProcessFailedExceptionThrowsException() ->method('isSuccessful') ->will($this->returnValue(true)); - $this->setExpectedException( + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( '\InvalidArgumentException', 'Expected a failed process, but the given process was successful.' ); diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 842dbf5b9ad15..e034aeb28a743 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -927,7 +927,14 @@ public function testSignalProcessNotRunning() public function testMethodsThatNeedARunningProcess($method) { $process = $this->getProcess('foo'); - $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method)); + + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Process\Exception\LogicException'); + $this->expectExceptionMessage(sprintf('Process must be started before calling %s.', $method)); + } else { + $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method)); + } + $process->{$method}(); } @@ -1081,7 +1088,14 @@ public function testStartWithACallbackAndDisabledOutput($startMethod, $exception { $p = $this->getProcess('foo'); $p->disableOutput(); - $this->setExpectedException($exception, $exceptionMessage); + + if (method_exists($this, 'expectException')) { + $this->expectException($exception); + $this->expectExceptionMessage($exceptionMessage); + } else { + $this->setExpectedException($exception, $exceptionMessage); + } + if ('mustRun' === $startMethod) { $this->skipIfNotEnhancedSigchild(); } @@ -1250,7 +1264,12 @@ private function skipIfNotEnhancedSigchild($expectException = true) if (!$expectException) { $this->markTestSkipped('PHP is compiled with --enable-sigchild.'); } elseif (self::$notEnhancedSigchild) { - $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.'); + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Process\Exception\RuntimeException'); + $this->expectExceptionMessage('This PHP has been compiled with --enable-sigchild.'); + } else { + $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.'); + } } } } diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index 36094ba49df8f..30790084ed517 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -359,7 +359,7 @@ public function testAdjacentVariables() // The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything // and following optional variables like _format could never match. - $this->setExpectedException('Symfony\Component\Routing\Exception\InvalidParameterException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\InvalidParameterException'); $generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml')); } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index 8f7fbb07be969..6d59855d2d8f3 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -195,7 +195,7 @@ public function testMatchOverriddenRoute() $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1')); - $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException'); $this->assertEquals(array(), $matcher->match('/foo')); } @@ -252,7 +252,7 @@ public function testAdjacentVariables() // z and _format are optional. $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxy')); - $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException'); $matcher->match('/wxy.html'); } @@ -267,7 +267,7 @@ public function testOptionalVariableWithNoRealSeparator() // Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match. // But here the 't' in 'get' is not a separating character, so it makes no sense to match without it. - $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException'); $matcher->match('/ge'); } diff --git a/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php b/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php index a042a6944993d..17410f851ac6a 100644 --- a/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php +++ b/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php @@ -30,7 +30,7 @@ public static function setUpBeforeClass() try { random_bytes(1); } catch (\Exception $e) { - throw new \PHPUnit_Framework_SkippedTestError($e->getMessage()); + self::markTestSkipped($e->getMessage()); } } diff --git a/src/Symfony/Component/Security/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Security/Tests/Resources/TranslationFilesTest.php index 40a23d82ab6ea..5e959b30d4fbc 100644 --- a/src/Symfony/Component/Security/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Security/Tests/Resources/TranslationFilesTest.php @@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase */ public function testTranslationFileIsValid($filePath) { - \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + if (class_exists('PHPUnit_Util_XML')) { + \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + } else { + \PHPUnit\Util\XML::loadfile($filePath, false, false, true); + } } public function provideTranslationFiles() diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 1c9ed79e35d62..fcdb7ac89d321 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -450,7 +450,12 @@ public function testPreventsComplexExternalEntities() public function testDecodeEmptyXml() { - $this->setExpectedException('Symfony\Component\Serializer\Exception\UnexpectedValueException', 'Invalid XML data, it can not be empty.'); + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException'); + $this->expectExceptionMessage('Invalid XML data, it can not be empty.'); + } else { + $this->setExpectedException('Symfony\Component\Serializer\Exception\UnexpectedValueException', 'Invalid XML data, it can not be empty.'); + } $this->encoder->decode(' ', 'xml'); } diff --git a/src/Symfony/Component/Templating/Tests/Helper/LegacyCoreAssetsHelperTest.php b/src/Symfony/Component/Templating/Tests/Helper/LegacyCoreAssetsHelperTest.php index a90479bc55c2b..45649216477fb 100644 --- a/src/Symfony/Component/Templating/Tests/Helper/LegacyCoreAssetsHelperTest.php +++ b/src/Symfony/Component/Templating/Tests/Helper/LegacyCoreAssetsHelperTest.php @@ -44,7 +44,7 @@ public function testGetNonexistingPackage() { $helper = new CoreAssetsHelper($this->package); - $this->setExpectedException('\InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException'); $helper->getPackage('foo'); } diff --git a/src/Symfony/Component/Templating/Tests/PhpEngineTest.php b/src/Symfony/Component/Templating/Tests/PhpEngineTest.php index d3d8c9885c410..4481c2abf526c 100644 --- a/src/Symfony/Component/Templating/Tests/PhpEngineTest.php +++ b/src/Symfony/Component/Templating/Tests/PhpEngineTest.php @@ -86,7 +86,7 @@ public function testUnsetHelper() $foo = new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('foo'); $engine->set($foo); - $this->setExpectedException('\LogicException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\LogicException'); unset($engine['foo']); } diff --git a/src/Symfony/Component/Translation/Tests/Catalogue/AbstractOperationTest.php b/src/Symfony/Component/Translation/Tests/Catalogue/AbstractOperationTest.php index 6fd909e878f70..90cf4a5dc381e 100644 --- a/src/Symfony/Component/Translation/Tests/Catalogue/AbstractOperationTest.php +++ b/src/Symfony/Component/Translation/Tests/Catalogue/AbstractOperationTest.php @@ -41,7 +41,7 @@ public function testGetMergedDomains() public function testGetMessagesFromUnknownDomain() { - $this->setExpectedException('InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); $this->createOperation( new MessageCatalogue('en'), new MessageCatalogue('en') diff --git a/src/Symfony/Component/Translation/Tests/Loader/QtFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/QtFileLoaderTest.php index a8d04d6f28746..7ee62b06cbc6a 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/QtFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/QtFileLoaderTest.php @@ -62,7 +62,14 @@ public function testLoadEmptyResource() { $loader = new QtFileLoader(); $resource = __DIR__.'/../fixtures/empty.xlf'; - $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s".', $resource)); + + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException'); + $this->expectExceptionMessage(sprintf('Unable to load "%s".', $resource)); + } else { + $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s".', $resource)); + } + $loader->load($resource, 'en', 'domain1'); } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index 1dc6ec38faf99..9a8c0dd072c3f 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -142,7 +142,14 @@ public function testParseEmptyFile() { $loader = new XliffFileLoader(); $resource = __DIR__.'/../fixtures/empty.xlf'; - $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s":', $resource)); + + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException'); + $this->expectExceptionMessage(sprintf('Unable to load "%s":', $resource)); + } else { + $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s":', $resource)); + } + $loader->load($resource, 'en', 'domain1'); } diff --git a/src/Symfony/Component/Validator/Tests/ConstraintTest.php b/src/Symfony/Component/Validator/Tests/ConstraintTest.php index b16536883278d..1b1219664402b 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintTest.php @@ -35,7 +35,7 @@ public function testSetProperties() public function testSetNotExistingPropertyThrowsException() { - $this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException'); new ConstraintA(array( 'foo' => 'bar', @@ -46,14 +46,14 @@ public function testMagicPropertiesAreNotAllowed() { $constraint = new ConstraintA(); - $this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException'); $constraint->foo = 'bar'; } public function testInvalidAndRequiredOptionsPassed() { - $this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException'); new ConstraintC(array( 'option1' => 'default', @@ -101,14 +101,14 @@ public function testDontSetDefaultPropertyIfValuePropertyExists() public function testSetUndefinedDefaultProperty() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); new ConstraintB('foo'); } public function testRequiredOptionsMustBeDefined() { - $this->setExpectedException('Symfony\Component\Validator\Exception\MissingOptionsException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\MissingOptionsException'); new ConstraintC(); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php index 6240ba727a1cd..8ca3c9fbcb606 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -39,14 +39,14 @@ protected function tearDown() public function testAddConstraintDoesNotAcceptValid() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); $this->metadata->addConstraint(new Valid()); } public function testAddConstraintRequiresClassConstraints() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); $this->metadata->addConstraint(new PropertyConstraint()); } @@ -249,14 +249,14 @@ public function testGroupSequencesWorkIfContainingDefaultGroup() public function testGroupSequencesFailIfNotContainingDefaultGroup() { - $this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException'); $this->metadata->setGroupSequence(array('Foo', 'Bar')); } public function testGroupSequencesFailIfContainingDefault() { - $this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException'); $this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP)); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php index 682ef94cb4c95..05aef47e84aaf 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php @@ -21,7 +21,7 @@ class GetterMetadataTest extends TestCase public function testInvalidPropertyName() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException'); new GetterMetadata(self::CLASSNAME, 'foobar'); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php index 818094962ca27..20dc80ed069b8 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php @@ -114,7 +114,7 @@ public function testThrowExceptionIfDocTypeIsSet() $loader = new XmlFileLoader(__DIR__.'/withdoctype.xml'); $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity'); - $this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException'); $loader->loadClassMetadata($metadata); } @@ -129,7 +129,7 @@ public function testDoNotModifyStateIfExceptionIsThrown() try { $loader->loadClassMetadata($metadata); } catch (MappingException $e) { - $this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException'); $loader->loadClassMetadata($metadata); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php index a50b4b3020712..671296e90ca0f 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php @@ -69,7 +69,7 @@ public function testDoNotModifyStateIfExceptionIsThrown() $loader->loadClassMetadata($metadata); } catch (\InvalidArgumentException $e) { // Call again. Again an exception should be thrown - $this->setExpectedException('\InvalidArgumentException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException'); $loader->loadClassMetadata($metadata); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php index 2ced2c739d419..f0726c863f01a 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php @@ -62,7 +62,7 @@ public function testLegacyAddOtherConstraintDoesNotSetMemberToCascaded() public function testAddConstraintRequiresClassConstraints() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); $this->metadata->addConstraint(new ClassConstraint()); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php index f61545a5a2d48..9fea435dff279 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php @@ -22,7 +22,7 @@ class PropertyMetadataTest extends TestCase public function testInvalidPropertyName() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException'); new PropertyMetadata(self::CLASSNAME, 'foobar'); } @@ -50,7 +50,7 @@ public function testGetPropertyValueFromRemovedProperty() $metadata = new PropertyMetadata(self::CLASSNAME, 'internal'); $metadata->name = 'test'; - $this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException'); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException'); $metadata->getPropertyValue($entity); } } diff --git a/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php index 14dd58fbeceb9..d33351352777c 100644 --- a/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php @@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase */ public function testTranslationFileIsValid($filePath) { - \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + if (class_exists('PHPUnit_Util_XML')) { + \PHPUnit_Util_XML::loadfile($filePath, false, false, true); + } else { + \PHPUnit\Util\XML::loadfile($filePath, false, false, true); + } } public function provideTranslationFiles() diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 7e353b4e34be0..2ab83f44cc437 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1084,10 +1084,12 @@ public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks() */ public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml) { - $this->setExpectedException( - '\Symfony\Component\Yaml\Exception\ParseException', - sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber) - ); + if (method_exists($this, 'expectException')) { + $this->expectException('\Symfony\Component\Yaml\Exception\ParseException'); + $this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)); + } else { + $this->setExpectedException('\Symfony\Component\Yaml\Exception\ParseException', sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)); + } $this->parser->parse($yaml); }