Skip to content

Commit 2756a74

Browse files
committed
Use ::class keyword when possible
1 parent 37219cd commit 2756a74

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Tests/PropertyAccessorTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testGetValue($objectOrArray, $path, $value)
103103
*/
104104
public function testGetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
105105
{
106-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
106+
$this->expectException(NoSuchPropertyException::class);
107107
$this->propertyAccessor->getValue($objectOrArray, $path);
108108
}
109109

@@ -130,7 +130,7 @@ public function testGetValueThrowsNoExceptionIfIndexNotFound($objectOrArray, $pa
130130
*/
131131
public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled($objectOrArray, $path)
132132
{
133-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
133+
$this->expectException(NoSuchIndexException::class);
134134
$this->propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, true);
135135
$this->propertyAccessor->getValue($objectOrArray, $path);
136136
}
@@ -159,7 +159,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetter()
159159
*/
160160
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousClass()
161161
{
162-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
162+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
163163
$this->expectExceptionMessage('The method "class@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
164164

165165
$object = eval('return new class() {
@@ -179,7 +179,7 @@ public function getUninitialized(): array
179179
*/
180180
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousStdClass()
181181
{
182-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
182+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
183183
$this->expectExceptionMessage('The method "stdClass@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
184184

185185
$object = eval('return new class() extends \stdClass {
@@ -199,7 +199,7 @@ public function getUninitialized(): array
199199
*/
200200
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousChildClass()
201201
{
202-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
202+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
203203
$this->expectExceptionMessage('The method "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
204204

205205
$object = eval('return new class() extends \Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty {};');
@@ -209,7 +209,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAn
209209

210210
public function testGetValueThrowsExceptionIfNotArrayAccess()
211211
{
212-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
212+
$this->expectException(NoSuchIndexException::class);
213213
$this->propertyAccessor->getValue(new \stdClass(), '[index]');
214214
}
215215

@@ -267,7 +267,7 @@ public function testGetValueNotModifyObjectException()
267267

268268
public function testGetValueDoesNotReadMagicCallByDefault()
269269
{
270-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
270+
$this->expectException(NoSuchPropertyException::class);
271271
$this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'magicCallProperty');
272272
}
273273

@@ -302,7 +302,7 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
302302
*/
303303
public function testGetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
304304
{
305-
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
305+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
306306
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
307307
$this->propertyAccessor->getValue($objectOrArray, $path);
308308
}
@@ -322,7 +322,7 @@ public function testSetValue($objectOrArray, $path)
322322
*/
323323
public function testSetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
324324
{
325-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
325+
$this->expectException(NoSuchPropertyException::class);
326326
$this->propertyAccessor->setValue($objectOrArray, $path, 'Updated');
327327
}
328328

@@ -349,7 +349,7 @@ public function testSetValueThrowsNoExceptionIfIndexNotFoundAndIndexExceptionsEn
349349

350350
public function testSetValueThrowsExceptionIfNotArrayAccess()
351351
{
352-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
352+
$this->expectException(NoSuchIndexException::class);
353353
$object = new \stdClass();
354354

355355
$this->propertyAccessor->setValue($object, '[index]', 'Updated');
@@ -376,15 +376,15 @@ public function testSetValueIgnoresMagicSet()
376376

377377
public function testSetValueThrowsExceptionIfThereAreMissingParameters()
378378
{
379-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
379+
$this->expectException(NoSuchPropertyException::class);
380380
$object = new TestClass('Bernhard');
381381

382382
$this->propertyAccessor->setValue($object, 'publicAccessorWithMoreRequiredParameters', 'Updated');
383383
}
384384

385385
public function testSetValueDoesNotUpdateMagicCallByDefault()
386386
{
387-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
387+
$this->expectException(NoSuchPropertyException::class);
388388
$author = new TestClassMagicCall('Bernhard');
389389

390390
$this->propertyAccessor->setValue($author, 'magicCallProperty', 'Updated');
@@ -421,7 +421,7 @@ public function testSetValueUpdatesMagicCallIfEnabled()
421421
*/
422422
public function testSetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
423423
{
424-
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
424+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
425425
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
426426
$this->propertyAccessor->setValue($objectOrArray, $path, 'value');
427427
}
@@ -679,7 +679,7 @@ public function testIsWritableForReferenceChainIssue($object, $path, $value)
679679

680680
public function testThrowTypeError()
681681
{
682-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
682+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
683683
$this->expectExceptionMessage('Expected argument of type "DateTime", "string" given at property path "date"');
684684
$object = new TypeHinted();
685685

@@ -688,7 +688,7 @@ public function testThrowTypeError()
688688

689689
public function testThrowTypeErrorWithNullArgument()
690690
{
691-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
691+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
692692
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
693693
$object = new TypeHinted();
694694

@@ -740,7 +740,7 @@ public function testAttributeWithSpecialChars()
740740

741741
public function testThrowTypeErrorWithInterface()
742742
{
743-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
743+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
744744
$this->expectExceptionMessage('Expected argument of type "Countable", "string" given');
745745
$object = new TypeHinted();
746746

@@ -760,7 +760,7 @@ public function testAnonymousClassRead()
760760

761761
public function testAnonymousClassReadThrowExceptionOnInvalidPropertyPath()
762762
{
763-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
763+
$this->expectException(NoSuchPropertyException::class);
764764
$obj = $this->generateAnonymousClass('bar');
765765

766766
$this->propertyAccessor->getValue($obj, 'invalid_property');
@@ -820,23 +820,23 @@ public function setFoo($foo)
820820

821821
public function testThrowTypeErrorInsideSetterCall()
822822
{
823-
$this->expectException('TypeError');
823+
$this->expectException(\TypeError::class);
824824
$object = new TestClassTypeErrorInsideCall();
825825

826826
$this->propertyAccessor->setValue($object, 'property', 'foo');
827827
}
828828

829829
public function testDoNotDiscardReturnTypeError()
830830
{
831-
$this->expectException('TypeError');
831+
$this->expectException(\TypeError::class);
832832
$object = new ReturnTyped();
833833

834834
$this->propertyAccessor->setValue($object, 'foos', [new \DateTime()]);
835835
}
836836

837837
public function testDoNotDiscardReturnTypeErrorWhenWriterMethodIsMisconfigured()
838838
{
839-
$this->expectException('TypeError');
839+
$this->expectException(\TypeError::class);
840840
$object = new ReturnTyped();
841841

842842
$this->propertyAccessor->setValue($object, 'name', 'foo');
@@ -886,39 +886,39 @@ public function testAdderAndRemoverArePreferredOverSetterForSameSingularAndPlura
886886

887887
public function testAdderWithoutRemover()
888888
{
889-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
889+
$this->expectException(NoSuchPropertyException::class);
890890
$this->expectExceptionMessageMatches('/.*The add method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding remove method "removeFoo" was not found\./');
891891
$object = new TestAdderRemoverInvalidMethods();
892892
$this->propertyAccessor->setValue($object, 'foos', [1, 2]);
893893
}
894894

895895
public function testRemoverWithoutAdder()
896896
{
897-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
897+
$this->expectException(NoSuchPropertyException::class);
898898
$this->expectExceptionMessageMatches('/.*The remove method "removeBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding add method "addBar" was not found\./');
899899
$object = new TestAdderRemoverInvalidMethods();
900900
$this->propertyAccessor->setValue($object, 'bars', [1, 2]);
901901
}
902902

903903
public function testAdderAndRemoveNeedsTheExactParametersDefined()
904904
{
905-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
905+
$this->expectException(NoSuchPropertyException::class);
906906
$this->expectExceptionMessageMatches('/.*The method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 0 arguments, but should accept only 1\./');
907907
$object = new TestAdderRemoverInvalidArgumentLength();
908908
$this->propertyAccessor->setValue($object, 'foo', [1, 2]);
909909
}
910910

911911
public function testSetterNeedsTheExactParametersDefined()
912912
{
913-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
913+
$this->expectException(NoSuchPropertyException::class);
914914
$this->expectExceptionMessageMatches('/.*The method "setBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 2 arguments, but should accept only 1\./');
915915
$object = new TestAdderRemoverInvalidArgumentLength();
916916
$this->propertyAccessor->setValue($object, 'bar', [1, 2]);
917917
}
918918

919919
public function testSetterNeedsPublicAccess()
920920
{
921-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
921+
$this->expectException(NoSuchPropertyException::class);
922922
$this->expectExceptionMessageMatches('/.*The method "setFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestClassSetValue" was found but does not have public access./');
923923
$object = new TestClassSetValue(0);
924924
$this->propertyAccessor->setValue($object, 'foo', 1);

0 commit comments

Comments
 (0)