minor #32872 Replace calls to setExpectedException by Pollyfill (jderusse)
This PR was merged into the 3.4 branch.
Discussion
----------
Replace calls to setExpectedException by Pollyfill
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | need #32869 to be merged
| Fixed tickets | #32844
| License | MIT
| Doc PR | NA
PhpUnit method `setExceptionException` has been deprecated seens 5.7. This PR replace theme by `exceptException` provide by the pollyfill.
Commits
-------
41c02d7ead
Replace calls to setExpectedException by Pollyfill
This commit is contained in:
commit
6d499132c0
|
@ -16,9 +16,12 @@ use PHPUnit\Framework\TestCase;
|
|||
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
|
||||
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
|
||||
class EntityUserProviderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testRefreshUserGetsUserByPrimaryKey()
|
||||
{
|
||||
$em = DoctrineTestHelper::createTestEntityManager();
|
||||
|
@ -105,10 +108,9 @@ class EntityUserProviderTest extends TestCase
|
|||
$user1 = new User(null, null, 'user1');
|
||||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||
|
||||
$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'
|
||||
);
|
||||
$this->expectException('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');
|
||||
|
||||
$provider->refreshUser($user1);
|
||||
}
|
||||
|
||||
|
@ -125,10 +127,9 @@ class EntityUserProviderTest extends TestCase
|
|||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||
|
||||
$user2 = new User(1, 2, 'user2');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
|
||||
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
|
||||
'User with id {"id1":1,"id2":2} not found'
|
||||
);
|
||||
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
|
||||
$this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
|
||||
|
||||
$provider->refreshUser($user2);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,16 @@
|
|||
namespace Symfony\Bridge\PhpUnit\Legacy;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
trait ForwardCompatTestTraitForV5
|
||||
{
|
||||
private $forwardCompatExpectedExceptionMessage = '';
|
||||
private $forwardCompatExpectedExceptionCode = null;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -210,4 +214,93 @@ trait ForwardCompatTestTraitForV5
|
|||
{
|
||||
static::assertInternalType('iterable', $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function expectException($exception)
|
||||
{
|
||||
if (method_exists(TestCase::class, 'expectException')) {
|
||||
parent::expectException($exception);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::setExpectedException($exception, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function expectExceptionCode($code)
|
||||
{
|
||||
if (method_exists(TestCase::class, 'expectExceptionCode')) {
|
||||
parent::expectExceptionCode($code);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->forwardCompatExpectedExceptionCode = $code;
|
||||
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function expectExceptionMessage($message)
|
||||
{
|
||||
if (method_exists(TestCase::class, 'expectExceptionMessage')) {
|
||||
parent::expectExceptionMessage($message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->forwardCompatExpectedExceptionMessage = $message;
|
||||
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $messageRegExp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function expectExceptionMessageRegExp($messageRegExp)
|
||||
{
|
||||
if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) {
|
||||
parent::expectExceptionMessageRegExp($messageRegExp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::setExpectedExceptionRegExp(parent::getExpectedException(), $messageRegExp, $this->forwardCompatExpectedExceptionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exceptionMessage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
|
||||
{
|
||||
$this->forwardCompatExpectedExceptionMessage = $exceptionMessage;
|
||||
$this->forwardCompatExpectedExceptionCode = $exceptionCode;
|
||||
|
||||
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exceptionMessageRegExp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = '', $exceptionCode = null)
|
||||
{
|
||||
$this->forwardCompatExpectedExceptionCode = $exceptionCode;
|
||||
|
||||
parent::setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp, $exceptionCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Symfony\Bridge\PhpUnit\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* Don't remove this test case, it tests the legacy group.
|
||||
|
@ -13,6 +14,8 @@ use PHPUnit\Framework\TestCase;
|
|||
*/
|
||||
class ProcessIsolationTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Test abc
|
||||
*/
|
||||
|
@ -25,12 +28,8 @@ class ProcessIsolationTest extends TestCase
|
|||
public function testCallingOtherErrorHandler()
|
||||
{
|
||||
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($class);
|
||||
$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);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
|
||||
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -22,6 +23,8 @@ use Twig\Loader\ArrayLoader;
|
|||
|
||||
class HttpKernelExtensionTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @expectedException \Twig\Error\RuntimeError
|
||||
*/
|
||||
|
@ -49,12 +52,8 @@ class HttpKernelExtensionTest extends TestCase
|
|||
;
|
||||
$renderer = new FragmentHandler($context);
|
||||
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
|
||||
use Symfony\Bundle\FullStack;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Lock\Store\SemaphoreStore;
|
|||
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testDefaultConfig()
|
||||
{
|
||||
$processor = new Processor();
|
||||
|
@ -245,12 +248,8 @@ class ConfigurationTest extends TestCase
|
|||
*/
|
||||
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidConfigurationException::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
$processor = new Processor();
|
||||
$configuration = new Configuration(true);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
|
@ -21,6 +22,8 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|||
|
||||
class AddSecurityVotersPassTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
|
||||
*/
|
||||
|
@ -101,12 +104,8 @@ class AddSecurityVotersPassTest extends TestCase
|
|||
$exception = LogicException::class;
|
||||
$message = 'stdClass should implement the Symfony\Component\Security\Core\Authorization\Voter\VoterInterface interface when used as voter.';
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionMessage($message);
|
||||
} else {
|
||||
$this->setExpectedException($exception, $message);
|
||||
}
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
|
|
|
@ -170,12 +170,8 @@ class UserPasswordEncoderCommandTest extends AbstractWebTestCase
|
|||
|
||||
public function testEncodePasswordNoConfigForGivenUserClass()
|
||||
{
|
||||
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([
|
||||
'command' => 'security:encode-password',
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\BrowserKit\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
|
||||
class CookieTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
|
@ -100,7 +103,7 @@ class CookieTest extends TestCase
|
|||
|
||||
public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
Cookie::fromString('foo');
|
||||
}
|
||||
|
||||
|
@ -113,7 +116,7 @@ class CookieTest extends TestCase
|
|||
|
||||
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
Cookie::fromString('foo=bar', 'foobar');
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,15 @@
|
|||
namespace Symfony\Component\Config\Tests\Definition;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\Definition\ArrayNode;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
use Symfony\Component\Config\Definition\ScalarNode;
|
||||
|
||||
class ArrayNodeTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
|
||||
*/
|
||||
|
@ -55,12 +58,8 @@ class ArrayNodeTest extends TestCase
|
|||
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
|
||||
{
|
||||
if ($expected instanceof \Exception) {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\get_class($expected));
|
||||
$this->expectExceptionMessage($expected->getMessage());
|
||||
} else {
|
||||
$this->setExpectedException(\get_class($expected), $expected->getMessage());
|
||||
}
|
||||
}
|
||||
$node = new ArrayNode('root');
|
||||
$node->setIgnoreExtraKeys($ignore, $remove);
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\Config\Tests\Definition;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\Definition\ArrayNode;
|
||||
use Symfony\Component\Config\Definition\ScalarNode;
|
||||
|
||||
class ScalarNodeTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider getValidValues
|
||||
*/
|
||||
|
@ -95,12 +98,8 @@ class ScalarNodeTest extends TestCase
|
|||
{
|
||||
$node = new ScalarNode('test');
|
||||
|
||||
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([]);
|
||||
}
|
||||
|
@ -110,12 +109,8 @@ class ScalarNodeTest extends TestCase
|
|||
$node = new ScalarNode('test');
|
||||
$node->setInfo('"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([]);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Config\Tests\Util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
|
||||
class XmlUtilsTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLoadFile()
|
||||
{
|
||||
$fixtures = __DIR__.'/../Fixtures/Util/';
|
||||
|
@ -166,12 +169,8 @@ class XmlUtilsTest extends TestCase
|
|||
{
|
||||
$file = __DIR__.'/../Fixtures/foo.xml';
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -314,12 +314,8 @@ class ApplicationTest extends TestCase
|
|||
|
||||
$expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1";
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(CommandNotFoundException::class);
|
||||
$this->expectExceptionMessage($expectedMsg);
|
||||
} else {
|
||||
$this->setExpectedException(CommandNotFoundException::class, $expectedMsg);
|
||||
}
|
||||
|
||||
$application->findNamespace('f');
|
||||
}
|
||||
|
@ -423,12 +419,8 @@ class ApplicationTest extends TestCase
|
|||
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
|
||||
{
|
||||
putenv('COLUMNS=120');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
|
||||
$this->expectExceptionMessage($expectedExceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedExceptionMessage);
|
||||
}
|
||||
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand());
|
||||
|
|
|
@ -120,12 +120,8 @@ class CommandTest extends TestCase
|
|||
*/
|
||||
public function testInvalidCommandNames($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);
|
||||
|
@ -191,7 +187,7 @@ class CommandTest extends TestCase
|
|||
public function testSetAliasesNull()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$command->setAliases(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Console\Tests\Formatter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class OutputFormatterStyleTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$style = new OutputFormatterStyle('green', 'black', ['bold', 'underscore']);
|
||||
|
@ -41,7 +44,7 @@ class OutputFormatterStyleTest extends TestCase
|
|||
$style->setForeground('default');
|
||||
$this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$style->setForeground('undefined-color');
|
||||
}
|
||||
|
||||
|
@ -58,7 +61,7 @@ class OutputFormatterStyleTest extends TestCase
|
|||
$style->setBackground('default');
|
||||
$this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$style->setBackground('undefined-color');
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
|
@ -19,6 +20,8 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
|
||||
class ArgvInputTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$_SERVER['argv'] = ['cli.php', 'foo'];
|
||||
|
@ -182,12 +185,8 @@ class ArgvInputTest extends TestCase
|
|||
*/
|
||||
public function testInvalidInput($argv, $definition, $expectedExceptionMessage)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('RuntimeException');
|
||||
$this->expectExceptionMessage($expectedExceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedException('RuntimeException', $expectedExceptionMessage);
|
||||
}
|
||||
|
||||
$input = new ArgvInput($argv);
|
||||
$input->bind($definition);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
|
@ -19,6 +20,8 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
|
||||
class ArrayInputTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetFirstArgument()
|
||||
{
|
||||
$input = new ArrayInput([]);
|
||||
|
@ -127,12 +130,8 @@ class ArrayInputTest extends TestCase
|
|||
*/
|
||||
public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage($expectedExceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
|
||||
}
|
||||
|
||||
new ArrayInput($parameters, $definition);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class InputArgumentTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$argument = new InputArgument('foo');
|
||||
|
@ -42,12 +45,8 @@ class InputArgumentTest extends TestCase
|
|||
*/
|
||||
public function testInvalidModes($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);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputOptionTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$option = new InputOption('foo');
|
||||
|
@ -78,12 +81,8 @@ class InputOptionTest extends TestCase
|
|||
*/
|
||||
public function testInvalidModes($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);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\CssSelector\Tests\Parser;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
|
||||
use Symfony\Component\CssSelector\Node\FunctionNode;
|
||||
use Symfony\Component\CssSelector\Node\SelectorNode;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\CssSelector\Parser\Token;
|
|||
|
||||
class ParserTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/** @dataProvider getParserTestData */
|
||||
public function testParser($source, $representation)
|
||||
{
|
||||
|
@ -89,7 +92,7 @@ class ParserTest extends TestCase
|
|||
|
||||
/** @var FunctionNode $function */
|
||||
$function = $selectors[0]->getTree();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
$this->expectException('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
Parser::parseSeries($function->getArguments());
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\CssSelector\Tests\Parser;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\CssSelector\Parser\Token;
|
||||
use Symfony\Component\CssSelector\Parser\TokenStream;
|
||||
|
||||
class TokenStreamTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetNext()
|
||||
{
|
||||
$stream = new TokenStream();
|
||||
|
@ -53,7 +56,7 @@ class TokenStreamTest extends TestCase
|
|||
|
||||
public function testFailToGetNextIdentifier()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
$this->expectException('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
|
||||
$stream = new TokenStream();
|
||||
$stream->push(new Token(Token::TYPE_DELIMITER, '.', 2));
|
||||
|
@ -73,7 +76,7 @@ class TokenStreamTest extends TestCase
|
|||
|
||||
public function testFailToGetNextIdentifierOrStar()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
$this->expectException('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
|
||||
|
||||
$stream = new TokenStream();
|
||||
$stream->push(new Token(Token::TYPE_DELIMITER, '.', 2));
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Warning;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
||||
|
@ -33,6 +34,8 @@ require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
|||
*/
|
||||
class AutowirePassTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -841,12 +844,8 @@ class AutowirePassTest extends TestCase
|
|||
$foo->addMethodCall($method, []);
|
||||
}
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage($expectedMsg);
|
||||
} else {
|
||||
$this->setExpectedException(RuntimeException::class, $expectedMsg);
|
||||
}
|
||||
|
||||
(new ResolveClassPass())->process($container);
|
||||
(new AutowireRequiredMethodsPass())->process($container);
|
||||
|
|
|
@ -1056,7 +1056,7 @@ class ContainerBuilderTest extends TestCase
|
|||
$container->registerExtension($extension = new \ProjectExtension());
|
||||
$this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension');
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException');
|
||||
$this->expectException('LogicException');
|
||||
$container->getExtension('no_registered');
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\DependencyInjection\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class DefinitionTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
@ -69,12 +72,8 @@ class DefinitionTest extends TestCase
|
|||
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -550,12 +550,8 @@ class PhpDumperTest extends TestCase
|
|||
$dumper = new PhpDumper($container);
|
||||
|
||||
$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->expectExceptionMessage($message);
|
||||
} else {
|
||||
$this->setExpectedException(ServiceCircularReferenceException::class, $message);
|
||||
}
|
||||
|
||||
$dumper->dump();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
@ -19,6 +20,8 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||
|
||||
class ParameterBagTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$bag = new ParameterBag($parameters = [
|
||||
|
@ -78,12 +81,8 @@ class ParameterBagTest extends TestCase
|
|||
'fiz' => ['bar' => ['boo' => 12]],
|
||||
]);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ParameterNotFoundException::class);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage);
|
||||
}
|
||||
|
||||
$bag->get($parameterKey);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ class GenericEventTest extends TestCase
|
|||
$this->assertEquals('Event', $this->event['name']);
|
||||
|
||||
// test getting invalid arg
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->assertFalse($this->event['nameNotExist']);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\ExpressionLanguage\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\ExpressionLanguage\Node\Node;
|
||||
use Symfony\Component\ExpressionLanguage\ParsedExpression;
|
||||
use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter;
|
||||
|
@ -21,6 +22,8 @@ use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter;
|
|||
*/
|
||||
class ParserCacheAdapterTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetItem()
|
||||
{
|
||||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
|
@ -75,7 +78,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
{
|
||||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->getItems();
|
||||
}
|
||||
|
@ -85,7 +88,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$key = 'key';
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->hasItem($key);
|
||||
}
|
||||
|
@ -94,7 +97,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
{
|
||||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->clear();
|
||||
}
|
||||
|
@ -104,7 +107,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$key = 'key';
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->deleteItem($key);
|
||||
}
|
||||
|
@ -114,7 +117,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$keys = ['key'];
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->deleteItems($keys);
|
||||
}
|
||||
|
@ -124,7 +127,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->saveDeferred($cacheItemMock);
|
||||
}
|
||||
|
@ -133,7 +136,7 @@ class ParserCacheAdapterTest extends TestCase
|
|||
{
|
||||
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
|
||||
$parserCacheAdapter = new ParserCacheAdapter($poolMock);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
|
||||
$parserCacheAdapter->commit();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Form\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\ButtonBuilder;
|
||||
use Symfony\Component\Form\Exception\InvalidArgumentException;
|
||||
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
|
|||
*/
|
||||
class ButtonBuilderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function getValidNames()
|
||||
{
|
||||
return [
|
||||
|
@ -54,12 +57,8 @@ class ButtonBuilderTest extends TestCase
|
|||
*/
|
||||
public function testInvalidNames($name)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Buttons cannot have empty names.');
|
||||
} else {
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Buttons cannot have empty names.');
|
||||
}
|
||||
new ButtonBuilder($name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Form\Tests\Command;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
@ -21,6 +22,8 @@ use Symfony\Component\Form\ResolvedFormTypeFactory;
|
|||
|
||||
class DebugCommandTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testDebugDefaults()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
|
@ -68,12 +71,8 @@ Did you mean one of these?
|
|||
Symfony\Component\Form\Tests\Fixtures\Debug\B\AmbiguousType
|
||||
TXT;
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedException(InvalidArgumentException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
$tester = $this->createCommandTester([
|
||||
'Symfony\Component\Form\Tests\Fixtures\Debug\A',
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTra
|
|||
*/
|
||||
class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$transformer = new DateIntervalToArrayTransformer();
|
||||
|
@ -176,7 +179,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||
{
|
||||
$transformer = new DateIntervalToArrayTransformer();
|
||||
$this->assertNull($transformer->reverseTransform(null));
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
$transformer->reverseTransform('12345');
|
||||
}
|
||||
|
||||
|
@ -184,7 +187,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||
{
|
||||
$transformer = new DateIntervalToArrayTransformer();
|
||||
$input = ['years' => '1'];
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
|
||||
$this->expectException(TransformationFailedException::class);
|
||||
$transformer->reverseTransform($input);
|
||||
}
|
||||
|
||||
|
@ -196,12 +199,8 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||
'minutes' => '',
|
||||
'seconds' => '6',
|
||||
];
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(TransformationFailedException::class);
|
||||
$this->expectExceptionMessage('This amount of "minutes" is invalid');
|
||||
} else {
|
||||
$this->setExpectedException(TransformationFailedException::class, 'This amount of "minutes" is invalid');
|
||||
}
|
||||
$transformer->reverseTransform($input);
|
||||
}
|
||||
|
||||
|
@ -211,12 +210,8 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||
$input = [
|
||||
'invert' => '1',
|
||||
];
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(TransformationFailedException::class);
|
||||
$this->expectExceptionMessage('The value of "invert" must be boolean');
|
||||
} else {
|
||||
$this->setExpectedException(TransformationFailedException::class, 'The value of "invert" must be boolean');
|
||||
}
|
||||
$transformer->reverseTransform($input);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTr
|
|||
*/
|
||||
class DateIntervalToStringTransformerTest extends DateIntervalTestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function dataProviderISO()
|
||||
{
|
||||
$data = [
|
||||
|
@ -75,7 +78,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
|
|||
public function testTransformExpectsDateTime()
|
||||
{
|
||||
$transformer = new DateIntervalToStringTransformer();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
$transformer->transform('1234');
|
||||
}
|
||||
|
||||
|
@ -96,7 +99,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
|
|||
{
|
||||
$reverseTransformer = new DateIntervalToStringTransformer($format, true);
|
||||
$interval = new \DateInterval($output);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
|
||||
$this->expectException(TransformationFailedException::class);
|
||||
$this->assertDateIntervalEquals($interval, $reverseTransformer->reverseTransform($input));
|
||||
}
|
||||
|
||||
|
@ -109,14 +112,14 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
|
|||
public function testReverseTransformExpectsString()
|
||||
{
|
||||
$reverseTransformer = new DateIntervalToStringTransformer();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
$reverseTransformer->reverseTransform(1234);
|
||||
}
|
||||
|
||||
public function testReverseTransformExpectsValidIntervalString()
|
||||
{
|
||||
$reverseTransformer = new DateIntervalToStringTransformer();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
|
||||
$this->expectException(TransformationFailedException::class);
|
||||
$reverseTransformer->reverseTransform('10Y');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ class DateTimeToLocalizedStringTransformerTest extends TestCase
|
|||
|
||||
// HOW TO REPRODUCE?
|
||||
|
||||
//$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
|
||||
//$this->expectException('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
|
||||
|
||||
//$transformer->transform(1.5);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
|
||||
class DateTimeToStringTransformerTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function dataProvider()
|
||||
{
|
||||
$data = [
|
||||
|
@ -111,7 +114,7 @@ class DateTimeToStringTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new DateTimeToStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('1234');
|
||||
}
|
||||
|
@ -150,7 +153,7 @@ class DateTimeToStringTransformerTest extends TestCase
|
|||
{
|
||||
$reverseTransformer = new DateTimeToStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$reverseTransformer->reverseTransform(1234);
|
||||
}
|
||||
|
@ -159,7 +162,7 @@ class DateTimeToStringTransformerTest extends TestCase
|
|||
{
|
||||
$reverseTransformer = new DateTimeToStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$reverseTransformer->reverseTransform('2010-2010-2010');
|
||||
}
|
||||
|
@ -168,7 +171,7 @@ class DateTimeToStringTransformerTest extends TestCase
|
|||
{
|
||||
$reverseTransformer = new DateTimeToStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$reverseTransformer->reverseTransform('2010-04-31');
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
|
||||
class DateTimeToTimestampTransformerTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$transformer = new DateTimeToTimestampTransformer('UTC', 'UTC');
|
||||
|
@ -72,7 +75,7 @@ class DateTimeToTimestampTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new DateTimeToTimestampTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('1234');
|
||||
}
|
||||
|
@ -109,7 +112,7 @@ class DateTimeToTimestampTransformerTest extends TestCase
|
|||
{
|
||||
$reverseTransformer = new DateTimeToTimestampTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$reverseTransformer->reverseTransform('2010-2010-2010');
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class MoneyToLocalizedStringTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('abcd');
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class MoneyToLocalizedStringTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->reverseTransform(12345);
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ class PercentToLocalizedStringTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('foo');
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class PercentToLocalizedStringTransformerTest extends TestCase
|
|||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->reverseTransform(1);
|
||||
}
|
||||
|
|
|
@ -11,11 +11,14 @@
|
|||
|
||||
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\AuthorType;
|
||||
|
||||
class CollectionTypeTest extends BaseTypeTest
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CollectionType';
|
||||
|
||||
public function testContainsNoChildByDefault()
|
||||
|
@ -61,7 +64,7 @@ class CollectionTypeTest extends BaseTypeTest
|
|||
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
]);
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$form->setData(new \stdClass());
|
||||
}
|
||||
|
||||
|
|
|
@ -52,13 +52,13 @@ class FormBuilderTest extends TestCase
|
|||
|
||||
public function testAddNameNoStringAndNoInteger()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->builder->add(true);
|
||||
}
|
||||
|
||||
public function testAddTypeNoString()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->builder->add('foo', 1234);
|
||||
}
|
||||
|
||||
|
@ -170,12 +170,8 @@ class FormBuilderTest extends TestCase
|
|||
|
||||
public function testGetUnknown()
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Form\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Form\FormConfigBuilder;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +20,8 @@ use Symfony\Component\Form\FormConfigBuilder;
|
|||
*/
|
||||
class FormConfigTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function getHtml4Ids()
|
||||
{
|
||||
return [
|
||||
|
@ -72,10 +75,8 @@ class FormConfigTest extends TestCase
|
|||
{
|
||||
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
||||
|
||||
if (null !== $expectedException && method_exists($this, 'expectException')) {
|
||||
if (null !== $expectedException) {
|
||||
$this->expectException($expectedException);
|
||||
} elseif (null !== $expectedException) {
|
||||
$this->setExpectedException($expectedException);
|
||||
}
|
||||
|
||||
$formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher);
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
protected $file;
|
||||
|
||||
public function testGetMimeTypeUsesMimeTypeGuessers()
|
||||
|
@ -64,7 +67,7 @@ class FileTest extends TestCase
|
|||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new File(__DIR__.'/Fixtures/not_here');
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class MimeTypeTest extends TestCase
|
|||
|
||||
public function testGuessImageWithDirectory()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class MimeTypeTest extends TestCase
|
|||
|
||||
public function testGuessWithIncorrectPath()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ class MimeTypeTest extends TestCase
|
|||
@chmod($path, 0333);
|
||||
|
||||
if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) {
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
MimeTypeGuesser::getInstance()->guess($path);
|
||||
} else {
|
||||
$this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');
|
||||
|
|
|
@ -28,7 +28,7 @@ class UploadedFileTest extends TestCase
|
|||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new UploadedFile(
|
||||
__DIR__.'/Fixtures/not_here',
|
||||
|
|
|
@ -2121,12 +2121,8 @@ class RequestTest extends TestCase
|
|||
$this->assertSame($expectedPort, $request->getPort());
|
||||
}
|
||||
} else {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(SuspiciousOperationException::class);
|
||||
$this->expectExceptionMessage('Invalid Host');
|
||||
} else {
|
||||
$this->setExpectedException(SuspiciousOperationException::class, 'Invalid Host');
|
||||
}
|
||||
|
||||
$request->getHost();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
namespace Symfony\Component\HttpKernel\Tests\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\HttpKernel\Config\FileLocator;
|
||||
|
||||
class FileLocatorTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLocate()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
|
||||
|
@ -30,7 +33,7 @@ class FileLocatorTest extends TestCase
|
|||
$kernel
|
||||
->expects($this->never())
|
||||
->method('locateResource');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException');
|
||||
$this->expectException('LogicException');
|
||||
$locator->locate('/some/path');
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
|
|||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
|||
|
||||
class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetControllerService()
|
||||
{
|
||||
$container = $this->createMockContainer();
|
||||
|
@ -237,12 +240,8 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
|||
{
|
||||
// All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected excetion and not use the regex
|
||||
$resolver = $this->createControllerResolver();
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessageRegExp($exceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedExceptionRegExp($exceptionName, $exceptionMessage);
|
||||
}
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $controller);
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
|||
|
||||
class ControllerResolverTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetControllerWithoutControllerParameter()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
|
@ -118,12 +121,8 @@ class ControllerResolverTest extends TestCase
|
|||
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedException($exceptionName, $exceptionMessage);
|
||||
}
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $controller);
|
||||
|
|
|
@ -332,7 +332,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
|
||||
}
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode);
|
||||
$this->expectException($exceptionCode);
|
||||
|
||||
$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
|
||||
}
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode);
|
||||
$this->expectException($exceptionCode);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
|
||||
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
|
||||
|
@ -841,7 +841,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
|
||||
}
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}($exceptionCode);
|
||||
$this->expectException($exceptionCode);
|
||||
|
||||
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
|
||||
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Intl\Tests\Util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Intl\Exception\RuntimeException;
|
||||
use Symfony\Component\Intl\Util\GitRepository;
|
||||
|
@ -21,6 +22,8 @@ use Symfony\Component\Intl\Util\GitRepository;
|
|||
*/
|
||||
class GitRepositoryTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
private $targetDir;
|
||||
|
||||
const REPO_URL = 'https://github.com/symfony/intl.git';
|
||||
|
@ -39,11 +42,7 @@ class GitRepositoryTest extends TestCase
|
|||
|
||||
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
} else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
|
||||
@mkdir($this->targetDir, 0777, true);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Symfony\Component\Ldap\Tests;
|
||||
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
|
||||
use Symfony\Component\Ldap\Adapter\ExtLdap\Collection;
|
||||
use Symfony\Component\Ldap\Adapter\ExtLdap\Query;
|
||||
|
@ -23,6 +24,8 @@ use Symfony\Component\Ldap\LdapInterface;
|
|||
*/
|
||||
class AdapterTest extends LdapTestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLdapEscape()
|
||||
{
|
||||
$ldap = new Adapter();
|
||||
|
@ -74,7 +77,7 @@ class AdapterTest extends LdapTestCase
|
|||
public function testLdapQueryWithoutBind()
|
||||
{
|
||||
$ldap = new Adapter($this->getLdapConfig());
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
|
||||
$this->expectException(NotBoundException::class);
|
||||
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []);
|
||||
$query->execute();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class LdapManagerTest extends LdapTestCase
|
|||
*/
|
||||
public function testLdapAddInvalidEntry()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(LdapException::class);
|
||||
$this->expectException(LdapException::class);
|
||||
$this->executeSearchQuery(1);
|
||||
|
||||
// The entry is missing a subject name
|
||||
|
@ -108,7 +108,7 @@ class LdapManagerTest extends LdapTestCase
|
|||
public function testLdapUnboundAdd()
|
||||
{
|
||||
$this->adapter = new Adapter($this->getLdapConfig());
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
|
||||
$this->expectException(NotBoundException::class);
|
||||
$em = $this->adapter->getEntryManager();
|
||||
$em->add(new Entry(''));
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class LdapManagerTest extends LdapTestCase
|
|||
public function testLdapUnboundRemove()
|
||||
{
|
||||
$this->adapter = new Adapter($this->getLdapConfig());
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
|
||||
$this->expectException(NotBoundException::class);
|
||||
$em = $this->adapter->getEntryManager();
|
||||
$em->remove(new Entry(''));
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class LdapManagerTest extends LdapTestCase
|
|||
public function testLdapUnboundUpdate()
|
||||
{
|
||||
$this->adapter = new Adapter($this->getLdapConfig());
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
|
||||
$this->expectException(NotBoundException::class);
|
||||
$em = $this->adapter->getEntryManager();
|
||||
$em->update(new Entry(''));
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class LdapTest extends TestCase
|
|||
|
||||
public function testCreateWithInvalidAdapterName()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(DriverNotFoundException::class);
|
||||
$this->expectException(DriverNotFoundException::class);
|
||||
Ldap::create('foo');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,12 +549,8 @@ class OptionsResolverTest extends TestCase
|
|||
$this->resolver->setDefined('option');
|
||||
$this->resolver->setAllowedTypes('option', $allowedType);
|
||||
|
||||
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(['option' => $actualType]);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +20,8 @@ use Symfony\Component\Process\Exception\ProcessFailedException;
|
|||
*/
|
||||
class ProcessFailedExceptionTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* tests ProcessFailedException throws exception if the process was successful.
|
||||
*/
|
||||
|
@ -29,12 +32,8 @@ class ProcessFailedExceptionTest extends TestCase
|
|||
->method('isSuccessful')
|
||||
->willReturn(true);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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);
|
||||
}
|
||||
|
|
|
@ -960,12 +960,8 @@ class ProcessTest extends TestCase
|
|||
{
|
||||
$process = $this->getProcess('foo');
|
||||
|
||||
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}();
|
||||
}
|
||||
|
@ -1614,12 +1610,8 @@ EOTXT;
|
|||
if (!$expectException) {
|
||||
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
|
||||
} elseif (self::$notEnhancedSigchild) {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Routing\Tests\Generator;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Routing\RouteCollection;
|
|||
|
||||
class UrlGeneratorTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testAbsoluteUrlWithPort80()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
|
@ -368,7 +371,7 @@ class UrlGeneratorTest extends TestCase
|
|||
|
||||
// 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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\InvalidParameterException');
|
||||
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
|
||||
$generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ class UrlMatcherTest extends TestCase
|
|||
$matcher = $this->getUrlMatcher($collection);
|
||||
|
||||
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo1'));
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$this->assertEquals([], $matcher->match('/foo'));
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ class UrlMatcherTest extends TestCase
|
|||
// z and _format are optional.
|
||||
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxy'));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$matcher->match('/wxy.html');
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ class UrlMatcherTest extends TestCase
|
|||
|
||||
// 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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||
$matcher->match('/ge');
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Security\Core\Tests\Authorization;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
@ -20,6 +21,8 @@ use Symfony\Component\Security\Core\Tests\Authorization\Stub\VoterWithoutInterfa
|
|||
|
||||
class AccessDecisionManagerTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
|
@ -147,12 +150,8 @@ class AccessDecisionManagerTest extends TestCase
|
|||
$exception = LogicException::class;
|
||||
$message = sprintf('stdClass should implement the %s interface when used as voter.', VoterInterface::class);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionMessage($message);
|
||||
} else {
|
||||
$this->setExpectedException($exception, $message);
|
||||
}
|
||||
|
||||
$adm = new AccessDecisionManager([new \stdClass()]);
|
||||
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
|
||||
|
|
|
@ -580,12 +580,8 @@ XML;
|
|||
|
||||
public function testDecodeEmptyXml()
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ class PhpEngineTest extends TestCase
|
|||
$foo = new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('foo');
|
||||
$engine->set($foo);
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\LogicException');
|
||||
$this->expectException('\LogicException');
|
||||
|
||||
unset($engine['foo']);
|
||||
}
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\Translation\Tests\Catalogue;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
use Symfony\Component\Translation\MessageCatalogueInterface;
|
||||
|
||||
abstract class AbstractOperationTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testGetEmptyDomains()
|
||||
{
|
||||
$this->assertEquals(
|
||||
|
@ -41,7 +44,7 @@ abstract class AbstractOperationTest extends TestCase
|
|||
|
||||
public function testGetMessagesFromUnknownDomain()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en'),
|
||||
new MessageCatalogue('en')
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\Translation\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Translation\Loader\QtFileLoader;
|
||||
|
||||
class QtFileLoaderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$loader = new QtFileLoader();
|
||||
|
@ -63,12 +66,8 @@ class QtFileLoaderTest extends TestCase
|
|||
$loader = new QtFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/empty.xlf';
|
||||
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -12,11 +12,14 @@
|
|||
namespace Symfony\Component\Translation\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Translation\Loader\XliffFileLoader;
|
||||
|
||||
class XliffFileLoaderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$loader = new XliffFileLoader();
|
||||
|
@ -149,12 +152,8 @@ class XliffFileLoaderTest extends TestCase
|
|||
$loader = new XliffFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/empty.xlf';
|
||||
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Validator\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
|
@ -22,6 +23,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValueAsDefault;
|
|||
|
||||
class ConstraintTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testSetProperties()
|
||||
{
|
||||
$constraint = new ConstraintA([
|
||||
|
@ -35,7 +38,7 @@ class ConstraintTest extends TestCase
|
|||
|
||||
public function testSetNotExistingPropertyThrowsException()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
|
||||
new ConstraintA([
|
||||
'foo' => 'bar',
|
||||
|
@ -46,14 +49,14 @@ class ConstraintTest extends TestCase
|
|||
{
|
||||
$constraint = new ConstraintA();
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
|
||||
$constraint->foo = 'bar';
|
||||
}
|
||||
|
||||
public function testInvalidAndRequiredOptionsPassed()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\InvalidOptionsException');
|
||||
|
||||
new ConstraintC([
|
||||
'option1' => 'default',
|
||||
|
@ -101,14 +104,14 @@ class ConstraintTest extends TestCase
|
|||
|
||||
public function testSetUndefinedDefaultProperty()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
new ConstraintB('foo');
|
||||
}
|
||||
|
||||
public function testRequiredOptionsMustBeDefined()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\MissingOptionsException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\MissingOptionsException');
|
||||
|
||||
new ConstraintC();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
|
@ -41,6 +42,8 @@ class ComparisonTest_Class
|
|||
*/
|
||||
abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
protected static function addPhp5Dot5Comparisons(array $comparisons)
|
||||
{
|
||||
$result = $comparisons;
|
||||
|
@ -163,12 +166,8 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
|
|||
{
|
||||
$constraint = $this->createConstraint(['propertyPath' => 'foo']);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ConstraintDefinitionException::class);
|
||||
$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);
|
||||
|
||||
|
|
|
@ -43,14 +43,14 @@ class ClassMetadataTest extends TestCase
|
|||
|
||||
public function testAddConstraintDoesNotAcceptValid()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new Valid());
|
||||
}
|
||||
|
||||
public function testAddConstraintRequiresClassConstraints()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new PropertyConstraint());
|
||||
}
|
||||
|
|
|
@ -12,16 +12,19 @@
|
|||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Validator\Mapping\GetterMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
|
||||
class GetterMetadataTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
|
||||
public function testInvalidPropertyName()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
|
||||
new GetterMetadata(self::CLASSNAME, 'foobar');
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
|
@ -29,6 +30,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
|||
|
||||
class XmlFileLoaderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLoadClassMetadataReturnsTrueIfSuccessful()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||
|
@ -114,7 +117,7 @@ class XmlFileLoaderTest extends TestCase
|
|||
$loader = new XmlFileLoader(__DIR__.'/withdoctype.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$this->expectException('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
|
@ -129,7 +132,7 @@ class XmlFileLoaderTest extends TestCase
|
|||
try {
|
||||
$loader->loadClassMetadata($metadata);
|
||||
} catch (MappingException $e) {
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$this->expectException('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
|
@ -26,6 +27,8 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
|||
|
||||
class YamlFileLoaderTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
public function testLoadClassMetadataReturnsFalseIfEmpty()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/empty-mapping.yml');
|
||||
|
@ -69,7 +72,7 @@ class YamlFileLoaderTest extends TestCase
|
|||
$loader->loadClassMetadata($metadata);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// Call again. Again an exception should be thrown
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException');
|
||||
$this->expectException('\InvalidArgumentException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class MemberMetadataTest extends TestCase
|
|||
|
||||
public function testAddConstraintRequiresClassConstraints()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new ClassConstraint());
|
||||
}
|
||||
|
|
|
@ -12,17 +12,20 @@
|
|||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
|
||||
use Symfony\Component\Validator\Mapping\PropertyMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
|
||||
class PropertyMetadataTest extends TestCase
|
||||
{
|
||||
use ForwardCompatTestTrait;
|
||||
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
||||
|
||||
public function testInvalidPropertyName()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
|
||||
new PropertyMetadata(self::CLASSNAME, 'foobar');
|
||||
}
|
||||
|
@ -50,7 +53,7 @@ class PropertyMetadataTest extends TestCase
|
|||
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
|
||||
$metadata->name = 'test';
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
$metadata->getPropertyValue($entity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,12 +307,8 @@ class InlineTest extends TestCase
|
|||
*/
|
||||
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
|
||||
{
|
||||
if (method_exists($this, 'expectExceptionMessage')) {
|
||||
$this->expectException(ParseException::class);
|
||||
$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));
|
||||
}
|
||||
|
@ -327,12 +323,8 @@ class InlineTest extends TestCase
|
|||
*/
|
||||
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
|
||||
{
|
||||
if (method_exists($this, 'expectExceptionMessage')) {
|
||||
$this->expectException(ParseException::class);
|
||||
$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));
|
||||
}
|
||||
|
@ -700,11 +692,7 @@ class InlineTest extends TestCase
|
|||
*/
|
||||
public function testParseInvalidBinaryData($data, $expectedMessage)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectExceptionMessageRegExp($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
Inline::parse($data);
|
||||
}
|
||||
|
|
|
@ -1488,11 +1488,7 @@ EOT
|
|||
*/
|
||||
public function testParseInvalidBinaryData($data, $expectedMessage)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectExceptionMessageRegExp($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
$this->parser->parse($data);
|
||||
}
|
||||
|
@ -1559,12 +1555,8 @@ EOT;
|
|||
*/
|
||||
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
Reference in New Issue