Merge branch '4.4'

* 4.4:
  cs fix
  Replace calls to setExpectedException by Pollyfill
This commit is contained in:
Nicolas Grekas 2019-08-01 23:17:12 +02:00
commit fe11c99f19
59 changed files with 231 additions and 260 deletions

View File

@ -17,9 +17,12 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\User; use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
class EntityUserProviderTest extends TestCase class EntityUserProviderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testRefreshUserGetsUserByPrimaryKey() public function testRefreshUserGetsUserByPrimaryKey()
{ {
$em = DoctrineTestHelper::createTestEntityManager(); $em = DoctrineTestHelper::createTestEntityManager();
@ -106,10 +109,8 @@ class EntityUserProviderTest extends TestCase
$user1 = new User(null, null, 'user1'); $user1 = new User(null, null, 'user1');
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name'); $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
$this->expectException( $this->expectException('InvalidArgumentException');
'InvalidArgumentException', $this->expectExceptionMessage('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');
'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'
);
$provider->refreshUser($user1); $provider->refreshUser($user1);
} }
@ -126,10 +127,9 @@ class EntityUserProviderTest extends TestCase
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name'); $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
$user2 = new User(1, 2, 'user2'); $user2 = new User(1, 2, 'user2');
$this->expectException( $this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException', $this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
'User with id {"id1":1,"id2":2} not found'
);
$provider->refreshUser($user2); $provider->refreshUser($user2);
} }

View File

@ -30,6 +30,6 @@ trait ForwardCompatTestTraitForV7
->disableOriginalClone() ->disableOriginalClone()
->disableArgumentCloning() ->disableArgumentCloning()
->disallowMockingUnknownTypes() ->disallowMockingUnknownTypes()
->getMock(); ->getMock();
} }
} }

View File

@ -3,6 +3,7 @@
namespace Symfony\Bridge\PhpUnit\Tests; namespace Symfony\Bridge\PhpUnit\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
/** /**
* Don't remove this test case, it tests the legacy group. * Don't remove this test case, it tests the legacy group.
@ -13,6 +14,8 @@ use PHPUnit\Framework\TestCase;
*/ */
class ProcessIsolationTest extends TestCase class ProcessIsolationTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @expectedDeprecation Test abc * @expectedDeprecation Test abc
*/ */
@ -25,12 +28,8 @@ class ProcessIsolationTest extends TestCase
public function testCallingOtherErrorHandler() public function testCallingOtherErrorHandler()
{ {
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception'; $class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
if (method_exists($this, 'expectException')) { $this->expectException($class);
$this->expectException($class); $this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
} else {
$this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.');
}
trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING); trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Tests\Extension; namespace Symfony\Bridge\Twig\Tests\Extension;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Bridge\Twig\Extension\HttpKernelExtension; use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -22,6 +23,8 @@ use Twig\Loader\ArrayLoader;
class HttpKernelExtensionTest extends TestCase class HttpKernelExtensionTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @expectedException \Twig\Error\RuntimeError * @expectedException \Twig\Error\RuntimeError
*/ */
@ -49,12 +52,8 @@ class HttpKernelExtensionTest extends TestCase
; ;
$renderer = new FragmentHandler($context); $renderer = new FragmentHandler($context);
if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException');
$this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('The "inline" renderer does not exist.');
$this->expectExceptionMessage('The "inline" renderer does not exist.');
} else {
$this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.');
}
$renderer->render('/foo'); $renderer->render('/foo');
} }

View File

@ -76,11 +76,7 @@ class CachePoolDeleteCommandTest extends TestCase
->with('bar') ->with('bar')
->willReturn(false); ->willReturn(false);
if (method_exists($this, 'expectExceptionMessage')) { $this->expectExceptionMessage('Cache item "bar" could not be deleted.');
$this->expectExceptionMessage('Cache item "bar" could not be deleted.');
} else {
$this->setExpectedException('Exception', 'Cache item "bar" could not be deleted.');
}
$tester = $this->getCommandTester($this->getKernel()); $tester = $this->getCommandTester($this->getKernel());
$tester->execute(['pool' => 'foo', 'key' => 'bar']); $tester->execute(['pool' => 'foo', 'key' => 'bar']);

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
use Symfony\Bundle\FullStack; use Symfony\Bundle\FullStack;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@ -24,6 +25,8 @@ use Symfony\Component\Messenger\MessageBusInterface;
class ConfigurationTest extends TestCase class ConfigurationTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testDefaultConfig() public function testDefaultConfig()
{ {
$processor = new Processor(); $processor = new Processor();
@ -124,12 +127,8 @@ class ConfigurationTest extends TestCase
*/ */
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage) public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
{ {
if (method_exists($this, 'expectException')) { $this->expectException(InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage($expectedMessage);
$this->expectExceptionMessage($expectedMessage);
} else {
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
}
$processor = new Processor(); $processor = new Processor();
$configuration = new Configuration(true); $configuration = new Configuration(true);
@ -178,12 +177,8 @@ class ConfigurationTest extends TestCase
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus() public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
{ {
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.'; $expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';
if (method_exists($this, 'expectException')) { $this->expectException(InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage($expectedMessage);
$this->expectExceptionMessage($expectedMessage);
} else {
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
}
$processor = new Processor(); $processor = new Processor();
$configuration = new Configuration(true); $configuration = new Configuration(true);

View File

@ -12,6 +12,7 @@
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler; namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass; use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
@ -21,6 +22,8 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class AddSecurityVotersPassTest extends TestCase class AddSecurityVotersPassTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
* @expectedExceptionMessage No security voters found. You need to tag at least one with "security.voter". * @expectedExceptionMessage No security voters found. You need to tag at least one with "security.voter".
@ -128,12 +131,14 @@ class AddSecurityVotersPassTest extends TestCase
$this->assertFalse($container->has('debug.security.voter.voter2'), 'voter2 should not be traced'); $this->assertFalse($container->has('debug.security.voter.voter2'), 'voter2 should not be traced');
} }
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
* @expectedExceptionMessage stdClass must implement the Symfony\Component\Security\Core\Authorization\Voter\VoterInterface when used as a voter.
*/
public function testVoterMissingInterface() public function testVoterMissingInterface()
{ {
$exception = LogicException::class;
$message = 'stdClass must implement the Symfony\Component\Security\Core\Authorization\Voter\VoterInterface when used as a voter.';
$this->expectException($exception);
$this->expectExceptionMessage($message);
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->setParameter('kernel.debug', false); $container->setParameter('kernel.debug', false);
$container $container

View File

@ -169,12 +169,8 @@ class UserPasswordEncoderCommandTest extends AbstractWebTestCase
public function testEncodePasswordNoConfigForGivenUserClass() public function testEncodePasswordNoConfigForGivenUserClass()
{ {
if (method_exists($this, 'expectException')) { $this->expectException('\RuntimeException');
$this->expectException('\RuntimeException'); $this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".');
$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([ $this->passwordEncoderCommandTester->execute([
'command' => 'security:encode-password', 'command' => 'security:encode-password',

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\BrowserKit\Tests; namespace Symfony\Component\BrowserKit\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\BrowserKit\Cookie;
class CookieTest extends TestCase class CookieTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testToString() public function testToString()
{ {
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true); $cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);

View File

@ -12,12 +12,15 @@
namespace Symfony\Component\Config\Tests\Definition; namespace Symfony\Component\Config\Tests\Definition;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Definition\ArrayNode; use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\ScalarNode; use Symfony\Component\Config\Definition\ScalarNode;
class ArrayNodeTest extends TestCase class ArrayNodeTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
*/ */
@ -80,12 +83,8 @@ class ArrayNodeTest extends TestCase
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '') public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
{ {
if ($expected instanceof \Exception) { if ($expected instanceof \Exception) {
if (method_exists($this, 'expectException')) { $this->expectException(\get_class($expected));
$this->expectException(\get_class($expected)); $this->expectExceptionMessage($expected->getMessage());
$this->expectExceptionMessage($expected->getMessage());
} else {
$this->setExpectedException(\get_class($expected), $expected->getMessage());
}
} }
$node = new ArrayNode('root'); $node = new ArrayNode('root');
$node->setIgnoreExtraKeys($ignore, $remove); $node->setIgnoreExtraKeys($ignore, $remove);

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Config\Tests\Definition; namespace Symfony\Component\Config\Tests\Definition;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Definition\ArrayNode; use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\ScalarNode; use Symfony\Component\Config\Definition\ScalarNode;
class ScalarNodeTest extends TestCase class ScalarNodeTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*/ */
@ -95,12 +98,8 @@ class ScalarNodeTest extends TestCase
{ {
$node = new ScalarNode('test'); $node = new ScalarNode('test');
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); $this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
$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([]); $node->normalize([]);
} }
@ -110,12 +109,8 @@ class ScalarNodeTest extends TestCase
$node = new ScalarNode('test'); $node = new ScalarNode('test');
$node->setInfo('"the test value"'); $node->setInfo('"the test value"');
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); $this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
$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([]); $node->normalize([]);
} }

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Config\Tests\Util; namespace Symfony\Component\Config\Tests\Util;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\Config\Util\XmlUtils;
class XmlUtilsTest extends TestCase class XmlUtilsTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLoadFile() public function testLoadFile()
{ {
$fixtures = __DIR__.'/../Fixtures/Util/'; $fixtures = __DIR__.'/../Fixtures/Util/';
@ -166,12 +169,8 @@ class XmlUtilsTest extends TestCase
{ {
$file = __DIR__.'/../Fixtures/foo.xml'; $file = __DIR__.'/../Fixtures/foo.xml';
if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException');
$this->expectException('InvalidArgumentException'); $this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
$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); XmlUtils::loadFile($file);
} }

View File

@ -316,12 +316,8 @@ class ApplicationTest extends TestCase
$expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1"; $expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1";
if (method_exists($this, 'expectException')) { $this->expectException(NamespaceNotFoundException::class);
$this->expectException(NamespaceNotFoundException::class); $this->expectExceptionMessage($expectedMsg);
$this->expectExceptionMessage($expectedMsg);
} else {
$this->setExpectedException(NamespaceNotFoundException::class, $expectedMsg);
}
$application->findNamespace('f'); $application->findNamespace('f');
} }
@ -425,12 +421,8 @@ class ApplicationTest extends TestCase
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage) public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
{ {
putenv('COLUMNS=120'); putenv('COLUMNS=120');
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); $this->expectExceptionMessage($expectedExceptionMessage);
$this->expectExceptionMessage($expectedExceptionMessage);
} else {
$this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedExceptionMessage);
}
$application = new Application(); $application = new Application();
$application->add(new \FooCommand()); $application->add(new \FooCommand());

View File

@ -120,12 +120,8 @@ class CommandTest extends TestCase
*/ */
public function testInvalidCommandNames($name) public function testInvalidCommandNames($name)
{ {
if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException');
$this->expectException('InvalidArgumentException'); $this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name));
$this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name));
} else {
$this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name));
}
$command = new \TestCommand(); $command = new \TestCommand();
$command->setName($name); $command->setName($name);

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Console\Tests\Formatter; namespace Symfony\Component\Console\Tests\Formatter;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class OutputFormatterStyleTest extends TestCase class OutputFormatterStyleTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$style = new OutputFormatterStyle('green', 'black', ['bold', 'underscore']); $style = new OutputFormatterStyle('green', 'black', ['bold', 'underscore']);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Console\Tests\Input; namespace Symfony\Component\Console\Tests\Input;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
@ -19,6 +20,8 @@ use Symfony\Component\Console\Input\InputOption;
class ArgvInputTest extends TestCase class ArgvInputTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$_SERVER['argv'] = ['cli.php', 'foo']; $_SERVER['argv'] = ['cli.php', 'foo'];
@ -182,12 +185,8 @@ class ArgvInputTest extends TestCase
*/ */
public function testInvalidInput($argv, $definition, $expectedExceptionMessage) public function testInvalidInput($argv, $definition, $expectedExceptionMessage)
{ {
if (method_exists($this, 'expectException')) { $this->expectException('RuntimeException');
$this->expectException('RuntimeException'); $this->expectExceptionMessage($expectedExceptionMessage);
$this->expectExceptionMessage($expectedExceptionMessage);
} else {
$this->setExpectedException('RuntimeException', $expectedExceptionMessage);
}
$input = new ArgvInput($argv); $input = new ArgvInput($argv);
$input->bind($definition); $input->bind($definition);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Console\Tests\Input; namespace Symfony\Component\Console\Tests\Input;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
@ -19,6 +20,8 @@ use Symfony\Component\Console\Input\InputOption;
class ArrayInputTest extends TestCase class ArrayInputTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testGetFirstArgument() public function testGetFirstArgument()
{ {
$input = new ArrayInput([]); $input = new ArrayInput([]);
@ -127,12 +130,8 @@ class ArrayInputTest extends TestCase
*/ */
public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage) public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage)
{ {
if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException');
$this->expectException('InvalidArgumentException'); $this->expectExceptionMessage($expectedExceptionMessage);
$this->expectExceptionMessage($expectedExceptionMessage);
} else {
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
}
new ArrayInput($parameters, $definition); new ArrayInput($parameters, $definition);
} }

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Console\Tests\Input; namespace Symfony\Component\Console\Tests\Input;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
class InputArgumentTest extends TestCase class InputArgumentTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$argument = new InputArgument('foo'); $argument = new InputArgument('foo');
@ -37,12 +40,11 @@ class InputArgumentTest extends TestCase
$this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode'); $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
} }
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Argument mode "-1" is not valid.
*/
public function testInvalidModes() public function testInvalidModes()
{ {
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Argument mode "-1" is not valid.');
new InputArgument('foo', '-1'); new InputArgument('foo', '-1');
} }

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Console\Tests\Input; namespace Symfony\Component\Console\Tests\Input;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
class InputOptionTest extends TestCase class InputOptionTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$option = new InputOption('foo'); $option = new InputOption('foo');
@ -73,12 +76,11 @@ class InputOptionTest extends TestCase
$this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode'); $this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
} }
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Option mode "-1" is not valid.
*/
public function testInvalidModes() public function testInvalidModes()
{ {
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Option mode "-1" is not valid.');
new InputOption('foo', 'f', '-1'); new InputOption('foo', 'f', '-1');
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\CssSelector\Tests\Parser; namespace Symfony\Component\CssSelector\Tests\Parser;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\CssSelector\Exception\SyntaxErrorException; use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
use Symfony\Component\CssSelector\Node\FunctionNode; use Symfony\Component\CssSelector\Node\FunctionNode;
use Symfony\Component\CssSelector\Node\SelectorNode; use Symfony\Component\CssSelector\Node\SelectorNode;
@ -20,6 +21,8 @@ use Symfony\Component\CssSelector\Parser\Token;
class ParserTest extends TestCase class ParserTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** @dataProvider getParserTestData */ /** @dataProvider getParserTestData */
public function testParser($source, $representation) public function testParser($source, $representation)
{ {

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\CssSelector\Tests\Parser; namespace Symfony\Component\CssSelector\Tests\Parser;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\CssSelector\Parser\Token; use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\TokenStream; use Symfony\Component\CssSelector\Parser\TokenStream;
class TokenStreamTest extends TestCase class TokenStreamTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testGetNext() public function testGetNext()
{ {
$stream = new TokenStream(); $stream = new TokenStream();

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Warning; use PHPUnit\Framework\Warning;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
@ -36,6 +37,8 @@ require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
*/ */
class AutowirePassTest extends TestCase class AutowirePassTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testProcess() public function testProcess()
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -750,12 +753,8 @@ class AutowirePassTest extends TestCase
$foo->addMethodCall($method, []); $foo->addMethodCall($method, []);
} }
if (method_exists($this, 'expectException')) { $this->expectException(RuntimeException::class);
$this->expectException(RuntimeException::class); $this->expectExceptionMessage($expectedMsg);
$this->expectExceptionMessage($expectedMsg);
} else {
$this->setExpectedException(RuntimeException::class, $expectedMsg);
}
(new ResolveClassPass())->process($container); (new ResolveClassPass())->process($container);
(new AutowireRequiredMethodsPass())->process($container); (new AutowireRequiredMethodsPass())->process($container);

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\DependencyInjection\Tests; namespace Symfony\Component\DependencyInjection\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
class DefinitionTest extends TestCase class DefinitionTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$def = new Definition('stdClass'); $def = new Definition('stdClass');
@ -73,12 +76,8 @@ class DefinitionTest extends TestCase
$def = new Definition('stdClass'); $def = new Definition('stdClass');
if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException');
$this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.');
$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'); $def->setDecoratedService('foo', 'foo');
} }

View File

@ -760,12 +760,8 @@ class PhpDumperTest extends TestCase
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);
$message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".'; $message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".';
if (method_exists($this, 'expectException')) { $this->expectException(ServiceCircularReferenceException::class);
$this->expectException(ServiceCircularReferenceException::class); $this->expectExceptionMessage($message);
$this->expectExceptionMessage($message);
} else {
$this->setExpectedException(ServiceCircularReferenceException::class, $message);
}
$dumper->dump(); $dumper->dump();
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException; use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -19,6 +20,8 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ParameterBagTest extends TestCase class ParameterBagTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testConstructor() public function testConstructor()
{ {
$bag = new ParameterBag($parameters = [ $bag = new ParameterBag($parameters = [
@ -78,12 +81,8 @@ class ParameterBagTest extends TestCase
'fiz' => ['bar' => ['boo' => 12]], 'fiz' => ['bar' => ['boo' => 12]],
]); ]);
if (method_exists($this, 'expectException')) { $this->expectException(ParameterNotFoundException::class);
$this->expectException(ParameterNotFoundException::class); $this->expectExceptionMessage($exceptionMessage);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage);
}
$bag->get($parameterKey); $bag->get($parameterKey);
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests; namespace Symfony\Component\Form\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\ButtonBuilder; use Symfony\Component\Form\ButtonBuilder;
use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\InvalidArgumentException;
@ -20,6 +21,8 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
*/ */
class ButtonBuilderTest extends TestCase class ButtonBuilderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function getValidNames() public function getValidNames()
{ {
return [ return [
@ -62,12 +65,8 @@ class ButtonBuilderTest extends TestCase
*/ */
public function testInvalidNames($name) public function testInvalidNames($name)
{ {
if (method_exists($this, 'expectException')) { $this->expectException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Buttons cannot have empty names.');
$this->expectExceptionMessage('Buttons cannot have empty names.');
} else {
$this->setExpectedException(InvalidArgumentException::class, 'Buttons cannot have empty names.');
}
new ButtonBuilder($name); new ButtonBuilder($name);
} }
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests\Command; namespace Symfony\Component\Form\Tests\Command;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
@ -25,6 +26,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class DebugCommandTest extends TestCase class DebugCommandTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testDebugDefaults() public function testDebugDefaults()
{ {
$tester = $this->createCommandTester(); $tester = $this->createCommandTester();
@ -99,12 +102,8 @@ Did you mean one of these?
Symfony\Component\Form\Tests\Fixtures\Debug\B\AmbiguousType Symfony\Component\Form\Tests\Fixtures\Debug\B\AmbiguousType
TXT; TXT;
if (method_exists($this, 'expectException')) { $this->expectException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage($expectedMessage);
$this->expectExceptionMessage($expectedMessage);
} else {
$this->setExpectedException(InvalidArgumentException::class, $expectedMessage);
}
$tester = $this->createCommandTester([ $tester = $this->createCommandTester([
'Symfony\Component\Form\Tests\Fixtures\Debug\A', 'Symfony\Component\Form\Tests\Fixtures\Debug\A',

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer;
@ -20,6 +21,8 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTra
*/ */
class DateIntervalToArrayTransformerTest extends DateIntervalTestCase class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
{ {
use ForwardCompatTestTrait;
public function testTransform() public function testTransform()
{ {
$transformer = new DateIntervalToArrayTransformer(); $transformer = new DateIntervalToArrayTransformer();
@ -196,12 +199,8 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
'minutes' => '', 'minutes' => '',
'seconds' => '6', 'seconds' => '6',
]; ];
if (method_exists($this, 'expectException')) { $this->expectException(TransformationFailedException::class);
$this->expectException(TransformationFailedException::class); $this->expectExceptionMessage('This amount of "minutes" is invalid');
$this->expectExceptionMessage('This amount of "minutes" is invalid');
} else {
$this->setExpectedException(TransformationFailedException::class, 'This amount of "minutes" is invalid');
}
$transformer->reverseTransform($input); $transformer->reverseTransform($input);
} }
@ -211,12 +210,8 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
$input = [ $input = [
'invert' => '1', 'invert' => '1',
]; ];
if (method_exists($this, 'expectException')) { $this->expectException(TransformationFailedException::class);
$this->expectException(TransformationFailedException::class); $this->expectExceptionMessage('The value of "invert" must be boolean');
$this->expectExceptionMessage('The value of "invert" must be boolean');
} else {
$this->setExpectedException(TransformationFailedException::class, 'The value of "invert" must be boolean');
}
$transformer->reverseTransform($input); $transformer->reverseTransform($input);
} }

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer;
@ -20,6 +21,8 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTr
*/ */
class DateIntervalToStringTransformerTest extends DateIntervalTestCase class DateIntervalToStringTransformerTest extends DateIntervalTestCase
{ {
use ForwardCompatTestTrait;
public function dataProviderISO() public function dataProviderISO()
{ {
$data = [ $data = [

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
class DateTimeToStringTransformerTest extends TestCase class DateTimeToStringTransformerTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function dataProvider() public function dataProvider()
{ {
$data = [ $data = [

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
class DateTimeToTimestampTransformerTest extends TestCase class DateTimeToTimestampTransformerTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testTransform() public function testTransform()
{ {
$transformer = new DateTimeToTimestampTransformer('UTC', 'UTC'); $transformer = new DateTimeToTimestampTransformer('UTC', 'UTC');

View File

@ -11,11 +11,14 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type; namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Tests\Fixtures\Author; use Symfony\Component\Form\Tests\Fixtures\Author;
use Symfony\Component\Form\Tests\Fixtures\AuthorType; use Symfony\Component\Form\Tests\Fixtures\AuthorType;
class CollectionTypeTest extends BaseTypeTest class CollectionTypeTest extends BaseTypeTest
{ {
use ForwardCompatTestTrait;
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CollectionType'; const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CollectionType';
public function testContainsNoChildByDefault() public function testContainsNoChildByDefault()

View File

@ -172,12 +172,8 @@ class FormBuilderTest extends TestCase
public function testGetUnknown() public function testGetUnknown()
{ {
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException');
$this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException'); $this->expectExceptionMessage('The child with the name "foo" does not exist.');
$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'); $this->builder->get('foo');
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests; namespace Symfony\Component\Form\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\FormConfigBuilder;
/** /**
@ -19,6 +20,8 @@ use Symfony\Component\Form\FormConfigBuilder;
*/ */
class FormConfigTest extends TestCase class FormConfigTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function getHtml4Ids() public function getHtml4Ids()
{ {
return [ return [
@ -67,10 +70,8 @@ class FormConfigTest extends TestCase
{ {
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
if (null !== $expectedException && method_exists($this, 'expectException')) { if (null !== $expectedException) {
$this->expectException($expectedException); $this->expectException($expectedException);
} elseif (null !== $expectedException) {
$this->setExpectedException($expectedException);
} }
$formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher); $formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpFoundation\Tests\File; namespace Symfony\Component\HttpFoundation\Tests\File;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
/** /**
@ -19,6 +20,8 @@ use Symfony\Component\HttpFoundation\File\File;
*/ */
class FileTest extends TestCase class FileTest extends TestCase
{ {
use ForwardCompatTestTrait;
protected $file; protected $file;
public function testGetMimeTypeUsesMimeTypeGuessers() public function testGetMimeTypeUsesMimeTypeGuessers()
@ -42,6 +45,7 @@ class FileTest extends TestCase
public function testConstructWhenFileNotExists() public function testConstructWhenFileNotExists()
{ {
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
new File(__DIR__.'/Fixtures/not_here'); new File(__DIR__.'/Fixtures/not_here');
} }

View File

@ -2070,12 +2070,8 @@ class RequestTest extends TestCase
$this->assertSame($expectedPort, $request->getPort()); $this->assertSame($expectedPort, $request->getPort());
} }
} else { } else {
if (method_exists($this, 'expectException')) { $this->expectException(SuspiciousOperationException::class);
$this->expectException(SuspiciousOperationException::class); $this->expectExceptionMessage('Invalid Host');
$this->expectExceptionMessage('Invalid Host');
} else {
$this->setExpectedException(SuspiciousOperationException::class, 'Invalid Host');
}
$request->getHost(); $request->getHost();
} }

View File

@ -12,10 +12,13 @@
namespace Symfony\Component\HttpKernel\Tests\Config; namespace Symfony\Component\HttpKernel\Tests\Config;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\Config\FileLocator;
class FileLocatorTest extends TestCase class FileLocatorTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLocate() public function testLocate()
{ {
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();

View File

@ -13,12 +13,15 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver; use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
class ContainerControllerResolverTest extends ControllerResolverTest class ContainerControllerResolverTest extends ControllerResolverTest
{ {
use ForwardCompatTestTrait;
public function testGetControllerServiceWithSingleColon() public function testGetControllerServiceWithSingleColon()
{ {
$service = new ControllerTestService('foo'); $service = new ControllerTestService('foo');

View File

@ -13,11 +13,14 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolver; use Symfony\Component\HttpKernel\Controller\ControllerResolver;
class ControllerResolverTest extends TestCase class ControllerResolverTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testGetControllerWithoutControllerParameter() public function testGetControllerWithoutControllerParameter()
{ {
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
@ -159,12 +162,8 @@ class ControllerResolverTest extends TestCase
public function testGetControllerWithUndefinedController($controller, $exceptionName = null, $exceptionMessage = null) public function testGetControllerWithUndefinedController($controller, $exceptionName = null, $exceptionMessage = null)
{ {
$resolver = $this->createControllerResolver(); $resolver = $this->createControllerResolver();
if (method_exists($this, 'expectException')) { $this->expectException($exceptionName);
$this->expectException($exceptionName); $this->expectExceptionMessage($exceptionMessage);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException($exceptionName, $exceptionMessage);
}
$request = Request::create('/'); $request = Request::create('/');
$request->attributes->set('_controller', $controller); $request->attributes->set('_controller', $controller);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Intl\Tests\Util; namespace Symfony\Component\Intl\Tests\Util;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Exception\RuntimeException; use Symfony\Component\Intl\Exception\RuntimeException;
use Symfony\Component\Intl\Util\GitRepository; use Symfony\Component\Intl\Util\GitRepository;
@ -21,6 +22,8 @@ use Symfony\Component\Intl\Util\GitRepository;
*/ */
class GitRepositoryTest extends TestCase class GitRepositoryTest extends TestCase
{ {
use ForwardCompatTestTrait;
private $targetDir; private $targetDir;
const REPO_URL = 'https://github.com/symfony/intl.git'; const REPO_URL = 'https://github.com/symfony/intl.git';
@ -39,11 +42,7 @@ class GitRepositoryTest extends TestCase
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory() public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
{ {
if (method_exists($this, 'expectException')) { $this->expectException(RuntimeException::class);
$this->expectException(RuntimeException::class);
} else {
$this->setExpectedException(RuntimeException::class);
}
@mkdir($this->targetDir, 0777, true); @mkdir($this->targetDir, 0777, true);

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Ldap\Tests; namespace Symfony\Component\Ldap\Tests;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter; use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
use Symfony\Component\Ldap\Adapter\ExtLdap\Collection; use Symfony\Component\Ldap\Adapter\ExtLdap\Collection;
use Symfony\Component\Ldap\Adapter\ExtLdap\Query; use Symfony\Component\Ldap\Adapter\ExtLdap\Query;
@ -24,6 +25,8 @@ use Symfony\Component\Ldap\LdapInterface;
*/ */
class AdapterTest extends LdapTestCase class AdapterTest extends LdapTestCase
{ {
use ForwardCompatTestTrait;
const PAGINATION_REQUIRED_CONFIG = [ const PAGINATION_REQUIRED_CONFIG = [
'options' => [ 'options' => [
'protocol_version' => 3, 'protocol_version' => 3,

View File

@ -869,12 +869,8 @@ class OptionsResolverTest extends TestCase
$this->resolver->setDefined('option'); $this->resolver->setDefined('option');
$this->resolver->setAllowedTypes('option', $allowedType); $this->resolver->setAllowedTypes('option', $allowedType);
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->expectExceptionMessage($exceptionMessage);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage);
}
$this->resolver->resolve(['option' => $actualType]); $this->resolver->resolve(['option' => $actualType]);
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Process\Tests; namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Exception\ProcessFailedException;
/** /**
@ -19,6 +20,8 @@ use Symfony\Component\Process\Exception\ProcessFailedException;
*/ */
class ProcessFailedExceptionTest extends TestCase class ProcessFailedExceptionTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* tests ProcessFailedException throws exception if the process was successful. * tests ProcessFailedException throws exception if the process was successful.
*/ */
@ -29,12 +32,8 @@ class ProcessFailedExceptionTest extends TestCase
->method('isSuccessful') ->method('isSuccessful')
->willReturn(true); ->willReturn(true);
if (method_exists($this, 'expectException')) { $this->expectException(\InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expected a failed process, but the given process was successful.');
$this->expectExceptionMessage('Expected a failed process, but the given process was successful.');
} else {
$this->setExpectedException(\InvalidArgumentException::class, 'Expected a failed process, but the given process was successful.');
}
new ProcessFailedException($process); new ProcessFailedException($process);
} }

View File

@ -967,12 +967,8 @@ class ProcessTest extends TestCase
{ {
$process = $this->getProcess('foo'); $process = $this->getProcess('foo');
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Process\Exception\LogicException');
$this->expectException('Symfony\Component\Process\Exception\LogicException'); $this->expectExceptionMessage(sprintf('Process must be started before calling %s.', $method));
$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}(); $process->{$method}();
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Routing\Tests\Generator; namespace Symfony\Component\Routing\Tests\Generator;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RequestContext;
@ -20,6 +21,8 @@ use Symfony\Component\Routing\RouteCollection;
class UrlGeneratorTest extends TestCase class UrlGeneratorTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testAbsoluteUrlWithPort80() public function testAbsoluteUrlWithPort80()
{ {
$routes = $this->getRoutes('test', new Route('/testing')); $routes = $this->getRoutes('test', new Route('/testing'));

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Security\Core\Tests\Authorization; namespace Symfony\Component\Security\Core\Tests\Authorization;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class AccessDecisionManagerTest extends TestCase class AccessDecisionManagerTest extends TestCase
{ {
use ForwardCompatTestTrait;
/** /**
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */

View File

@ -654,12 +654,8 @@ XML;
public function testDecodeEmptyXml() public function testDecodeEmptyXml()
{ {
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException'); $this->expectExceptionMessage('Invalid XML data, it can not be empty.');
$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'); $this->encoder->decode(' ', 'xml');
} }

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Translation\Tests\Catalogue; namespace Symfony\Component\Translation\Tests\Catalogue;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\MessageCatalogueInterface; use Symfony\Component\Translation\MessageCatalogueInterface;
abstract class AbstractOperationTest extends TestCase abstract class AbstractOperationTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testGetEmptyDomains() public function testGetEmptyDomains()
{ {
$this->assertEquals( $this->assertEquals(

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Translation\Tests\Loader; namespace Symfony\Component\Translation\Tests\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Loader\QtFileLoader; use Symfony\Component\Translation\Loader\QtFileLoader;
class QtFileLoaderTest extends TestCase class QtFileLoaderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLoad() public function testLoad()
{ {
$loader = new QtFileLoader(); $loader = new QtFileLoader();
@ -67,12 +70,8 @@ class QtFileLoaderTest extends TestCase
$loader = new QtFileLoader(); $loader = new QtFileLoader();
$resource = __DIR__.'/../fixtures/empty.xlf'; $resource = __DIR__.'/../fixtures/empty.xlf';
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
$this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException'); $this->expectExceptionMessage(sprintf('Unable to load "%s".', $resource));
$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'); $loader->load($resource, 'en', 'domain1');
} }

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Translation\Tests\Loader; namespace Symfony\Component\Translation\Tests\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Loader\XliffFileLoader; use Symfony\Component\Translation\Loader\XliffFileLoader;
class XliffFileLoaderTest extends TestCase class XliffFileLoaderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLoad() public function testLoad()
{ {
$loader = new XliffFileLoader(); $loader = new XliffFileLoader();
@ -159,12 +162,8 @@ class XliffFileLoaderTest extends TestCase
$loader = new XliffFileLoader(); $loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/empty.xlf'; $resource = __DIR__.'/../fixtures/empty.xlf';
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
$this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException'); $this->expectExceptionMessage(sprintf('Unable to load "%s":', $resource));
$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'); $loader->load($resource, 'en', 'domain1');
} }

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests; namespace Symfony\Component\Validator\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint; use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
@ -22,6 +23,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValueAsDefault;
class ConstraintTest extends TestCase class ConstraintTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testSetProperties() public function testSetProperties()
{ {
$constraint = new ConstraintA([ $constraint = new ConstraintA([

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Validator\Tests\Constraints; namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@ -41,6 +42,8 @@ class ComparisonTest_Class
*/ */
abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTestCase abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTestCase
{ {
use ForwardCompatTestTrait;
protected static function addPhp5Dot5Comparisons(array $comparisons) protected static function addPhp5Dot5Comparisons(array $comparisons)
{ {
$result = $comparisons; $result = $comparisons;
@ -163,12 +166,8 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
{ {
$constraint = $this->createConstraint(['propertyPath' => 'foo']); $constraint = $this->createConstraint(['propertyPath' => 'foo']);
if (method_exists($this, 'expectException')) { $this->expectException(ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class); $this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
} else {
$this->setExpectedException(ConstraintDefinitionException::class, sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
}
$object = new ComparisonTest_Class(5); $object = new ComparisonTest_Class(5);

View File

@ -119,12 +119,8 @@ class BicValidatorTest extends ConstraintValidatorTestCase
{ {
$constraint = new Bic(['ibanPropertyPath' => 'foo']); $constraint = new Bic(['ibanPropertyPath' => 'foo']);
if (method_exists($this, 'expectException')) { $this->expectException(ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class); $this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
} else {
$this->setExpectedException(ConstraintDefinitionException::class, sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
}
$object = new BicComparisonTestClass(5); $object = new BicComparisonTestClass(5);

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Validator\Tests\Mapping; namespace Symfony\Component\Validator\Tests\Mapping;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Validator\Mapping\GetterMetadata; use Symfony\Component\Validator\Mapping\GetterMetadata;
use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Tests\Fixtures\Entity;
class GetterMetadataTest extends TestCase class GetterMetadataTest extends TestCase
{ {
use ForwardCompatTestTrait;
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity'; const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
public function testInvalidPropertyName() public function testInvalidPropertyName()

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests\Mapping\Loader; namespace Symfony\Component\Validator\Tests\Mapping\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\Choice;
@ -29,6 +30,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
class XmlFileLoaderTest extends TestCase class XmlFileLoaderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLoadClassMetadataReturnsTrueIfSuccessful() public function testLoadClassMetadataReturnsTrueIfSuccessful()
{ {
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml'); $loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests\Mapping\Loader; namespace Symfony\Component\Validator\Tests\Mapping\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\Choice;
@ -26,6 +27,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
class YamlFileLoaderTest extends TestCase class YamlFileLoaderTest extends TestCase
{ {
use ForwardCompatTestTrait;
public function testLoadClassMetadataReturnsFalseIfEmpty() public function testLoadClassMetadataReturnsFalseIfEmpty()
{ {
$loader = new YamlFileLoader(__DIR__.'/empty-mapping.yml'); $loader = new YamlFileLoader(__DIR__.'/empty-mapping.yml');

View File

@ -12,11 +12,14 @@
namespace Symfony\Component\Validator\Tests\Mapping; namespace Symfony\Component\Validator\Tests\Mapping;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Mapping\PropertyMetadata;
use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Tests\Fixtures\Entity;
class PropertyMetadataTest extends TestCase class PropertyMetadataTest extends TestCase
{ {
use ForwardCompatTestTrait;
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity'; const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent'; const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';

View File

@ -253,12 +253,8 @@ class InlineTest extends TestCase
*/ */
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator) public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
{ {
if (method_exists($this, 'expectExceptionMessage')) { $this->expectException(ParseException::class);
$this->expectException(ParseException::class); $this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
} else {
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
}
Inline::parse(sprintf('{ foo: %sfoo }', $indicator)); Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
} }
@ -273,12 +269,8 @@ class InlineTest extends TestCase
*/ */
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator) public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
{ {
if (method_exists($this, 'expectExceptionMessage')) { $this->expectException(ParseException::class);
$this->expectException(ParseException::class); $this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
} else {
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
}
Inline::parse(sprintf('{ foo: %sfoo }', $indicator)); Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
} }
@ -627,11 +619,7 @@ class InlineTest extends TestCase
*/ */
public function testParseInvalidBinaryData($data, $expectedMessage) public function testParseInvalidBinaryData($data, $expectedMessage)
{ {
if (method_exists($this, 'expectException')) { $this->expectExceptionMessageRegExp($expectedMessage);
$this->expectExceptionMessageRegExp($expectedMessage);
} else {
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
}
Inline::parse($data); Inline::parse($data);
} }

View File

@ -1374,11 +1374,7 @@ EOT
*/ */
public function testParseInvalidBinaryData($data, $expectedMessage) public function testParseInvalidBinaryData($data, $expectedMessage)
{ {
if (method_exists($this, 'expectException')) { $this->expectExceptionMessageRegExp($expectedMessage);
$this->expectExceptionMessageRegExp($expectedMessage);
} else {
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
}
$this->parser->parse($data); $this->parser->parse($data);
} }
@ -1445,12 +1441,8 @@ EOT;
*/ */
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml) public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
{ {
if (method_exists($this, 'expectException')) { $this->expectException('\Symfony\Component\Yaml\Exception\ParseException');
$this->expectException('\Symfony\Component\Yaml\Exception\ParseException'); $this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));
$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); $this->parser->parse($yaml);
} }