Skip to content

Commit 84ce026

Browse files
committed
minor #39783 Use ::class keyword when possible (fabpot)
This PR was merged into the 5.2 branch. Discussion ---------- Use ::class keyword when possible | Q | A | ------------- | --- | Branch? | 5.2 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Commits ------- 2922224 Use ::class keyword when possible
2 parents b145df9 + 2922224 commit 84ce026

File tree

21 files changed

+160
-160
lines changed

21 files changed

+160
-160
lines changed

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testFilterUid($entityClass)
160160

161161
$em = DoctrineTestHelper::createTestEntityManager();
162162

163-
$query = $this->getMockBuilder('QueryMock')
163+
$query = $this->getMockBuilder(\QueryMock::class)
164164
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
165165
->getMock();
166166

@@ -173,7 +173,7 @@ public function testFilterUid($entityClass)
173173
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()], Connection::PARAM_STR_ARRAY)
174174
->willReturn($query);
175175

176-
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
176+
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
177177
->setConstructorArgs([$em])
178178
->setMethods(['getQuery'])
179179
->getMock();
@@ -205,7 +205,7 @@ public function testUidThrowProperException($entityClass)
205205

206206
$em = DoctrineTestHelper::createTestEntityManager();
207207

208-
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
208+
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
209209
->setConstructorArgs([$em])
210210
->setMethods(['getQuery'])
211211
->getMock();

src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
2828
*/
2929
public function testTypeGuesser(string $type, $expected)
3030
{
31-
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
31+
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
3232
$classMetadata->fieldMappings['field'] = true;
3333
$classMetadata->expects($this->once())->method('getTypeOfField')->with('field')->willReturn($type);
3434

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgno
300300
{
301301
$entity1 = new SingleIntIdEntity(1, null);
302302

303-
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
303+
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
304304
$this->validator->validate($entity1, $constraint);
305305
}
306306

@@ -616,7 +616,7 @@ public function testValidateUniquenessWithArrayValue()
616616

617617
public function testDedicatedEntityManagerNullObject()
618618
{
619-
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
619+
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
620620
$this->expectExceptionMessage('Object manager "foo" does not exist.');
621621
$constraint = new UniqueEntity([
622622
'message' => 'myMessage',
@@ -636,7 +636,7 @@ public function testDedicatedEntityManagerNullObject()
636636

637637
public function testEntityManagerNullObject()
638638
{
639-
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
639+
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
640640
$this->expectExceptionMessage('Unable to find the object manager associated with an entity of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity"');
641641
$constraint = new UniqueEntity([
642642
'message' => 'myMessage',
@@ -718,7 +718,7 @@ public function testValidateInheritanceUniqueness()
718718

719719
public function testInvalidateRepositoryForInheritance()
720720
{
721-
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
721+
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
722722
$this->expectExceptionMessage('The "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity" entity repository does not support the "Symfony\Bridge\Doctrine\Tests\Fixtures\Person" entity. The entity should be an instance of or extend "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity".');
723723
$constraint = new UniqueEntity([
724724
'message' => 'myMessage',

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public function testIsActivatedLegacy($url, $record, $expected)
6565

6666
public function testExclusionsWithoutCode()
6767
{
68-
$this->expectException('LogicException');
68+
$this->expectException(\LogicException::class);
6969
new HttpCodeActivationStrategy(new RequestStack(), [['urls' => []]], new ErrorLevelActivationStrategy(Logger::WARNING));
7070
}
7171

7272
public function testExclusionsWithoutUrls()
7373
{
74-
$this->expectException('LogicException');
74+
$this->expectException(\LogicException::class);
7575
new HttpCodeActivationStrategy(new RequestStack(), [['code' => 404]], new ErrorLevelActivationStrategy(Logger::WARNING));
7676
}
7777

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function testPropertyAccessCacheWithDebug()
137137

138138
public function testCsrfProtectionNeedsSessionToBeEnabled()
139139
{
140-
$this->expectException('LogicException');
140+
$this->expectException(\LogicException::class);
141141
$this->expectExceptionMessage('CSRF protection needs sessions to be enabled.');
142142
$this->createContainerFromFile('csrf_needs_session');
143143
}
@@ -317,21 +317,21 @@ public function testWorkflows()
317317

318318
public function testWorkflowAreValidated()
319319
{
320-
$this->expectException('Symfony\Component\Workflow\Exception\InvalidDefinitionException');
320+
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
321321
$this->expectExceptionMessage('A transition from a place/state must have an unique name. Multiple transitions named "go" from place/state "first" were found on StateMachine "my_workflow".');
322322
$this->createContainerFromFile('workflow_not_valid');
323323
}
324324

325325
public function testWorkflowCannotHaveBothSupportsAndSupportStrategy()
326326
{
327-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
327+
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
328328
$this->expectExceptionMessage('"supports" and "support_strategy" cannot be used together.');
329329
$this->createContainerFromFile('workflow_with_support_and_support_strategy');
330330
}
331331

332332
public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
333333
{
334-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
334+
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
335335
$this->expectExceptionMessage('"supports" or "support_strategy" should be configured.');
336336
$this->createContainerFromFile('workflow_without_support_and_support_strategy');
337337
}
@@ -513,7 +513,7 @@ public function testRouter()
513513

514514
public function testRouterRequiresResourceOption()
515515
{
516-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
516+
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
517517
$container = $this->createContainer();
518518
$loader = new FrameworkExtension();
519519
$loader->load([['router' => true]], $container);
@@ -774,14 +774,14 @@ public function testMessengerWithMultipleBuses()
774774

775775
public function testMessengerMiddlewareFactoryErroneousFormat()
776776
{
777-
$this->expectException('InvalidArgumentException');
777+
$this->expectException(\InvalidArgumentException::class);
778778
$this->expectExceptionMessage('Invalid middleware at path "framework.messenger": a map with a single factory id as key and its arguments as value was expected, {"foo":["qux"],"bar":["baz"]} given.');
779779
$this->createContainerFromFile('messenger_middleware_factory_erroneous_format');
780780
}
781781

782782
public function testMessengerInvalidTransportRouting()
783783
{
784-
$this->expectException('LogicException');
784+
$this->expectException(\LogicException::class);
785785
$this->expectExceptionMessage('Invalid Messenger routing configuration: the "Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage" class is being routed to a sender called "invalid". This is not a valid transport or service id.');
786786
$this->createContainerFromFile('messenger_routing_invalid_transport');
787787
}
@@ -797,19 +797,19 @@ public function testTranslator()
797797
$this->assertSame($container->getParameter('kernel.cache_dir').'/translations', $options['cache_dir']);
798798

799799
$files = array_map('realpath', $options['resource_files']['en']);
800-
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
800+
$ref = new \ReflectionClass(\Symfony\Component\Validator\Validation::class);
801801
$this->assertContains(
802802
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
803803
$files,
804804
'->registerTranslatorConfiguration() finds Validator translation resources'
805805
);
806-
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
806+
$ref = new \ReflectionClass(\Symfony\Component\Form\Form::class);
807807
$this->assertContains(
808808
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
809809
$files,
810810
'->registerTranslatorConfiguration() finds Form translation resources'
811811
);
812-
$ref = new \ReflectionClass('Symfony\Component\Security\Core\Security');
812+
$ref = new \ReflectionClass(\Symfony\Component\Security\Core\Security::class);
813813
$this->assertContains(
814814
strtr(\dirname($ref->getFileName()).'/Resources/translations/security.en.xlf', '/', \DIRECTORY_SEPARATOR),
815815
$files,
@@ -866,7 +866,7 @@ public function testValidation()
866866
$container = $this->createContainerFromFile('full');
867867
$projectDir = $container->getParameter('kernel.project_dir');
868868

869-
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
869+
$ref = new \ReflectionClass(\Symfony\Component\Form\Form::class);
870870
$xmlMappings = [
871871
\dirname($ref->getFileName()).'/Resources/config/validation.xml',
872872
strtr($projectDir.'/config/validator/foo.xml', '/', \DIRECTORY_SEPARATOR),
@@ -900,7 +900,7 @@ public function testValidationService()
900900
{
901901
$container = $this->createContainerFromFile('validation_annotations', ['kernel.charset' => 'UTF-8'], false);
902902

903-
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator.alias'));
903+
$this->assertInstanceOf(\Symfony\Component\Validator\Validator\ValidatorInterface::class, $container->get('validator.alias'));
904904
}
905905

906906
public function testAnnotations()

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function load(array $configs, ContainerBuilder $container)
3737
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3838
$loader->load('twig.php');
3939

40-
if (class_exists('Symfony\Component\Form\Form')) {
40+
if (class_exists(\Symfony\Component\Form\Form::class)) {
4141
$loader->load('form.php');
4242
}
4343

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testCreateTableCellStyle()
2121
$tableCellStyle = new TableCellStyle(['fg' => 'red']);
2222
$this->assertEquals('red', $tableCellStyle->getOptions()['fg']);
2323

24-
$this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
24+
$this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class);
2525
new TableCellStyle(['wrong_key' => null]);
2626
}
2727
}

src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FragmentHandlerTest extends TestCase
2626

2727
protected function setUp(): void
2828
{
29-
$this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
29+
$this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)
3030
->disableOriginalConstructor()
3131
->getMock()
3232
;
@@ -39,14 +39,14 @@ protected function setUp(): void
3939

4040
public function testRenderWhenRendererDoesNotExist()
4141
{
42-
$this->expectException('InvalidArgumentException');
42+
$this->expectException(\InvalidArgumentException::class);
4343
$handler = new FragmentHandler($this->requestStack);
4444
$handler->render('/', 'foo');
4545
}
4646

4747
public function testRenderWithUnknownRenderer()
4848
{
49-
$this->expectException('InvalidArgumentException');
49+
$this->expectException(\InvalidArgumentException::class);
5050
$handler = $this->getHandler($this->returnValue(new Response('foo')));
5151

5252
$handler->render('/', 'bar');
@@ -59,7 +59,7 @@ public function testDeliverWithUnsuccessfulResponse()
5959
$handler->render('/', 'foo');
6060
$this->fail('->render() throws a \RuntimeException exception if response is not successful');
6161
} catch (\Exception $e) {
62-
$this->assertInstanceOf('\RuntimeException', $e);
62+
$this->assertInstanceOf(\RuntimeException::class, $e);
6363
$this->assertEquals(0, $e->getCode());
6464
$this->assertEquals('Error when rendering "http://localhost/" (Status code is 404).', $e->getMessage());
6565

@@ -79,7 +79,7 @@ public function testRender()
7979

8080
protected function getHandler($returnValue, $arguments = [])
8181
{
82-
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
82+
$renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock();
8383
$renderer
8484
->expects($this->any())
8585
->method('getName')

src/Symfony/Component/Mime/Tests/Header/PathHeaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testSingleAddressCanBeSetAndFetched()
2525

2626
public function testAddressMustComplyWithRfc2822()
2727
{
28-
$this->expectException('Exception');
28+
$this->expectException(\Exception::class);
2929
new PathHeader('Return-Path', new Address('chr is@swiftmailer.org'));
3030
}
3131

0 commit comments

Comments
 (0)