Skip to content

Commit 6b383bc

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent 032b08d commit 6b383bc

31 files changed

+152
-114
lines changed

Tests/Annotation/DiscriminatorMapTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
16+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1617

1718
/**
1819
* @author Samuel Roze <samuel.roze@gmail.com>
@@ -35,25 +36,25 @@ public function testGetTypePropertyAndMapping()
3536

3637
public function testExceptionWithoutTypeProperty()
3738
{
38-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
39+
$this->expectException(InvalidArgumentException::class);
3940
new DiscriminatorMap(['mapping' => ['foo' => 'FooClass']]);
4041
}
4142

4243
public function testExceptionWithEmptyTypeProperty()
4344
{
44-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
45+
$this->expectException(InvalidArgumentException::class);
4546
new DiscriminatorMap(['typeProperty' => '', 'mapping' => ['foo' => 'FooClass']]);
4647
}
4748

4849
public function testExceptionWithoutMappingProperty()
4950
{
50-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
51+
$this->expectException(InvalidArgumentException::class);
5152
new DiscriminatorMap(['typeProperty' => 'type']);
5253
}
5354

5455
public function testExceptionWitEmptyMappingProperty()
5556
{
56-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
57+
$this->expectException(InvalidArgumentException::class);
5758
new DiscriminatorMap(['typeProperty' => 'type', 'mapping' => []]);
5859
}
5960
}

Tests/Annotation/GroupsTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Annotation\Groups;
16+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1617

1718
/**
1819
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -21,19 +22,19 @@ class GroupsTest extends TestCase
2122
{
2223
public function testEmptyGroupsParameter()
2324
{
24-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
25+
$this->expectException(InvalidArgumentException::class);
2526
new Groups(['value' => []]);
2627
}
2728

2829
public function testNotAnArrayGroupsParameter()
2930
{
30-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
31+
$this->expectException(InvalidArgumentException::class);
3132
new Groups(['value' => 12]);
3233
}
3334

3435
public function testInvalidGroupsParameter()
3536
{
36-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
37+
$this->expectException(InvalidArgumentException::class);
3738
new Groups(['value' => ['a', 1, new \stdClass()]]);
3839
}
3940

Tests/Annotation/MaxDepthTest.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\Serializer\Annotation\MaxDepth;
16+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1617

1718
/**
1819
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -21,7 +22,7 @@ class MaxDepthTest extends TestCase
2122
{
2223
public function testNotSetMaxDepthParameter()
2324
{
24-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
25+
$this->expectException(InvalidArgumentException::class);
2526
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" should be set.');
2627
new MaxDepth([]);
2728
}
@@ -41,7 +42,7 @@ public function provideInvalidValues()
4142
*/
4243
public function testNotAnIntMaxDepthParameter($value)
4344
{
44-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
45+
$this->expectException(InvalidArgumentException::class);
4546
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer.');
4647
new MaxDepth(['value' => $value]);
4748
}

Tests/Annotation/SerializedNameTest.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\Serializer\Annotation\SerializedName;
16+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1617

1718
/**
1819
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
@@ -21,7 +22,7 @@ class SerializedNameTest extends TestCase
2122
{
2223
public function testNotSetSerializedNameParameter()
2324
{
24-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
25+
$this->expectException(InvalidArgumentException::class);
2526
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\SerializedName" should be set.');
2627
new SerializedName([]);
2728
}
@@ -39,7 +40,7 @@ public function provideInvalidValues()
3940
*/
4041
public function testNotAStringSerializedNameParameter($value)
4142
{
42-
$this->expectException(\Symfony\Component\Serializer\Exception\InvalidArgumentException::class);
43+
$this->expectException(InvalidArgumentException::class);
4344
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\SerializedName" must be a non-empty string.');
4445
new SerializedName(['value' => $value]);
4546
}

Tests/Encoder/ChainDecoderTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Encoder\ChainDecoder;
16+
use Symfony\Component\Serializer\Encoder\DecoderInterface;
17+
use Symfony\Component\Serializer\Exception\RuntimeException;
1618

1719
class ChainDecoderTest extends TestCase
1820
{
@@ -26,10 +28,7 @@ class ChainDecoderTest extends TestCase
2628

2729
protected function setUp(): void
2830
{
29-
$this->decoder1 = $this
30-
->getMockBuilder(\Symfony\Component\Serializer\Encoder\DecoderInterface::class)
31-
->getMock();
32-
31+
$this->decoder1 = $this->createMock(DecoderInterface::class);
3332
$this->decoder1
3433
->method('supportsDecoding')
3534
->willReturnMap([
@@ -39,10 +38,7 @@ protected function setUp(): void
3938
[self::FORMAT_3, ['foo' => 'bar'], true],
4039
]);
4140

42-
$this->decoder2 = $this
43-
->getMockBuilder(\Symfony\Component\Serializer\Encoder\DecoderInterface::class)
44-
->getMock();
45-
41+
$this->decoder2 = $this->createMock(DecoderInterface::class);
4642
$this->decoder2
4743
->method('supportsDecoding')
4844
->willReturnMap([
@@ -72,7 +68,7 @@ public function testDecode()
7268

7369
public function testDecodeUnsupportedFormat()
7470
{
75-
$this->expectException(\Symfony\Component\Serializer\Exception\RuntimeException::class);
71+
$this->expectException(RuntimeException::class);
7672
$this->chainDecoder->decode('string_to_decode', self::FORMAT_3);
7773
}
7874
}

Tests/Encoder/ChainEncoderTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Serializer\Encoder\ChainEncoder;
1616
use Symfony\Component\Serializer\Encoder\EncoderInterface;
1717
use Symfony\Component\Serializer\Encoder\NormalizationAwareInterface;
18+
use Symfony\Component\Serializer\Exception\RuntimeException;
1819

1920
class ChainEncoderTest extends TestCase
2021
{
@@ -28,10 +29,7 @@ class ChainEncoderTest extends TestCase
2829

2930
protected function setUp(): void
3031
{
31-
$this->encoder1 = $this
32-
->getMockBuilder(EncoderInterface::class)
33-
->getMock();
34-
32+
$this->encoder1 = $this->createMock(EncoderInterface::class);
3533
$this->encoder1
3634
->method('supportsEncoding')
3735
->willReturnMap([
@@ -41,10 +39,7 @@ protected function setUp(): void
4139
[self::FORMAT_3, ['foo' => 'bar'], true],
4240
]);
4341

44-
$this->encoder2 = $this
45-
->getMockBuilder(EncoderInterface::class)
46-
->getMock();
47-
42+
$this->encoder2 = $this->createMock(EncoderInterface::class);
4843
$this->encoder2
4944
->method('supportsEncoding')
5045
->willReturnMap([
@@ -74,7 +69,7 @@ public function testEncode()
7469

7570
public function testEncodeUnsupportedFormat()
7671
{
77-
$this->expectException(\Symfony\Component\Serializer\Exception\RuntimeException::class);
72+
$this->expectException(RuntimeException::class);
7873
$this->chainEncoder->encode(['foo' => 123], self::FORMAT_3);
7974
}
8075

Tests/Encoder/JsonDecodeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Encoder\JsonDecode;
1616
use Symfony\Component\Serializer\Encoder\JsonEncoder;
17+
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1718

1819
class JsonDecodeTest extends TestCase
1920
{
@@ -60,7 +61,7 @@ public function decodeProvider()
6061
*/
6162
public function testDecodeWithException($value)
6263
{
63-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
64+
$this->expectException(UnexpectedValueException::class);
6465
$this->decode->decode($value, JsonEncoder::FORMAT);
6566
}
6667

Tests/Encoder/JsonEncodeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Encoder\JsonEncode;
1616
use Symfony\Component\Serializer\Encoder\JsonEncoder;
17+
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1718

1819
class JsonEncodeTest extends TestCase
1920
{
@@ -53,7 +54,7 @@ public function encodeProvider()
5354

5455
public function testEncodeWithError()
5556
{
56-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
57+
$this->expectException(UnexpectedValueException::class);
5758
$this->encode->encode("\xB1\x31", JsonEncoder::FORMAT);
5859
}
5960
}

Tests/Encoder/JsonEncoderTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Encoder\JsonEncoder;
16+
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1617
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
1718
use Symfony\Component\Serializer\Serializer;
1819

@@ -67,7 +68,7 @@ public function testOptions()
6768

6869
public function testEncodeNotUtf8WithoutPartialOnError()
6970
{
70-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
71+
$this->expectException(UnexpectedValueException::class);
7172
$arr = [
7273
'utf8' => 'Hello World!',
7374
'notUtf8' => "\xb0\xd0\xb5\xd0",

Tests/Encoder/XmlEncoderTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1717
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
18+
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1819
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
1920
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2021
use Symfony\Component\Serializer\Serializer;
@@ -86,7 +87,7 @@ public function testSetRootNodeName()
8687

8788
public function testDocTypeIsNotAllowed()
8889
{
89-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
90+
$this->expectException(UnexpectedValueException::class);
9091
$this->expectExceptionMessage('Document types are not allowed.');
9192
$this->encoder->decode('<?xml version="1.0"?><!DOCTYPE foo><foo></foo>', 'foo');
9293
}
@@ -708,19 +709,19 @@ public function testDecodeWithoutItemHash()
708709

709710
public function testDecodeInvalidXml()
710711
{
711-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
712+
$this->expectException(UnexpectedValueException::class);
712713
$this->encoder->decode('<?xml version="1.0"?><invalid><xml>', 'xml');
713714
}
714715

715716
public function testPreventsComplexExternalEntities()
716717
{
717-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
718+
$this->expectException(UnexpectedValueException::class);
718719
$this->encoder->decode('<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=XmlEncoderTest.php">]><scan>&test;</scan>', 'xml');
719720
}
720721

721722
public function testDecodeEmptyXml()
722723
{
723-
$this->expectException(\Symfony\Component\Serializer\Exception\UnexpectedValueException::class);
724+
$this->expectException(UnexpectedValueException::class);
724725
$this->expectExceptionMessage('Invalid XML data, it can not be empty.');
725726
$this->encoder->decode(' ', 'xml');
726727
}
@@ -934,7 +935,7 @@ private function createXmlEncoderWithDateTimeNormalizer(): XmlEncoder
934935
*/
935936
private function createMockDateTimeNormalizer()
936937
{
937-
$mock = $this->getMockBuilder(CustomNormalizer::class)->getMock();
938+
$mock = $this->createMock(CustomNormalizer::class);
938939

939940
$mock
940941
->expects($this->once())

0 commit comments

Comments
 (0)