8000 Use ::class keyword when possible · symfony/symfony@036a36c · GitHub
[go: up one dir, main page]

Skip to content

Commit 036a36c

Browse files
committed
Use ::class keyword when possible
1 parent 220cedf commit 036a36c

File tree

64 files changed

+175
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+175
-155
lines changed

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
2222
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
2323
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
24+
use Symfony\Component\Security\Core\User\UserInterface;
2425

2526
class EntityUserProviderTest extends TestCase
2627
{
@@ -154,7 +155,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
154155
->method('loadUserByUsername')
155156
->with('name')
156157
->willReturn(
157-
$this->getMockBuilder('\Symfony\Component\Security\Core\User\UserInterface')->getMock()
158+
$this->getMockBuilder(UserInterface::class)->getMock()
158159
);
159160

160161
$provider = new EntityUserProvider(

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
require_once __DIR__.'/Fixtures/includes/foo.php';
1515

1616
use PHPUnit\Framework\TestCase;
17+
use ProxyManager\Proxy\LazyLoadingInterface;
18+
use ProxyManagerBridgeFooClass;
1719
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1820
use Symfony\Component\DependencyInjection\ContainerBuilder;
1921

@@ -31,7 +33,7 @@ public function testCreateProxyServiceWithRuntimeInstantiator()
3133

3234
$builder->setProxyInstantiator(new RuntimeInstantiator());
3335

34-
$builder->register('foo1', 'ProxyManagerBridgeFooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php')->setPublic(true);
36+
$builder->register('foo1', ProxyManagerBridgeFooClass::class)->setFile(__DIR__.'/Fixtures/includes/foo.php')->setPublic(true);
3537
$builder->getDefinition('foo1')->setLazy(true);
3638

3739
$builder->compile();
@@ -43,16 +45,16 @@ public function testCreateProxyServiceWithRuntimeInstantiator()
4345
$this->assertSame(0, $foo1::$destructorCount);
4446

4547
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls');
46-
$this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1);
47-
$this->assertInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1);
48+
$this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1);
49+
$this->assertInstanceOf(LazyLoadingInterface::class, $foo1);
4850
$this->assertFalse($foo1->isProxyInitialized());
4951

5052
$foo1->initializeProxy();
5153

5254
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization');
5355
$this->assertTrue($foo1->isProxyInitialized());
54-
$this->assertInstanceOf('\ProxyManagerBridgeFooClass', $foo1->getWrappedValueHolderValue());
55-
$this->assertNotInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface', $foo1->getWrappedValueHolderValue());
56+
$this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1->getWrappedValueHolderValue());
57+
$this->assertNotInstanceOf(LazyLoadingInterface::class, $foo1->getWrappedValueHolderValue());
5658

5759
$foo1->__destruct();
5860
$this->assertSame(1, $foo1::$destructorCount);

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testParse()
5151
$parser->parse('foo:');
5252
$this->fail('->parse() throws an \InvalidArgumentException if the controller is not an a:b:c string');
5353
} catch (\Exception $e) {
54-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException if the controller is not an a:b:c string');
54+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws an \InvalidArgumentException if the controller is not an a:b:c string');
5555
}
5656
}
5757

@@ -66,21 +66,21 @@ public function testBuild()
6666
$parser->build('TestBundle\FooBundle\Controller\DefaultController::index');
6767
$this->fail('->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
6868
} catch (\Exception $e) {
69-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
69+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
7070
}
7171

7272
try {
7373
$parser->build('TestBundle\FooBundle\Controller\Default::indexAction');
7474
$this->fail('->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
7575
} catch (\Exception $e) {
76-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
76+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
7777
}
7878

7979
try {
8080
$parser->build('Foo\Controller\DefaultController::indexAction');
8181
$this->fail('->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
8282
} catch (\Exception $e) {
83-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
83+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws an \InvalidArgumentException if the controller is not an aController::cAction string');
8484
}
8585
}
8686

@@ -95,7 +95,7 @@ public function testMissingControllers($name)
9595
$parser->parse($name);
9696
$this->fail('->parse() throws a \InvalidArgumentException if the class is found but does not exist');
9797
} catch (\Exception $e) {
98-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws a \InvalidArgumentException if the class is found but does not exist');
98+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws a \InvalidArgumentException if the class is found but does not exist');
9999
}
100100
}
101101

@@ -125,7 +125,7 @@ public function testInvalidBundleName($bundleName, $suggestedBundleName)
125125
$parser->parse($bundleName);
126126
$this->fail('->parse() throws a \InvalidArgumentException if the bundle does not exist');
127127
} catch (\Exception $e) {
128-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws a \InvalidArgumentException if the bundle does not exist');
128+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->parse() throws a \InvalidArgumentException if the bundle does not exist');
129129

130130
if (false === $suggestedBundleName) {
131131
// make sure we don't have a suggestion

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testTransWithCachingWithInvalidLocale()
140140
$this->expectException('InvalidArgumentException');
141141
$this->expectExceptionMessage('Invalid "invalid locale" locale.');
142142
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
143-
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir], 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale');
143+
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir], 'loader', TranslatorWithInvalidLocale::class);
144144

145145
$translator->trans('foo');
146146
}
@@ -346,7 +346,7 @@ protected function getContainer($loader)
346346
return $container;
347347
}
348348

349-
public function getTranslator($loader, $options = [], $loaderFomat = 'loader', $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $defaultLocale = 'en')
349+
public function getTranslator($loader, $options = [], $loaderFomat = 'loader', $translatorClass = Translator::class, $defaultLocale = 'en')
350350
{
351351
$translator = $this->createTranslator($loader, $options, $translatorClass, $loaderFomat, $defaultLocale);
352352

@@ -403,7 +403,7 @@ public function testLoadingTranslationFilesWithDotsInMessageDomain()
403403
$this->assertEquals('It works!', $translator->trans('message', [], 'domain.with.dots'));
404404
}
405405

406-
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader', $defaultLocale = 'en')
406+
private function createTranslator($loader, $options, $translatorClass = Translator::class, $loaderFomat = 'loader', $defaultLocale = 'en')
407407
{
408408
if (null === $defaultLocale) {
409409
return new $translatorClass(

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function testEncodePasswordSodiumOutput()
258258

259259
public function testEncodePasswordNoConfigForGivenUserClass()
260260
{
261-
$this->expectException('\RuntimeException');
261+
$this->expectException(\RuntimeException::class);
262262
$this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".');
263263

264264
$this->passwordEncoderCommandTester->execute([

src/Symfony/Bundle/TwigBundle/Tests/Controller/PreviewErrorControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testForwardRequestToConfiguredController()
3030
$code = 123;
3131
$logicalControllerName = 'foo:bar:baz';
3232

33-
$kernel = $this->getMockBuilder('\Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
33+
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
3434
$kernel
3535
->expects($this->once())
3636
->method('handle')

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Twig\AppVariable;
1516
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
17+
use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader;
1618
use Symfony\Bundle\TwigBundle\TemplateIterator;
19+
use Symfony\Bundle\TwigBundle\TwigEngine;
1720
use Symfony\Component\DependencyInjection\ContainerBuilder;
1821
use Symfony\Component\DependencyInjection\Definition;
22+
use Twig\Loader\FilesystemLoader as TwigFilesystemLoader;
1923

2024
class ExtensionPassTest extends TestCase
2125
{
@@ -24,17 +28,17 @@ public function testProcessDoesNotDropExistingFileLoaderMethodCalls()
2428
$container = new ContainerBuilder();
2529
$container->setParameter('kernel.debug', false);
2630

27-
$container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable');
28-
$container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine');
31+
$container->register('twig.app_variable', AppVariable::class);
32+
$container->register('templating', TwigEngine::class);
2933
$container->register('twig.extension.yaml');
3034
$container->register('twig.extension.debug.stopwatch');
3135
$container->register('twig.extension.expression');
3236

33-
$nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader');
37+
$nativeTwigLoader = new Definition(TwigFilesystemLoader::class);
3438
$nativeTwigLoader->addMethodCall('addPath', []);
3539
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);
3640

37-
$filesystemLoader = new Definition('\Symfony\Bundle\TwigBundle\Loader\FilesystemLoader');
41+
$filesystemLoader = new Definition(FilesystemLoader::class);
3842
$filesystemLoader->setArguments([null, null, null]);
3943
$filesystemLoader->addMethodCall('addPath', []);
4044
$container->setDefinition('twig.loader.filesystem', $filesystemLoader);

src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testMultiPartRequestWithSingleFile()
7373
->method('request')
7474
->with('POST', 'http://example.com/', $this->callback(function ($options) {
7575
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
76-
$this->assertInstanceOf('\Generator', $options['body']);
76+
$this->assertInstanceOf(\Generator::class, $options['body']);
7777
$this->assertStringContainsString('my_file', implode('', iterator_to_array($options['body'])));
7878

7979
return true;
@@ -183,7 +183,7 @@ protected function expectClientToSendRequestWithFiles(HttpClientInterface $clien
183183
->method('request')
184184
->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) {
185185
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
186-
$this->assertInstanceOf('\Generator', $options['body']);
186+
$this->assertInstanceOf(\Generator::class, $options['body']);
187187
$body = implode('', iterator_to_array($options['body'], false));
188188
foreach ($fileContents as $content) {
189189
$this->assertStringContainsString($content, $body);
@@ -201,7 +201,7 @@ protected function expectClientToNotSendRequestWithFiles(HttpClientInterface $cl
201201
->method('request')
202202
->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) {
203203
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
204-
$this->assertInstanceOf('\Generator', $options['body']);
204+
$this->assertInstanceOf(\Generator::class, $options['body']);
205205
$body = implode('', iterator_to_array($options['body'], false));
206206
foreach ($fileContents as $content) {
207207
$this->assertStringNotContainsString($content, $body);

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testDsnWithOptions(string $dsn, array $options, array $expectedO
186186

187187
public function provideDsnWithOptions(): iterable
188188
{
189-
if (!class_exists('\Memcached')) {
189+
if (!class_exists(\Memcached::class)) {
190190
self::markTestSkipped('Extension memcached required.');
191191
}
192192

src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Resource\FileResource;
1616
use Symfony\Component\Config\ResourceCheckerConfigCache;
17+
use Symfony\Component\Config\ResourceCheckerInterface;
1718
use Symfony\Component\Config\Tests\Resource\ResourceStub;
1819

1920
class ResourceCheckerConfigCacheTest extends TestCase
@@ -45,7 +46,7 @@ public function testGetPath()
4546

4647
public function testCacheIsNotFreshIfEmpty()
4748
{
48-
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock()
49+
$checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock()
4950
->expects($this->never())->method('supports');
5051

5152
/* If there is nothing in the cache, it needs to be filled (and thus it's not fresh).
@@ -82,7 +83,7 @@ public function testResourcesWithoutcheckersAreIgnoredAndConsideredFresh()
8283

8384
public function testIsFreshWithchecker()
8485
{
85-
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
86+
$checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
8687

8788
$checker->expects($this->once())
8889
->method('supports')
@@ -100,7 +101,7 @@ public function testIsFreshWithchecker()
100101

101102
public function testIsNotFreshWithchecker()
102103
{
103-
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
104+
$checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
104105

105106
$checker->expects($this->once())
106107
->method('supports')
@@ -118,7 +119,7 @@ public function testIsNotFreshWithchecker()
118119

119120
public function testCacheIsNotFreshWhenUnserializeFails()
120121
{
121-
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
122+
$checker = $this->getMockBuilder(ResourceCheckerInterface::class)->getMock();
122123
$cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]);
123124
$cache->write('foo', [new FileResource(__FILE__)]);
124125

@@ -138,7 +139,8 @@ public function testCacheKeepsContent()
138139

139140
public function testCacheIsNotFreshIfNotExistsMetaFile()
140141
{
141-
$checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock();
142+
$checker = $this->getMockBuilder(ResourceCheckerInterface::class
143+
)->getMock();
142144
$cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]);
143145
$cache->write('foo', [new FileResource(__FILE__)]);
144146

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ public function testSetCatchExceptions()
777777
$tester->run(['command' => 'foo'], ['decorated' => false]);
778778
$this->fail('->setCatchExceptions() sets the catch exception flag');
779779
} catch (\Exception $e) {
780-
$this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
780+
$this->assertInstanceOf(\Exception::class, $e, '->setCatchExceptions() sets the catch exception flag');
781781
$this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
782782
}
783783
}

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ public function testOptions()
8585
$style->setOption('foo');
8686
$this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
8787
} catch (\Exception $e) {
88-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
88+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
8989
$this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
9090
}
9191

9292
try {
9393
$style->unsetOption('foo');
9494
$this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
9595
} catch (\Exception $e) {
96-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
96+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
9797
$this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
9898
}
9999
}

src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\HelperInterface;
1617
use Symfony\Component\Console\Helper\HelperSet;
1718

1819
class HelperSetTest extends TestCase
@@ -66,7 +67,7 @@ public function testGet()
6667
$helperset->get('foo');
6768
$this->fail('->get() throws InvalidArgumentException when helper not found');
6869
} catch (\Exception $e) {
69-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws InvalidArgumentException when helper not found');
70+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found');
7071
$this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found');
7172
$this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found');
7273
}
@@ -111,7 +112,7 @@ public function testIteration()
111112

112113
private function getGenericMockHelper($name, HelperSet $helperset = null)
113114
{
114-
$mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock();
115+
$mock_helper = $this->getMockBuilder(HelperInterface::class)->getMock();
115116
$mock_helper->expects($this->any())
116117
->method('getName')
117118
->willReturn($name);

0 commit comments

Comments
 (0)
0