@@ 16-114 (lines=99) @@ | ||
13 | use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
|
14 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
15 | ||
16 | final class FacadeCisListResponseDenormalizerTest extends TestCase |
|
17 | { |
|
18 | /** |
|
19 | * @var FacadeCisListResponseDenormalizer |
|
20 | */ |
|
21 | private $denormalizer; |
|
22 | /** |
|
23 | * @var MockObject|DenormalizerInterface |
|
24 | */ |
|
25 | private $inner; |
|
26 | ||
27 | protected function setUp(): void |
|
28 | { |
|
29 | $this->inner = $this->createMock(DenormalizerInterface::class); |
|
30 | $this->denormalizer = new FacadeCisListResponseDenormalizer(); |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @dataProvider dataSupportsDenormalization |
|
35 | */ |
|
36 | public function testSupportsDenormalization(string $type, bool $expected): void |
|
37 | { |
|
38 | $result = $this->denormalizer->supportsDenormalization([], $type); |
|
39 | ||
40 | $this->assertEquals($expected, $result); |
|
41 | } |
|
42 | ||
43 | public function dataSupportsDenormalization(): array |
|
44 | { |
|
45 | return [ |
|
46 | [ |
|
47 | FacadeCisListResponse::class, |
|
48 | true, |
|
49 | ], |
|
50 | [ |
|
51 | \stdClass::class, |
|
52 | false, |
|
53 | ], |
|
54 | ]; |
|
55 | } |
|
56 | ||
57 | public function testDenormalizationWhenDenormalizerIsNotSet(): void |
|
58 | { |
|
59 | $this->expectException(BadMethodCallException::class); |
|
60 | $this->denormalizer->denormalize([], FacadeCisListResponse::class); |
|
61 | } |
|
62 | ||
63 | public function testDenormalizationWhenWrongData(): void |
|
64 | { |
|
65 | $this->denormalizer->setDenormalizer($this->inner); |
|
66 | ||
67 | $this->expectException(InvalidArgumentException::class); |
|
68 | $this->denormalizer->denormalize('wrong', FacadeCisListResponse::class); |
|
69 | } |
|
70 | ||
71 | public function testDenormalizationWhenWrongType(): void |
|
72 | { |
|
73 | $this->denormalizer->setDenormalizer($this->inner); |
|
74 | ||
75 | $this->expectException(InvalidArgumentException::class); |
|
76 | $this->denormalizer->denormalize([], \stdClass::class); |
|
77 | } |
|
78 | ||
79 | public function testDenormalizationWorks(): void |
|
80 | { |
|
81 | $this->denormalizer->setDenormalizer($this->inner); |
|
82 | ||
83 | $item1 = new FacadeCisItemResponse('', '', '', 0, '', 0); |
|
84 | $item2 = new FacadeCisItemResponse('', '', '', 0, '', 0); |
|
85 | ||
86 | $expectedResult = new FacadeCisListResponse($item1, $item2); |
|
87 | ||
88 | $this->inner->expects($this->exactly(2)) |
|
89 | ->method('denormalize') |
|
90 | ->withConsecutive( |
|
91 | ['first', FacadeCisItemResponse::class, null, []], |
|
92 | ['second', FacadeCisItemResponse::class, null, []] |
|
93 | ) |
|
94 | ->willReturnOnConsecutiveCalls( |
|
95 | $item1, |
|
96 | $item2 |
|
97 | ); |
|
98 | ||
99 | $result = $this->denormalizer->denormalize([ |
|
100 | 'first', |
|
101 | 'second', |
|
102 | ], FacadeCisListResponse::class); |
|
103 | ||
104 | $this->assertEquals($expectedResult, $result); |
|
105 | } |
|
106 | ||
107 | public function testHasCacheableSupportsMethod(): void |
|
108 | { |
|
109 | $this->denormalizer->setDenormalizer($this->inner); |
|
110 | ||
111 | $result = $this->denormalizer->hasCacheableSupportsMethod(); |
|
112 | $this->assertFalse($result); |
|
113 | } |
|
114 | } |
|
115 |
@@ 16-114 (lines=99) @@ | ||
13 | use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
|
14 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
15 | ||
16 | final class FacadeCisListResponseDenormalizerTest extends TestCase |
|
17 | { |
|
18 | /** |
|
19 | * @var FacadeCisListResponseDenormalizer |
|
20 | */ |
|
21 | private $denormalizer; |
|
22 | /** |
|
23 | * @var MockObject|DenormalizerInterface |
|
24 | */ |
|
25 | private $inner; |
|
26 | ||
27 | protected function setUp(): void |
|
28 | { |
|
29 | $this->inner = $this->createMock(DenormalizerInterface::class); |
|
30 | $this->denormalizer = new FacadeCisListResponseDenormalizer(); |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @dataProvider dataSupportsDenormalization |
|
35 | */ |
|
36 | public function testSupportsDenormalization(string $type, bool $expected): void |
|
37 | { |
|
38 | $result = $this->denormalizer->supportsDenormalization([], $type); |
|
39 | ||
40 | $this->assertEquals($expected, $result); |
|
41 | } |
|
42 | ||
43 | public function dataSupportsDenormalization(): array |
|
44 | { |
|
45 | return [ |
|
46 | [ |
|
47 | FacadeCisListResponse::class, |
|
48 | true, |
|
49 | ], |
|
50 | [ |
|
51 | \stdClass::class, |
|
52 | false, |
|
53 | ], |
|
54 | ]; |
|
55 | } |
|
56 | ||
57 | public function testDenormalizationWhenDenormalizerIsNotSet(): void |
|
58 | { |
|
59 | $this->expectException(BadMethodCallException::class); |
|
60 | $this->denormalizer->denormalize([], FacadeCisListResponse::class); |
|
61 | } |
|
62 | ||
63 | public function testDenormalizationWhenWrongData(): void |
|
64 | { |
|
65 | $this->denormalizer->setDenormalizer($this->inner); |
|
66 | ||
67 | $this->expectException(InvalidArgumentException::class); |
|
68 | $this->denormalizer->denormalize('wrong', FacadeCisListResponse::class); |
|
69 | } |
|
70 | ||
71 | public function testDenormalizationWhenWrongType(): void |
|
72 | { |
|
73 | $this->denormalizer->setDenormalizer($this->inner); |
|
74 | ||
75 | $this->expectException(InvalidArgumentException::class); |
|
76 | $this->denormalizer->denormalize([], \stdClass::class); |
|
77 | } |
|
78 | ||
79 | public function testDenormalizationWorks(): void |
|
80 | { |
|
81 | $this->denormalizer->setDenormalizer($this->inner); |
|
82 | ||
83 | $item1 = new FacadeCisItemResponse('', '', '', 0, '', 0); |
|
84 | $item2 = new FacadeCisItemResponse('', '', '', 0, '', 0); |
|
85 | ||
86 | $expectedResult = new FacadeCisListResponse($item1, $item2); |
|
87 | ||
88 | $this->inner->expects($this->exactly(2)) |
|
89 | ->method('denormalize') |
|
90 | ->withConsecutive( |
|
91 | ['first', FacadeCisItemResponse::class, null, []], |
|
92 | ['second', FacadeCisItemResponse::class, null, []] |
|
93 | ) |
|
94 | ->willReturnOnConsecutiveCalls( |
|
95 | $item1, |
|
96 | $item2 |
|
97 | ); |
|
98 | ||
99 | $result = $this->denormalizer->denormalize([ |
|
100 | 'first', |
|
101 | 'second', |
|
102 | ], FacadeCisListResponse::class); |
|
103 | ||
104 | $this->assertEquals($expectedResult, $result); |
|
105 | } |
|
106 | ||
107 | public function testHasCacheableSupportsMethod(): void |
|
108 | { |
|
109 | $this->denormalizer->setDenormalizer($this->inner); |
|
110 | ||
111 | $result = $this->denormalizer->hasCacheableSupportsMethod(); |
|
112 | $this->assertFalse($result); |
|
113 | } |
|
114 | } |
|
115 |