Skip to content

Commit 3af8ed2

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents 79d273e + d99f6d5 commit 3af8ed2

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Tests/PropertyAccessorArrayAccessTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
1516
use Symfony\Component\PropertyAccess\PropertyAccess;
1617
use Symfony\Component\PropertyAccess\PropertyAccessor;
1718

@@ -47,7 +48,7 @@ public function testGetValue($collection, $path, $value)
4748

4849
public function testGetValueFailsIfNoSuchIndex()
4950
{
50-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchIndexException::class);
51+
$this->expectException(NoSuchIndexException::class);
5152
$this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
5253
->enableExceptionOnInvalidIndex()
5354
->getPropertyAccessor();

Tests/PropertyAccessorCollectionTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14+
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
15+
1416
class PropertyAccessorCollectionTest_Car
1517
{
1618
private $axes;
@@ -121,8 +123,8 @@ public function testSetValueCallsAdderAndRemoverForCollections()
121123

122124
public function testSetValueCallsAdderAndRemoverForNestedCollections()
123125
{
124-
$car = $this->getMockBuilder(__CLASS__.'_CompositeCar')->getMock();
125-
$structure = $this->getMockBuilder(__CLASS__.'_CarStructure')->getMock();
126+
$car = $this->createMock(__CLASS__.'_CompositeCar');
127+
$structure = $this->createMock(__CLASS__.'_CarStructure');
126128
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
127129
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
128130

@@ -148,9 +150,9 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()
148150

149151
public function testSetValueFailsIfNoAdderNorRemoverFound()
150152
{
151-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
153+
$this->expectException(NoSuchPropertyException::class);
152154
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
153-
$car = $this->getMockBuilder(__CLASS__.'_CarNoAdderAndRemover')->getMock();
155+
$car = $this->createMock(__CLASS__.'_CarNoAdderAndRemover');
154156
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
155157
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
156158

@@ -187,7 +189,7 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
187189

188190
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
189191
{
190-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
192+
$this->expectException(NoSuchPropertyException::class);
191193
$this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTest_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./');
192194
$car = new PropertyAccessorCollectionTest_Car();
193195

Tests/PropertyAccessorTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Cache\Adapter\ArrayAdapter;
16+
use Symfony\Component\PropertyAccess\Exception\AccessException;
17+
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
1618
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
1719
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
20+
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
1821
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1922
use Symfony\Component\PropertyAccess\PropertyAccess;
2023
use Symfony\Component\PropertyAccess\PropertyAccessor;
@@ -159,7 +162,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetter()
159162
*/
160163
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousClass()
161164
{
162-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
165+
$this->expectException(AccessException::class);
163166
$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"?');
164167

165168
$object = eval('return new class() {
@@ -179,7 +182,7 @@ public function getUninitialized(): array
179182
*/
180183
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousStdClass()
181184
{
182-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
185+
$this->expectException(AccessException::class);
183186
$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"?');
184187

185188
$object = eval('return new class() extends \stdClass {
@@ -199,7 +202,7 @@ public function getUninitialized(): array
199202
*/
200203
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousChildClass()
201204
{
202-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
205+
$this->expectException(AccessException::class);
203206
$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"?');
204207

205208
$object = eval('return new class() extends \Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty {};');
@@ -302,7 +305,7 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
302305
*/
303306
public function testGetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
304307
{
305-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
308+
$this->expectException(UnexpectedTypeException::class);
306309
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
307310
$this->propertyAccessor->getValue($objectOrArray, $path);
308311
}
@@ -421,7 +424,7 @@ public function testSetValueUpdatesMagicCallIfEnabled()
421424
*/
422425
public function testSetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
423426
{
424-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
427+
$this->expectException(UnexpectedTypeException::class);
425428
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
426429
$this->propertyAccessor->setValue($objectOrArray, $path, 'value');
427430
}
@@ -679,7 +682,7 @@ public function testIsWritableForReferenceChainIssue($object, $path, $value)
679682

680683
public function testThrowTypeError()
681684
{
682-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
685+
$this->expectException(InvalidArgumentException::class);
683686
$this->expectExceptionMessage('Expected argument of type "DateTime", "string" given at property path "date"');
684687
$object = new TypeHinted();
685688

@@ -688,7 +691,7 @@ public function testThrowTypeError()
688691

689692
public function testThrowTypeErrorWithNullArgument()
690693
{
691-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
694+
$this->expectException(InvalidArgumentException::class);
692695
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
693696
$object = new TypeHinted();
694697

@@ -740,7 +743,7 @@ public function testAttributeWithSpecialChars()
740743

741744
public function testThrowTypeErrorWithInterface()
742745
{
743-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
746+
$this->expectException(InvalidArgumentException::class);
744747
$this->expectExceptionMessage('Expected argument of type "Countable", "string" given');
745748
$object = new TypeHinted();
746749

Tests/PropertyPathTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
16+
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
1517
use Symfony\Component\PropertyAccess\PropertyPath;
1618

1719
class PropertyPathTest extends TestCase
@@ -25,13 +27,13 @@ public function testToString()
2527

2628
public function testDotIsRequiredBeforeProperty()
2729
{
28-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException::class);
30+
$this->expectException(InvalidPropertyPathException::class);
2931
new PropertyPath('[index]property');
3032
}
3133

3234
public function testDotCannotBePresentAtTheBeginning()
3335
{
34-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException::class);
36+
$this->expectException(InvalidPropertyPathException::class);
3537
new PropertyPath('.property');
3638
}
3739

@@ -53,25 +55,25 @@ public function providePathsContainingUnexpectedCharacters()
5355
*/
5456
public function testUnexpectedCharacters($path)
5557
{
56-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException::class);
58+
$this->expectException(InvalidPropertyPathException::class);
5759
new PropertyPath($path);
5860
}
5961

6062
public function testPathCannotBeEmpty()
6163
{
62-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException::class);
64+
$this->expectException(InvalidPropertyPathException::class);
6365
new PropertyPath('');
6466
}
6567

6668
public function testPathCannotBeNull()
6769
{
68-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
70+
$this->expectException(InvalidArgumentException::class);
6971
new PropertyPath(null);
7072
}
7173

7274
public function testPathCannotBeFalse()
7375
{
74-
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
76+
$this->expectException(InvalidArgumentException::class);
7577
new PropertyPath(false);
7678
}
7779

0 commit comments

Comments
 (0)