Merge branch '5.2' into 5.x

* 5.2:
  Use ::class keyword when possible
This commit is contained in:
Fabien Potencier 2021-01-11 07:08:00 +01:00
commit c373e24e49
60 changed files with 162 additions and 143 deletions

View File

@ -21,6 +21,7 @@ use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\User; use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class EntityUserProviderTest extends TestCase class EntityUserProviderTest extends TestCase
{ {
@ -154,7 +155,7 @@ class EntityUserProviderTest extends TestCase
->method('loadUserByUsername') ->method('loadUserByUsername')
->with('name') ->with('name')
->willReturn( ->willReturn(
$this->getMockBuilder('\Symfony\Component\Security\Core\User\UserInterface')->getMock() $this->getMockBuilder(UserInterface::class)->getMock()
); );
$provider = new EntityUserProvider( $provider = new EntityUserProvider(

View File

@ -14,6 +14,8 @@ namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy;
require_once __DIR__.'/Fixtures/includes/foo.php'; require_once __DIR__.'/Fixtures/includes/foo.php';
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManagerBridgeFooClass;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -31,7 +33,7 @@ class ContainerBuilderTest extends TestCase
$builder->setProxyInstantiator(new RuntimeInstantiator()); $builder->setProxyInstantiator(new RuntimeInstantiator());
$builder->register('foo1', 'ProxyManagerBridgeFooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php')->setPublic(true); $builder->register('foo1', ProxyManagerBridgeFooClass::class)->setFile(__DIR__.'/Fixtures/includes/foo.php')->setPublic(true);
$builder->getDefinition('foo1')->setLazy(true); $builder->getDefinition('foo1')->setLazy(true);
$builder->compile(); $builder->compile();
@ -43,16 +45,16 @@ class ContainerBuilderTest extends TestCase
$this->assertSame(0, $foo1::$destructorCount); $this->assertSame(0, $foo1::$destructorCount);
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls'); $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls');
$this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1); $this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1);
$this->assertInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1); $this->assertInstanceOf(LazyLoadingInterface::class, $foo1);
$this->assertFalse($foo1->isProxyInitialized()); $this->assertFalse($foo1->isProxyInitialized());
$foo1->initializeProxy(); $foo1->initializeProxy();
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization'); $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization');
$this->assertTrue($foo1->isProxyInitialized()); $this->assertTrue($foo1->isProxyInitialized());
$this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1->getWrappedValueHolderValue()); $this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1->getWrappedValueHolderValue());
$this->assertNotInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1->getWrappedValueHolderValue()); $this->assertNotInstanceOf(LazyLoadingInterface::class, $foo1->getWrappedValueHolderValue());
$foo1->__destruct(); $foo1->__destruct();
$this->assertSame(1, $foo1::$destructorCount); $this->assertSame(1, $foo1::$destructorCount);

View File

@ -102,7 +102,7 @@ class TranslatorTest extends TestCase
$this->expectException('InvalidArgumentException'); $this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid "invalid locale" locale.'); $this->expectExceptionMessage('Invalid "invalid locale" locale.');
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock(); $loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir], 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale'); $translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir], 'loader', TranslatorWithInvalidLocale::class);
$translator->trans('foo'); $translator->trans('foo');
} }
@ -308,7 +308,7 @@ class TranslatorTest extends TestCase
return $container; return $container;
} }
public function getTranslator($loader, $options = [], $loaderFomat = 'loader', $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $defaultLocale = 'en', array $enabledLocales = []) public function getTranslator($loader, $options = [], $loaderFomat = 'loader', $translatorClass = Translator::class, $defaultLocale = 'en', array $enabledLocales = [])
{ {
$translator = $this->createTranslator($loader, $options, $translatorClass, $loaderFomat, $defaultLocale, $enabledLocales); $translator = $this->createTranslator($loader, $options, $translatorClass, $loaderFomat, $defaultLocale, $enabledLocales);
@ -390,7 +390,7 @@ class TranslatorTest extends TestCase
$this->assertEquals('It works!', $translator->trans('message', [], 'domain.with.dots')); $this->assertEquals('It works!', $translator->trans('message', [], 'domain.with.dots'));
} }
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader', $defaultLocale = 'en', array $enabledLocales = []) private function createTranslator($loader, $options, $translatorClass = Translator::class, $loaderFomat = 'loader', $defaultLocale = 'en', array $enabledLocales = [])
{ {
if (null === $defaultLocale) { if (null === $defaultLocale) {
return new $translatorClass( return new $translatorClass(

View File

@ -258,7 +258,7 @@ class UserPasswordEncoderCommandTest extends AbstractWebTestCase
public function testEncodePasswordNoConfigForGivenUserClass() public function testEncodePasswordNoConfigForGivenUserClass()
{ {
$this->expectException('\RuntimeException'); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".'); $this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".');
$this->passwordEncoderCommandTester->execute([ $this->passwordEncoderCommandTester->execute([

View File

@ -12,10 +12,14 @@
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\AppVariable;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader;
use Symfony\Bundle\TwigBundle\TemplateIterator; use Symfony\Bundle\TwigBundle\TemplateIterator;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Twig\Loader\FilesystemLoader as TwigFilesystemLoader;
class ExtensionPassTest extends TestCase class ExtensionPassTest extends TestCase
{ {
@ -24,12 +28,12 @@ class ExtensionPassTest extends TestCase
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->setParameter('kernel.debug', false); $container->setParameter('kernel.debug', false);
$container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable'); $container->register('twig.app_variable', AppVariable::class);
$container->register('twig.extension.yaml'); $container->register('twig.extension.yaml');
$container->register('twig.extension.debug.stopwatch'); $container->register('twig.extension.debug.stopwatch');
$container->register('twig.extension.expression'); $container->register('twig.extension.expression');
$nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader'); $nativeTwigLoader = new Definition(TwigFilesystemLoader::class);
$nativeTwigLoader->addMethodCall('addPath', []); $nativeTwigLoader->addMethodCall('addPath', []);
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader); $container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);

View File

@ -81,7 +81,7 @@ class HttpBrowserTest extends AbstractBrowserTest
->method('request') ->method('request')
->with('POST', 'http://example.com/', $this->callback(function ($options) { ->with('POST', 'http://example.com/', $this->callback(function ($options) {
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
$this->assertInstanceOf('\Generator', $options['body']); $this->assertInstanceOf(\Generator::class, $options['body']);
$this->assertStringContainsString('my_file', implode('', iterator_to_array($options['body']))); $this->assertStringContainsString('my_file', implode('', iterator_to_array($options['body'])));
return true; return true;
@ -191,7 +191,7 @@ class HttpBrowserTest extends AbstractBrowserTest
->method('request') ->method('request')
->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) { ->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) {
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
$this->assertInstanceOf('\Generator', $options['body']); $this->assertInstanceOf(\Generator::class, $options['body']);
$body = implode('', iterator_to_array($options['body'], false)); $body = implode('', iterator_to_array($options['body'], false));
foreach ($fileContents as $content) { foreach ($fileContents as $content) {
$this->assertStringContainsString($content, $body); $this->assertStringContainsString($content, $body);
@ -209,7 +209,7 @@ class HttpBrowserTest extends AbstractBrowserTest
->method('request') ->method('request')
->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) { ->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) {
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
$this->assertInstanceOf('\Generator', $options['body']); $this->assertInstanceOf(\Generator::class, $options['body']);
$body = implode('', iterator_to_array($options['body'], false)); $body = implode('', iterator_to_array($options['body'], false));
foreach ($fileContents as $content) { foreach ($fileContents as $content) {
$this->assertStringNotContainsString($content, $body); $this->assertStringNotContainsString($content, $body);

View File

@ -186,7 +186,7 @@ class MemcachedAdapterTest extends AdapterTestCase
public function provideDsnWithOptions(): iterable public function provideDsnWithOptions(): iterable
{ {
if (!class_exists('\Memcached')) { if (!class_exists(\Memcached::class)) {
self::markTestSkipped('Extension memcached required.'); self::markTestSkipped('Extension memcached required.');
} }

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Config\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\ResourceCheckerConfigCache; use Symfony\Component\Config\ResourceCheckerConfigCache;
use Symfony\Component\Config\ResourceCheckerInterface;
use Symfony\Component\Config\Tests\Resource\ResourceStub; use Symfony\Component\Config\Tests\Resource\ResourceStub;
class ResourceCheckerConfigCacheTest extends TestCase class ResourceCheckerConfigCacheTest extends TestCase
@ -45,7 +46,7 @@ class ResourceCheckerConfigCacheTest extends TestCase
public function testCacheIsNotFreshIfEmpty() public function testCacheIsNotFreshIfEmpty()
{ {
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock() $checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock()
->expects($this->never())->method('supports'); ->expects($this->never())->method('supports');
/* If there is nothing in the cache, it needs to be filled (and thus it's not fresh). /* If there is nothing in the cache, it needs to be filled (and thus it's not fresh).
@ -82,7 +83,7 @@ class ResourceCheckerConfigCacheTest extends TestCase
public function testIsFreshWithchecker() public function testIsFreshWithchecker()
{ {
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
$checker->expects($this->once()) $checker->expects($this->once())
->method('supports') ->method('supports')
@ -100,7 +101,7 @@ class ResourceCheckerConfigCacheTest extends TestCase
public function testIsNotFreshWithchecker() public function testIsNotFreshWithchecker()
{ {
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
$checker->expects($this->once()) $checker->expects($this->once())
->method('supports') ->method('supports')
@ -118,7 +119,7 @@ class ResourceCheckerConfigCacheTest extends TestCase
public function testCacheIsNotFreshWhenUnserializeFails() public function testCacheIsNotFreshWhenUnserializeFails()
{ {
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
$cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]); $cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]);
$cache->write('foo', [new FileResource(__FILE__)]); $cache->write('foo', [new FileResource(__FILE__)]);
@ -138,7 +139,8 @@ class ResourceCheckerConfigCacheTest extends TestCase
public function testCacheIsNotFreshIfNotExistsMetaFile() public function testCacheIsNotFreshIfNotExistsMetaFile()
{ {
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker = $this->getMockBuilder(ResourceCheckerInterface::class
)->getMock();
$cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]); $cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]);
$cache->write('foo', [new FileResource(__FILE__)]); $cache->write('foo', [new FileResource(__FILE__)]);

View File

@ -764,7 +764,7 @@ class ApplicationTest extends TestCase
$tester->run(['command' => 'foo'], ['decorated' => false]); $tester->run(['command' => 'foo'], ['decorated' => false]);
$this->fail('->setCatchExceptions() sets the catch exception flag'); $this->fail('->setCatchExceptions() sets the catch exception flag');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag'); $this->assertInstanceOf(\Exception::class, $e, '->setCatchExceptions() sets the catch exception flag');
$this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag'); $this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
} }
} }

View File

@ -85,7 +85,7 @@ class OutputFormatterStyleTest extends TestCase
$style->setOption('foo'); $style->setOption('foo');
$this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
$this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
} }
} }

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Tests\Helper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\HelperInterface;
use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\HelperSet;
class HelperSetTest extends TestCase class HelperSetTest extends TestCase
@ -66,7 +67,7 @@ class HelperSetTest extends TestCase
$helperset->get('foo'); $helperset->get('foo');
$this->fail('->get() throws InvalidArgumentException when helper not found'); $this->fail('->get() throws InvalidArgumentException when helper not found');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws InvalidArgumentException when helper not found'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found');
$this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found'); $this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found');
$this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found'); $this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found');
} }
@ -111,7 +112,7 @@ class HelperSetTest extends TestCase
private function getGenericMockHelper($name, HelperSet $helperset = null) private function getGenericMockHelper($name, HelperSet $helperset = null)
{ {
$mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock(); $mock_helper = $this->getMockBuilder(HelperInterface::class)->getMock();
$mock_helper->expects($this->any()) $mock_helper->expects($this->any())
->method('getName') ->method('getName')
->willReturn($name); ->willReturn($name);

View File

@ -17,6 +17,7 @@ use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
@ -728,7 +729,7 @@ EOD;
' [<info>żółw </info>] bar', ' [<info>żółw </info>] bar',
' [<info>łabądź</info>] baz', ' [<info>łabądź</info>] baz',
]; ];
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock(); $output = $this->getMockBuilder(OutputInterface::class)->getMock();
$output->method('getFormatter')->willReturn(new OutputFormatter()); $output->method('getFormatter')->willReturn(new OutputFormatter());
$dialog = new QuestionHelper(); $dialog = new QuestionHelper();

View File

@ -55,7 +55,7 @@ class ResolveClassPassTest extends TestCase
{ {
yield [\stdClass::class]; yield [\stdClass::class];
yield ['bar']; yield ['bar'];
yield ['\DateTime']; yield [\DateTime::class];
} }
public function testNonFqcnChildDefinition() public function testNonFqcnChildDefinition()

View File

@ -420,7 +420,7 @@ class ContainerBuilderTest extends TestCase
$builder = new ContainerBuilder(); $builder = new ContainerBuilder();
$builder->register('foo1', '%class%'); $builder->register('foo1', '%class%');
$builder->setParameter('class', 'stdClass'); $builder->setParameter('class', 'stdClass');
$this->assertInstanceOf('\stdClass', $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition'); $this->assertInstanceOf(\stdClass::class, $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
} }
public function testCreateServiceArguments() public function testCreateServiceArguments()
@ -519,7 +519,7 @@ class ContainerBuilderTest extends TestCase
foreach ($lazyContext->lazyValues as $k => $v) { foreach ($lazyContext->lazyValues as $k => $v) {
++$i; ++$i;
$this->assertEquals('k1', $k); $this->assertEquals('k1', $k);
$this->assertInstanceOf('\stdClass', $v); $this->assertInstanceOf(\stdClass::class, $v);
} }
// The second argument should have been ignored. // The second argument should have been ignored.

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\DependencyInjection\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Contracts\Service\ResetInterface; use Symfony\Contracts\Service\ResetInterface;
@ -116,7 +117,7 @@ class ContainerTest extends TestCase
$sc->getParameter('baba'); $sc->getParameter('baba');
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist'); $this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
$this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist'); $this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
} }
} }
@ -252,7 +253,7 @@ class ContainerTest extends TestCase
$sc->get('circular'); $sc->get('circular');
$this->fail('->get() throws a ServiceCircularReferenceException if it contains circular reference'); $this->fail('->get() throws a ServiceCircularReferenceException if it contains circular reference');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException', $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference'); $this->assertInstanceOf(ServiceCircularReferenceException::class, $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference');
$this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference'); $this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference');
} }
} }

View File

@ -217,7 +217,7 @@ class PhpDumperTest extends TestCase
$dumper->dump(); $dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertInstanceOf(RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} }
} }

View File

@ -66,7 +66,7 @@ class XmlDumperTest extends TestCase
$dumper->dump(); $dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} }
} }

View File

@ -61,7 +61,7 @@ class YamlDumperTest extends TestCase
$dumper->dump(); $dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} }
} }

View File

@ -3,6 +3,7 @@
require_once __DIR__.'/../includes/classes.php'; require_once __DIR__.'/../includes/classes.php';
require_once __DIR__.'/../includes/foo.php'; require_once __DIR__.'/../includes/foo.php';
use Bar\FooClass;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -13,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\Expression;
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container $container
->register('foo', '\Bar\FooClass') ->register('foo', FooClass::class)
->addTag('foo', ['foo' => 'foo']) ->addTag('foo', ['foo' => 'foo'])
->addTag('foo', ['bar' => 'bar', 'baz' => 'baz']) ->addTag('foo', ['bar' => 'bar', 'baz' => 'baz'])
->addTag('foo', ['name' => 'bar', 'baz' => 'baz']) ->addTag('foo', ['name' => 'bar', 'baz' => 'baz'])

View File

@ -548,7 +548,7 @@ class XmlFileLoaderTest extends TestCase
$loader->load('extensions/services4.xml'); $loader->load('extensions/services4.xml');
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid'); $this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->load() throws an InvalidArgumentException if the tag is not valid');
$this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
} }
} }

View File

@ -279,7 +279,7 @@ class YamlFileLoaderTest extends TestCase
$loader->load('services11.yml'); $loader->load('services11.yml');
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid'); $this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->load() throws an InvalidArgumentException if the tag is not valid');
$this->assertStringStartsWith('There is no extension able to load the configuration for "foobarfoobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertStringStartsWith('There is no extension able to load the configuration for "foobarfoobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
} }
} }

View File

@ -290,7 +290,7 @@ class FlattenExceptionTest extends TestCase
$args = $array[$i++]; $args = $array[$i++];
$this->assertSame('object', $args[0]); $this->assertSame('object', $args[0]);
$this->assertTrue('Closure' === $args[1] || is_subclass_of($args[1], '\Closure'), 'Expect object class name to be Closure or a subclass of Closure.'); $this->assertTrue('Closure' === $args[1] || is_subclass_of($args[1], \Closure::class), 'Expect object class name to be Closure or a subclass of Closure.');
$this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]); $this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]);
$this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]); $this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]);

View File

@ -80,7 +80,7 @@ class GenericEventTest extends TestCase
public function testGetArgException() public function testGetArgException()
{ {
$this->expectException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->event->getArgument('nameNotExist'); $this->event->getArgument('nameNotExist');
} }
@ -90,7 +90,7 @@ class GenericEventTest extends TestCase
$this->assertEquals('Event', $this->event['name']); $this->assertEquals('Event', $this->event['name']);
// test getting invalid arg // test getting invalid arg
$this->expectException('InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->assertFalse($this->event['nameNotExist']); $this->assertFalse($this->event['nameNotExist']);
} }

View File

@ -72,13 +72,13 @@ class ImmutableEventDispatcherTest extends TestCase
public function testAddListenerDisallowed() public function testAddListenerDisallowed()
{ {
$this->expectException('\BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$this->dispatcher->addListener('event', function () { return 'foo'; }); $this->dispatcher->addListener('event', function () { return 'foo'; });
} }
public function testAddSubscriberDisallowed() public function testAddSubscriberDisallowed()
{ {
$this->expectException('\BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock(); $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
$this->dispatcher->addSubscriber($subscriber); $this->dispatcher->addSubscriber($subscriber);
@ -86,13 +86,13 @@ class ImmutableEventDispatcherTest extends TestCase
public function testRemoveListenerDisallowed() public function testRemoveListenerDisallowed()
{ {
$this->expectException('\BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$this->dispatcher->removeListener('event', function () { return 'foo'; }); $this->dispatcher->removeListener('event', function () { return 'foo'; });
} }
public function testRemoveSubscriberDisallowed() public function testRemoveSubscriberDisallowed()
{ {
$this->expectException('\BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock(); $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
$this->dispatcher->removeSubscriber($subscriber); $this->dispatcher->removeSubscriber($subscriber);

View File

@ -82,7 +82,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
); );
} }
if (!$dateInterval instanceof \DateInterval) { if (!$dateInterval instanceof \DateInterval) {
throw new UnexpectedTypeException($dateInterval, '\DateInterval'); throw new UnexpectedTypeException($dateInterval, \DateInterval::class);
} }
$result = []; $result = [];
foreach (self::$availableFields as $field => $char) { foreach (self::$availableFields as $field => $char) {

View File

@ -51,7 +51,7 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
return ''; return '';
} }
if (!$value instanceof \DateInterval) { if (!$value instanceof \DateInterval) {
throw new UnexpectedTypeException($value, '\DateInterval'); throw new UnexpectedTypeException($value, \DateInterval::class);
} }
return $value->format($this->format); return $value->format($this->format);

View File

@ -26,6 +26,7 @@ use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface; use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator; use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
use Symfony\Component\Form\ChoiceList\View\ChoiceListView; use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\ChoiceList\View\ChoiceView;
@ -351,17 +352,17 @@ class ChoiceType extends AbstractType
$resolver->setNormalizer('placeholder', $placeholderNormalizer); $resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer); $resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
$resolver->setAllowedTypes('choices', ['null', 'array', '\Traversable']); $resolver->setAllowedTypes('choices', ['null', 'array', \Traversable::class]);
$resolver->setAllowedTypes('choice_translation_domain', ['null', 'bool', 'string']); $resolver->setAllowedTypes('choice_translation_domain', ['null', 'bool', 'string']);
$resolver->setAllowedTypes('choice_loader', ['null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface', ChoiceLoader::class]); $resolver->setAllowedTypes('choice_loader', ['null', ChoiceLoaderInterface::class, ChoiceLoader::class]);
$resolver->setAllowedTypes('choice_filter', ['null', 'callable', 'string', PropertyPath::class, ChoiceFilter::class]); $resolver->setAllowedTypes('choice_filter', ['null', 'callable', 'string', PropertyPath::class, ChoiceFilter::class]);
$resolver->setAllowedTypes('choice_label', ['null', 'bool', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceLabel::class]); $resolver->setAllowedTypes('choice_label', ['null', 'bool', 'callable', 'string', PropertyPath::class, ChoiceLabel::class]);
$resolver->setAllowedTypes('choice_name', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceFieldName::class]); $resolver->setAllowedTypes('choice_name', ['null', 'callable', 'string', PropertyPath::class, ChoiceFieldName::class]);
$resolver->setAllowedTypes('choice_value', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceValue::class]); $resolver->setAllowedTypes('choice_value', ['null', 'callable', 'string', PropertyPath::class, ChoiceValue::class]);
$resolver->setAllowedTypes('choice_attr', ['null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceAttr::class]); $resolver->setAllowedTypes('choice_attr', ['null', 'array', 'callable', 'string', PropertyPath::class, ChoiceAttr::class]);
$resolver->setAllowedTypes('choice_translation_parameters', ['null', 'array', 'callable', ChoiceTranslationParameters::class]); $resolver->setAllowedTypes('choice_translation_parameters', ['null', 'array', 'callable', ChoiceTranslationParameters::class]);
$resolver->setAllowedTypes('preferred_choices', ['array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', PreferredChoice::class]); $resolver->setAllowedTypes('preferred_choices', ['array', '\Traversable', 'callable', 'string', PropertyPath::class, PreferredChoice::class]);
$resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', GroupBy::class]); $resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', PropertyPath::class, GroupBy::class]);
} }
/** /**

View File

@ -36,15 +36,15 @@ class ButtonBuilderTest extends TestCase
*/ */
public function testValidNames($name) public function testValidNames($name)
{ {
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name)); $this->assertInstanceOf(ButtonBuilder::class, new ButtonBuilder($name));
} }
public function testNameContainingIllegalCharacters() public function testNameContainingIllegalCharacters()
{ {
$this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException'); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The name "button[]" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").'); $this->expectExceptionMessage('The name "button[]" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").');
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]')); $this->assertInstanceOf(ButtonBuilder::class, new ButtonBuilder('button[]'));
} }
public function getInvalidNames() public function getInvalidNames()

View File

@ -45,7 +45,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, $this->isInstanceOf('\Closure')) ->with($choices, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($choices, $callback) { ->willReturnCallback(function ($choices, $callback) {
return new ArrayChoiceList(array_map($callback, $choices)); return new ArrayChoiceList(array_map($callback, $choices));
}); });
@ -59,7 +59,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, $this->isInstanceOf('\Closure')) ->with($choices, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($choices, $callback) { ->willReturnCallback(function ($choices, $callback) {
return new ArrayChoiceList(array_map($callback, $choices)); return new ArrayChoiceList(array_map($callback, $choices));
}); });
@ -114,7 +114,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, $this->isInstanceOf('\Closure')) ->with($loader, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($loader, $callback) { ->willReturnCallback(function ($loader, $callback) {
return new ArrayChoiceList((array) $callback((object) ['property' => 'value'])); return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
}); });
@ -149,7 +149,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, $this->isInstanceOf('\Closure')) ->with($choices, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($choices, $callback) { ->willReturnCallback(function ($choices, $callback) {
return new ArrayChoiceList(array_map($callback, $choices)); return new ArrayChoiceList(array_map($callback, $choices));
}); });
@ -164,7 +164,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, $this->isInstanceOf('\Closure')) ->with($loader, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($loader, $callback) { ->willReturnCallback(function ($loader, $callback) {
return new ArrayChoiceList((array) $callback(null)); return new ArrayChoiceList((array) $callback(null));
}); });
@ -178,7 +178,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, $this->isInstanceOf('\Closure')) ->with($loader, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($loader, $callback) { ->willReturnCallback(function ($loader, $callback) {
return new ArrayChoiceList((array) $callback((object) ['property' => 'value'])); return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
}); });
@ -192,7 +192,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, $this->isInstanceOf('\Closure')) ->with($list, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred) { ->willReturnCallback(function ($list, $preferred) {
return new ChoiceListView((array) $preferred((object) ['property' => true])); return new ChoiceListView((array) $preferred((object) ['property' => true]));
}); });
@ -206,7 +206,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, $this->isInstanceOf('\Closure')) ->with($list, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred) { ->willReturnCallback(function ($list, $preferred) {
return new ChoiceListView((array) $preferred((object) ['property' => true])); return new ChoiceListView((array) $preferred((object) ['property' => true]));
}); });
@ -221,7 +221,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, $this->isInstanceOf('\Closure')) ->with($list, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred) { ->willReturnCallback(function ($list, $preferred) {
return new ChoiceListView((array) $preferred((object) ['category' => null])); return new ChoiceListView((array) $preferred((object) ['category' => null]));
}); });
@ -235,7 +235,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, $this->isInstanceOf('\Closure')) ->with($list, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label) { ->willReturnCallback(function ($list, $preferred, $label) {
return new ChoiceListView((array) $label((object) ['property' => 'label'])); return new ChoiceListView((array) $label((object) ['property' => 'label']));
}); });
@ -249,7 +249,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, $this->isInstanceOf('\Closure')) ->with($list, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label) { ->willReturnCallback(function ($list, $preferred, $label) {
return new ChoiceListView((array) $label((object) ['property' => 'label'])); return new ChoiceListView((array) $label((object) ['property' => 'label']));
}); });
@ -263,7 +263,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index) { ->willReturnCallback(function ($list, $preferred, $label, $index) {
return new ChoiceListView((array) $index((object) ['property' => 'index'])); return new ChoiceListView((array) $index((object) ['property' => 'index']));
}); });
@ -277,7 +277,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index) { ->willReturnCallback(function ($list, $preferred, $label, $index) {
return new ChoiceListView((array) $index((object) ['property' => 'index'])); return new ChoiceListView((array) $index((object) ['property' => 'index']));
}); });
@ -291,7 +291,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) { ->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
return new ChoiceListView((array) $groupBy((object) ['property' => 'group'])); return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
}); });
@ -305,7 +305,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) { ->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
return new ChoiceListView((array) $groupBy((object) ['property' => 'group'])); return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
}); });
@ -320,7 +320,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) { ->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
return new ChoiceListView((array) $groupBy((object) ['group' => null])); return new ChoiceListView((array) $groupBy((object) ['group' => null]));
}); });
@ -334,7 +334,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) { ->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
return new ChoiceListView((array) $attr((object) ['property' => 'attr'])); return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
}); });
@ -348,7 +348,7 @@ class PropertyAccessDecoratorTest extends TestCase
$this->decoratedFactory->expects($this->once()) $this->decoratedFactory->expects($this->once())
->method('createView') ->method('createView')
->with($list, null, null, null, null, $this->isInstanceOf('\Closure')) ->with($list, null, null, null, null, $this->isInstanceOf(\Closure::class))
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) { ->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
return new ChoiceListView((array) $attr((object) ['property' => 'attr'])); return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
}); });

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests\ChoiceList\Loader; namespace Symfony\Component\Form\Tests\ChoiceList\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\LazyChoiceList; use Symfony\Component\Form\ChoiceList\LazyChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
@ -63,7 +64,7 @@ class CallbackChoiceLoaderTest extends TestCase
public function testLoadChoiceList() public function testLoadChoiceList()
{ {
$this->assertInstanceOf('\Symfony\Component\Form\ChoiceList\ChoiceListInterface', self::$loader->loadChoiceList(self::$value)); $this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value));
} }
public function testLoadChoiceListOnlyOnce() public function testLoadChoiceListOnlyOnce()

View File

@ -227,7 +227,7 @@ class CompoundFormTest extends AbstractFormTest
public function testAddUsingNameButNoType() public function testAddUsingNameButNoType()
{ {
$this->form = $this->getBuilder('name', null, '\stdClass') $this->form = $this->getBuilder('name', null, \stdClass::class)
->setCompound(true) ->setCompound(true)
->setDataMapper($this->getDataMapper()) ->setDataMapper($this->getDataMapper())
->getForm(); ->getForm();
@ -236,7 +236,7 @@ class CompoundFormTest extends AbstractFormTest
$this->factory->expects($this->once()) $this->factory->expects($this->once())
->method('createForProperty') ->method('createForProperty')
->with('\stdClass', 'foo') ->with(\stdClass::class, 'foo')
->willReturn($child); ->willReturn($child);
$this->form->add('foo'); $this->form->add('foo');
@ -248,7 +248,7 @@ class CompoundFormTest extends AbstractFormTest
public function testAddUsingNameButNoTypeAndOptions() public function testAddUsingNameButNoTypeAndOptions()
{ {
$this->form = $this->getBuilder('name', null, '\stdClass') $this->form = $this->getBuilder('name', null, \stdClass::class)
->setCompound(true) ->setCompound(true)
->setDataMapper($this->getDataMapper()) ->setDataMapper($this->getDataMapper())
->getForm(); ->getForm();
@ -257,7 +257,7 @@ class CompoundFormTest extends AbstractFormTest
$this->factory->expects($this->once()) $this->factory->expects($this->once())
->method('createForProperty') ->method('createForProperty')
->with('\stdClass', 'foo', null, [ ->with(\stdClass::class, 'foo', null, [
'bar' => 'baz', 'bar' => 'baz',
'auto_initialize' => false, 'auto_initialize' => false,
]) ])
@ -348,7 +348,7 @@ class CompoundFormTest extends AbstractFormTest
$child = $this->getBuilder()->getForm(); $child = $this->getBuilder()->getForm();
$mapper->expects($this->once()) $mapper->expects($this->once())
->method('mapDataToForms') ->method('mapDataToForms')
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator')) ->with('bar', $this->isInstanceOf(\RecursiveIteratorIterator::class))
->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child) { ->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child) {
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator()); $this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
$this->assertSame([$child->getName() => $child], iterator_to_array($iterator)); $this->assertSame([$child->getName() => $child], iterator_to_array($iterator));
@ -438,7 +438,7 @@ class CompoundFormTest extends AbstractFormTest
$mapper->expects($this->once()) $mapper->expects($this->once())
->method('mapDataToForms') ->method('mapDataToForms')
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator')) ->with('bar', $this->isInstanceOf(\RecursiveIteratorIterator::class))
->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child1, $child2) { ->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child1, $child2) {
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator()); $this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
$this->assertSame(['firstName' => $child1, 'lastName' => $child2], iterator_to_array($iterator)); $this->assertSame(['firstName' => $child1, 'lastName' => $child2], iterator_to_array($iterator));

View File

@ -24,6 +24,6 @@ class MergeCollectionListenerArrayObjectTest extends MergeCollectionListenerTest
protected function getBuilder($name = 'name') protected function getBuilder($name = 'name')
{ {
return new FormBuilder($name, '\ArrayObject', new EventDispatcher(), (new FormFactoryBuilder())->getFormFactory()); return new FormBuilder($name, \ArrayObject::class, new EventDispatcher(), (new FormFactoryBuilder())->getFormFactory());
} }
} }

View File

@ -18,6 +18,7 @@ use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormFactoryBuilder; use Symfony\Component\Form\FormFactoryBuilder;
use Symfony\Component\Form\Util\ServerParams;
use Symfony\Component\Security\Csrf\CsrfTokenManager; use Symfony\Component\Security\Csrf\CsrfTokenManager;
class CsrfValidationListenerTest extends TestCase class CsrfValidationListenerTest extends TestCase
@ -76,7 +77,7 @@ class CsrfValidationListenerTest extends TestCase
public function testMaxPostSizeExceeded() public function testMaxPostSizeExceeded()
{ {
$serverParams = $this $serverParams = $this
->getMockBuilder('\Symfony\Component\Form\Util\ServerParams') ->getMockBuilder(ServerParams::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;

View File

@ -31,7 +31,7 @@ class GuessTest extends TestCase
public function testGuessExpectsValidConfidence() public function testGuessExpectsValidConfidence()
{ {
$this->expectException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
new TestGuess(5); new TestGuess(5);
} }
} }

View File

@ -156,7 +156,7 @@ class ResolvedFormTypeTest extends TestCase
public function testCreateBuilderWithDataClassOption() public function testCreateBuilderWithDataClassOption()
{ {
$givenOptions = ['data_class' => 'Foo']; $givenOptions = ['data_class' => 'Foo'];
$resolvedOptions = ['data_class' => '\stdClass']; $resolvedOptions = ['data_class' => \stdClass::class];
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolver')->getMock(); $optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolver')->getMock();
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType') $this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
@ -178,7 +178,7 @@ class ResolvedFormTypeTest extends TestCase
$this->assertSame($this->resolvedType, $builder->getType()); $this->assertSame($this->resolvedType, $builder->getType());
$this->assertSame($resolvedOptions, $builder->getOptions()); $this->assertSame($resolvedOptions, $builder->getOptions());
$this->assertSame('\stdClass', $builder->getDataClass()); $this->assertSame(\stdClass::class, $builder->getDataClass());
} }
public function testFailsCreateBuilderOnInvalidFormOptionsResolution() public function testFailsCreateBuilderOnInvalidFormOptionsResolution()

View File

@ -121,7 +121,7 @@ class SimpleFormTest extends AbstractFormTest
$preSetData = false; $preSetData = false;
$preSubmit = false; $preSubmit = false;
$mock = $this->getMockBuilder('\stdClass') $mock = $this->getMockBuilder(\stdClass::class)
->setMethods(['preSetData', 'preSubmit']) ->setMethods(['preSetData', 'preSubmit'])
->getMock(); ->getMock();
$mock->expects($this->once()) $mock->expects($this->once())
@ -153,7 +153,7 @@ class SimpleFormTest extends AbstractFormTest
// https://github.com/symfony/symfony/pull/7789 // https://github.com/symfony/symfony/pull/7789
public function testFalseIsConvertedToNull() public function testFalseIsConvertedToNull()
{ {
$mock = $this->getMockBuilder('\stdClass') $mock = $this->getMockBuilder(\stdClass::class)
->setMethods(['preSubmit']) ->setMethods(['preSubmit'])
->getMock(); ->getMock();
$mock->expects($this->once()) $mock->expects($this->once())
@ -394,7 +394,7 @@ class SimpleFormTest extends AbstractFormTest
public function testSetDataClonesObjectIfNotByReference() public function testSetDataClonesObjectIfNotByReference()
{ {
$data = new \stdClass(); $data = new \stdClass();
$form = $this->getBuilder('name', null, '\stdClass')->setByReference(false)->getForm(); $form = $this->getBuilder('name', null, \stdClass::class)->setByReference(false)->getForm();
$form->setData($data); $form->setData($data);
$this->assertNotSame($data, $form->getData()); $this->assertNotSame($data, $form->getData());
@ -404,7 +404,7 @@ class SimpleFormTest extends AbstractFormTest
public function testSetDataDoesNotCloneObjectIfByReference() public function testSetDataDoesNotCloneObjectIfByReference()
{ {
$data = new \stdClass(); $data = new \stdClass();
$form = $this->getBuilder('name', null, '\stdClass')->setByReference(true)->getForm(); $form = $this->getBuilder('name', null, \stdClass::class)->setByReference(true)->getForm();
$form->setData($data); $form->setData($data);
$this->assertSame($data, $form->getData()); $this->assertSame($data, $form->getData());

View File

@ -89,7 +89,7 @@ class SessionTest extends TestCase
} catch (\Exception $e) { } catch (\Exception $e) {
} }
$this->assertInstanceOf('\LogicException', $e); $this->assertInstanceOf(\LogicException::class, $e);
} }
public function testSetName() public function testSetName()

View File

@ -136,6 +136,6 @@ class MemcachedSessionHandlerTest extends TestCase
$method = new \ReflectionMethod($this->storage, 'getMemcached'); $method = new \ReflectionMethod($this->storage, 'getMemcached');
$method->setAccessible(true); $method->setAccessible(true);
$this->assertInstanceOf('\Memcached', $method->invoke($this->storage)); $this->assertInstanceOf(\Memcached::class, $method->invoke($this->storage));
} }
} }

View File

@ -298,7 +298,7 @@ class PdoSessionHandlerTest extends TestCase
$method = new \ReflectionMethod($storage, 'getConnection'); $method = new \ReflectionMethod($storage, 'getConnection');
$method->setAccessible(true); $method->setAccessible(true);
$this->assertInstanceOf('\PDO', $method->invoke($storage)); $this->assertInstanceOf(\PDO::class, $method->invoke($storage));
} }
public function testGetConnectionConnectsIfNeeded() public function testGetConnectionConnectsIfNeeded()
@ -308,7 +308,7 @@ class PdoSessionHandlerTest extends TestCase
$method = new \ReflectionMethod($storage, 'getConnection'); $method = new \ReflectionMethod($storage, 'getConnection');
$method->setAccessible(true); $method->setAccessible(true);
$this->assertInstanceOf('\PDO', $method->invoke($storage)); $this->assertInstanceOf(\PDO::class, $method->invoke($storage));
} }
/** /**

View File

@ -132,7 +132,7 @@ class ArgumentResolverTest extends TestCase
self::$resolver->getArguments($request, $controller); self::$resolver->getArguments($request, $controller);
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); $this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); $this->assertInstanceOf(\RuntimeException::class, $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
} }
} }

View File

@ -71,7 +71,7 @@ final class Intl
*/ */
public static function isExtensionLoaded(): bool public static function isExtensionLoaded(): bool
{ {
return class_exists('\ResourceBundle'); return class_exists(\ResourceBundle::class);
} }
/** /**

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Intl\Tests\Collator; namespace Symfony\Component\Intl\Tests\Collator;
use Symfony\Component\Intl\Collator\Collator; use Symfony\Component\Intl\Collator\Collator;
use Symfony\Component\Intl\Exception\MethodNotImplementedException;
use Symfony\Component\Intl\Globals\IntlGlobals; use Symfony\Component\Intl\Globals\IntlGlobals;
/** /**
@ -60,19 +61,19 @@ class CollatorTest extends AbstractCollatorTest
public function testConstructWithoutLocale() public function testConstructWithoutLocale()
{ {
$collator = $this->getCollator(null); $collator = $this->getCollator(null);
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator); $this->assertInstanceOf(Collator::class, $collator);
} }
public function testGetSortKey() public function testGetSortKey()
{ {
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException'); $this->expectException(MethodNotImplementedException::class);
$collator = $this->getCollator('en'); $collator = $this->getCollator('en');
$collator->getSortKey('Hello'); $collator->getSortKey('Hello');
} }
public function testGetStrength() public function testGetStrength()
{ {
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException'); $this->expectException(MethodNotImplementedException::class);
$collator = $this->getCollator('en'); $collator = $this->getCollator('en');
$collator->getStrength(); $collator->getStrength();
} }
@ -95,7 +96,7 @@ class CollatorTest extends AbstractCollatorTest
{ {
$collator = $this->getCollator('en'); $collator = $this->getCollator('en');
$collator = $collator::create('en'); $collator = $collator::create('en');
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator); $this->assertInstanceOf(Collator::class, $collator);
} }
protected function getCollator(?string $locale): Collator protected function getCollator(?string $locale): Collator

View File

@ -34,7 +34,7 @@ class IntlBundleReaderTest extends TestCase
{ {
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro'); $data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro');
$this->assertInstanceOf('\ArrayAccess', $data); $this->assertInstanceOf(\ArrayAccess::class, $data);
$this->assertSame('Bar', $data['Foo']); $this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data); $this->assertArrayNotHasKey('ExistsNot', $data);
} }
@ -44,7 +44,7 @@ class IntlBundleReaderTest extends TestCase
// "alias" = "ro" // "alias" = "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'alias'); $data = $this->reader->read(__DIR__.'/Fixtures/res', 'alias');
$this->assertInstanceOf('\ArrayAccess', $data); $this->assertInstanceOf(\ArrayAccess::class, $data);
$this->assertSame('Bar', $data['Foo']); $this->assertSame('Bar', $data['Foo']);
$this->assertArrayNotHasKey('ExistsNot', $data); $this->assertArrayNotHasKey('ExistsNot', $data);
} }
@ -54,7 +54,7 @@ class IntlBundleReaderTest extends TestCase
// "ro_MD" -> "ro" // "ro_MD" -> "ro"
$data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD'); $data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD');
$this->assertInstanceOf('\ArrayAccess', $data); $this->assertInstanceOf(\ArrayAccess::class, $data);
$this->assertSame('Bam', $data['Baz']); $this->assertSame('Bam', $data['Baz']);
$this->assertArrayNotHasKey('Foo', $data); $this->assertArrayNotHasKey('Foo', $data);
$this->assertNull($data['Foo']); $this->assertNull($data['Foo']);

View File

@ -47,7 +47,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
{ {
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT); $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
$formatter = $formatter::create('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT); $formatter = $formatter::create('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
$this->assertInstanceOf('\Symfony\Component\Intl\DateFormatter\IntlDateFormatter', $formatter); $this->assertInstanceOf(IntlDateFormatter::class, $formatter);
} }
public function testFormatWithUnsupportedTimestampArgument() public function testFormatWithUnsupportedTimestampArgument()

View File

@ -56,10 +56,7 @@ class NumberFormatterTest extends AbstractNumberFormatterTest
public function testConstructWithoutLocale() public function testConstructWithoutLocale()
{ {
$this->assertInstanceOf( $this->assertInstanceOf(NumberFormatter::class, $this->getNumberFormatter(null, NumberFormatter::DECIMAL));
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
$this->getNumberFormatter(null, NumberFormatter::DECIMAL)
);
} }
public function testCreate() public function testCreate()

View File

@ -29,7 +29,7 @@ class NumberFormatterTest extends AbstractNumberFormatterTest
public function testCreate() public function testCreate()
{ {
$this->assertInstanceOf('\NumberFormatter', \NumberFormatter::create('en', \NumberFormatter::DECIMAL)); $this->assertInstanceOf(\NumberFormatter::class, \NumberFormatter::create('en', \NumberFormatter::DECIMAL));
} }
public function testGetTextAttribute() public function testGetTextAttribute()

View File

@ -60,7 +60,7 @@ trait ExpiringStoreTestTrait
*/ */
public function testAbortAfterExpiration() public function testAbortAfterExpiration()
{ {
$this->expectException('\Symfony\Component\Lock\Exception\LockExpiredException'); $this->expectException(LockExpiredException::class);
$key = new Key(uniqid(__METHOD__, true)); $key = new Key(uniqid(__METHOD__, true));
/** @var PersistingStoreInterface $store */ /** @var PersistingStoreInterface $store */

View File

@ -57,7 +57,7 @@ abstract class AbstractMimeTypeGuesserTest extends TestCase
$this->markTestSkipped('Guesser is not supported'); $this->markTestSkipped('Guesser is not supported');
} }
$this->expectException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->getGuesser()->guessMimeType(__DIR__.'/Fixtures/mimetypes/directory'); $this->getGuesser()->guessMimeType(__DIR__.'/Fixtures/mimetypes/directory');
} }
@ -94,7 +94,7 @@ abstract class AbstractMimeTypeGuesserTest extends TestCase
$this->markTestSkipped('Guesser is not supported'); $this->markTestSkipped('Guesser is not supported');
} }
$this->expectException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->getGuesser()->guessMimeType(__DIR__.'/Fixtures/mimetypes/not_here'); $this->getGuesser()->guessMimeType(__DIR__.'/Fixtures/mimetypes/not_here');
} }

View File

@ -66,7 +66,7 @@ class RouteCollectionTest extends TestCase
$collection->addCollection($collection1); $collection->addCollection($collection1);
$collection->add('last', $last = new Route('/last')); $collection->add('last', $last = new Route('/last'));
$this->assertInstanceOf('\ArrayIterator', $collection->getIterator()); $this->assertInstanceOf(\ArrayIterator::class, $collection->getIterator());
$this->assertSame(['bar' => $bar, 'foo' => $foo, 'last' => $last], $collection->getIterator()->getArrayCopy()); $this->assertSame(['bar' => $bar, 'foo' => $foo, 'last' => $last], $collection->getIterator()->getArrayCopy());
} }

View File

@ -13,6 +13,8 @@ namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute;
use Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler;
class RouteTest extends TestCase class RouteTest extends TestCase
{ {
@ -266,13 +268,13 @@ class RouteTest extends TestCase
*/ */
public function testSerializeWhenCompiledWithClass() public function testSerializeWhenCompiledWithClass()
{ {
$route = new Route('/', [], [], ['compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler']); $route = new Route('/', [], [], ['compiler_class' => CustomRouteCompiler::class]);
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $route->compile(), '->compile() returned a proper route'); $this->assertInstanceOf(CustomCompiledRoute::class, $route->compile(), '->compile() returned a proper route');
$serialized = serialize($route); $serialized = serialize($route);
try { try {
$unserialized = unserialize($serialized); $unserialized = unserialize($serialized);
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully'); $this->assertInstanceOf(CustomCompiledRoute::class, $unserialized->compile(), 'the unserialized route compiled successfully');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->fail('unserializing a route which uses a custom compiled route class'); $this->fail('unserializing a route which uses a custom compiled route class');
} }

View File

@ -89,7 +89,7 @@ class AbstractTokenTest extends TestCase
$token->getAttribute('foobar'); $token->getAttribute('foobar');
$this->fail('->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); $this->fail('->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
$this->assertEquals('This token has no "foobar" attribute.', $e->getMessage(), '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); $this->assertEquals('This token has no "foobar" attribute.', $e->getMessage(), '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
} }
} }

View File

@ -13,12 +13,14 @@ namespace Symfony\Component\Security\Http\Tests\Firewall;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Firewall\RememberMeListener; use Symfony\Component\Security\Http\Firewall\RememberMeListener;
use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class RememberMeListenerTest extends TestCase class RememberMeListenerTest extends TestCase
@ -227,7 +229,7 @@ class RememberMeListenerTest extends TestCase
->willReturn($token) ->willReturn($token)
; ;
$session = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock(); $session = $this->getMockBuilder(SessionInterface::class)->getMock();
$session $session
->expects($this->once()) ->expects($this->once())
->method('isStarted') ->method('isStarted')
@ -277,7 +279,7 @@ class RememberMeListenerTest extends TestCase
->willReturn($token) ->willReturn($token)
; ;
$session = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock(); $session = $this->getMockBuilder(SessionInterface::class)->getMock();
$session $session
->expects($this->once()) ->expects($this->once())
->method('isStarted') ->method('isStarted')
@ -402,6 +404,6 @@ class RememberMeListenerTest extends TestCase
private function getSessionStrategy() private function getSessionStrategy()
{ {
return $this->getMockBuilder('\Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(); return $this->getMockBuilder(SessionAuthenticationStrategyInterface::class)->getMock();
} }
} }

View File

@ -863,7 +863,7 @@ XML;
*/ */
private function createMockDateTimeNormalizer(): object private function createMockDateTimeNormalizer(): object
{ {
$mock = $this->getMockBuilder('\Symfony\Component\Serializer\Normalizer\CustomNormalizer')->getMock(); $mock = $this->getMockBuilder(CustomNormalizer::class)->getMock();
$mock $mock
->expects($this->once()) ->expects($this->once())

View File

@ -232,7 +232,7 @@ class SerializerTest extends TestCase
{ {
$serializer = new Serializer([new GetSetMethodNormalizer()], ['json' => new JsonEncoder()]); $serializer = new Serializer([new GetSetMethodNormalizer()], ['json' => new JsonEncoder()]);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$result = $serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $result = $serializer->deserialize(json_encode($data), Model::class, 'json');
$this->assertEquals($data, $result->toArray()); $this->assertEquals($data, $result->toArray());
} }
@ -240,9 +240,9 @@ class SerializerTest extends TestCase
{ {
$serializer = new Serializer([new GetSetMethodNormalizer()], ['json' => new JsonEncoder()]); $serializer = new Serializer([new GetSetMethodNormalizer()], ['json' => new JsonEncoder()]);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $serializer->deserialize(json_encode($data), Model::class, 'json');
$data = ['title' => 'bar', 'numbers' => [2, 8]]; $data = ['title' => 'bar', 'numbers' => [2, 8]];
$result = $serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $result = $serializer->deserialize(json_encode($data), Model::class, 'json');
$this->assertEquals($data, $result->toArray()); $this->assertEquals($data, $result->toArray());
} }
@ -251,7 +251,7 @@ class SerializerTest extends TestCase
$this->expectException('Symfony\Component\Serializer\Exception\LogicException'); $this->expectException('Symfony\Component\Serializer\Exception\LogicException');
$serializer = new Serializer([], ['json' => new JsonEncoder()]); $serializer = new Serializer([], ['json' => new JsonEncoder()]);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $serializer->deserialize(json_encode($data), Model::class, 'json');
} }
public function testDeserializeWrongNormalizer() public function testDeserializeWrongNormalizer()
@ -259,7 +259,7 @@ class SerializerTest extends TestCase
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException'); $this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');
$serializer = new Serializer([new CustomNormalizer()], ['json' => new JsonEncoder()]); $serializer = new Serializer([new CustomNormalizer()], ['json' => new JsonEncoder()]);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $serializer->deserialize(json_encode($data), Model::class, 'json');
} }
public function testDeserializeNoEncoder() public function testDeserializeNoEncoder()
@ -267,14 +267,14 @@ class SerializerTest extends TestCase
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException'); $this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');
$serializer = new Serializer([], []); $serializer = new Serializer([], []);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$serializer->deserialize(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json'); $serializer->deserialize(json_encode($data), Model::class, 'json');
} }
public function testDeserializeSupported() public function testDeserializeSupported()
{ {
$serializer = new Serializer([new GetSetMethodNormalizer()], []); $serializer = new Serializer([new GetSetMethodNormalizer()], []);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$this->assertTrue($serializer->supportsDenormalization(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json')); $this->assertTrue($serializer->supportsDenormalization(json_encode($data), Model::class, 'json'));
} }
public function testDeserializeNotSupported() public function testDeserializeNotSupported()
@ -288,7 +288,7 @@ class SerializerTest extends TestCase
{ {
$serializer = new Serializer([], []); $serializer = new Serializer([], []);
$data = ['title' => 'foo', 'numbers' => [5, 3]]; $data = ['title' => 'foo', 'numbers' => [5, 3]];
$this->assertFalse($serializer->supportsDenormalization(json_encode($data), '\Symfony\Component\Serializer\Tests\Model', 'json')); $this->assertFalse($serializer->supportsDenormalization(json_encode($data), Model::class, 'json'));
} }
public function testEncode() public function testEncode()

View File

@ -66,7 +66,7 @@ class SlotsHelperTest extends TestCase
$this->fail('->start() throws an InvalidArgumentException if a slot with the same name is already started'); $this->fail('->start() throws an InvalidArgumentException if a slot with the same name is already started');
} catch (\Exception $e) { } catch (\Exception $e) {
$helper->stop(); $helper->stop();
$this->assertInstanceOf('\InvalidArgumentException', $e, '->start() throws an InvalidArgumentException if a slot with the same name is already started'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->start() throws an InvalidArgumentException if a slot with the same name is already started');
$this->assertEquals('A slot named "bar" is already started.', $e->getMessage(), '->start() throws an InvalidArgumentException if a slot with the same name is already started'); $this->assertEquals('A slot named "bar" is already started.', $e->getMessage(), '->start() throws an InvalidArgumentException if a slot with the same name is already started');
} }
@ -74,7 +74,7 @@ class SlotsHelperTest extends TestCase
$helper->stop(); $helper->stop();
$this->fail('->stop() throws an LogicException if no slot is started'); $this->fail('->stop() throws an LogicException if no slot is started');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->stop() throws an LogicException if no slot is started'); $this->assertInstanceOf(\LogicException::class, $e, '->stop() throws an LogicException if no slot is started');
$this->assertEquals('No slot started.', $e->getMessage(), '->stop() throws an LogicException if no slot is started'); $this->assertEquals('No slot started.', $e->getMessage(), '->stop() throws an LogicException if no slot is started');
} }
} }

View File

@ -51,7 +51,7 @@ class PhpEngineTest extends TestCase
$engine['bar']; $engine['bar'];
$this->fail('->offsetGet() throws an InvalidArgumentException if the helper is not defined'); $this->fail('->offsetGet() throws an InvalidArgumentException if the helper is not defined');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->offsetGet() throws an InvalidArgumentException if the helper is not defined'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->offsetGet() throws an InvalidArgumentException if the helper is not defined');
$this->assertEquals('The helper "bar" is not defined.', $e->getMessage(), '->offsetGet() throws an InvalidArgumentException if the helper is not defined'); $this->assertEquals('The helper "bar" is not defined.', $e->getMessage(), '->offsetGet() throws an InvalidArgumentException if the helper is not defined');
} }
} }
@ -72,7 +72,7 @@ class PhpEngineTest extends TestCase
$engine->get('foobar'); $engine->get('foobar');
$this->fail('->get() throws an InvalidArgumentException if the helper is not defined'); $this->fail('->get() throws an InvalidArgumentException if the helper is not defined');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an InvalidArgumentException if the helper is not defined'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws an InvalidArgumentException if the helper is not defined');
$this->assertEquals('The helper "foobar" is not defined.', $e->getMessage(), '->get() throws an InvalidArgumentException if the helper is not defined'); $this->assertEquals('The helper "foobar" is not defined.', $e->getMessage(), '->get() throws an InvalidArgumentException if the helper is not defined');
} }
@ -87,7 +87,7 @@ class PhpEngineTest extends TestCase
$foo = new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('foo'); $foo = new \Symfony\Component\Templating\Tests\Fixtures\SimpleHelper('foo');
$engine->set($foo); $engine->set($foo);
$this->expectException('\LogicException'); $this->expectException(\LogicException::class);
unset($engine['foo']); unset($engine['foo']);
} }
@ -99,7 +99,7 @@ class PhpEngineTest extends TestCase
$engine->render('name'); $engine->render('name');
$this->fail('->render() throws an InvalidArgumentException if the template does not exist'); $this->fail('->render() throws an InvalidArgumentException if the template does not exist');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->render() throws an InvalidArgumentException if the template does not exist'); $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->render() throws an InvalidArgumentException if the template does not exist');
$this->assertEquals('The template "name" does not exist.', $e->getMessage(), '->render() throws an InvalidArgumentException if the template does not exist'); $this->assertEquals('The template "name" does not exist.', $e->getMessage(), '->render() throws an InvalidArgumentException if the template does not exist');
} }

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Validator\Constraints; namespace Symfony\Component\Validator\Constraints;
use Egulias\EmailValidator\EmailValidator as EguliasEmailValidator;
use Egulias\EmailValidator\Validation\EmailValidation; use Egulias\EmailValidator\Validation\EmailValidation;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
@ -77,7 +78,7 @@ class EmailValidator extends ConstraintValidator
} }
if (Email::VALIDATION_MODE_STRICT === $constraint->mode) { if (Email::VALIDATION_MODE_STRICT === $constraint->mode) {
$strictValidator = new \Egulias\EmailValidator\EmailValidator(); $strictValidator = new EguliasEmailValidator();
if (interface_exists(EmailValidation::class) && !$strictValidator->isValid($value, new NoRFCWarningsValidation())) { if (interface_exists(EmailValidation::class) && !$strictValidator->isValid($value, new NoRFCWarningsValidation())) {
$this->context->buildViolation($constraint->message) $this->context->buildViolation($constraint->message)

View File

@ -116,7 +116,7 @@ class XmlFileLoaderTest extends TestCase
$loader = new XmlFileLoader(__DIR__.'/withdoctype.xml'); $loader = new XmlFileLoader(__DIR__.'/withdoctype.xml');
$metadata = new ClassMetadata(Entity::class); $metadata = new ClassMetadata(Entity::class);
$this->expectException('\Symfony\Component\Validator\Exception\MappingException'); $this->expectException(MappingException::class);
$loader->loadClassMetadata($metadata); $loader->loadClassMetadata($metadata);
} }
@ -131,7 +131,7 @@ class XmlFileLoaderTest extends TestCase
try { try {
$loader->loadClassMetadata($metadata); $loader->loadClassMetadata($metadata);
} catch (MappingException $e) { } catch (MappingException $e) {
$this->expectException('\Symfony\Component\Validator\Exception\MappingException'); $this->expectException(MappingException::class);
$loader->loadClassMetadata($metadata); $loader->loadClassMetadata($metadata);
} }
} }

View File

@ -71,7 +71,7 @@ class YamlFileLoaderTest extends TestCase
$loader->loadClassMetadata($metadata); $loader->loadClassMetadata($metadata);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
// Call again. Again an exception should be thrown // Call again. Again an exception should be thrown
$this->expectException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$loader->loadClassMetadata($metadata); $loader->loadClassMetadata($metadata);
} }
} }
@ -87,7 +87,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadClassMetadataReturnsFalseIfNotSuccessful() public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
{ {
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml'); $loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
$metadata = new ClassMetadata('\stdClass'); $metadata = new ClassMetadata(\stdClass::class);
$this->assertFalse($loader->loadClassMetadata($metadata)); $this->assertFalse($loader->loadClassMetadata($metadata));
} }

View File

@ -68,7 +68,7 @@ class ParserTest extends TestCase
$this->fail('YAML files must not contain tabs'); $this->fail('YAML files must not contain tabs');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, 'YAML files must not contain tabs'); $this->assertInstanceOf(\Exception::class, $e, 'YAML files must not contain tabs');
$this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs'); $this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs');
} }
} }
@ -1414,7 +1414,7 @@ EOT;
*/ */
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml) public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
{ {
$this->expectException('\Symfony\Component\Yaml\Exception\ParseException'); $this->expectException(ParseException::class);
$this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)); $this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));
$this->parser->parse($yaml); $this->parser->parse($yaml);