11<?php
2- declare (strict_types=1 );
3-
42namespace App \Tests \Service \Decoder ;
53
64use App \Service \Cache ;
7- use App \Service \Decoder \ResponseDecoder ;
5+ use App \Service \Decoder \JsonResponseDecoder ;
86use Http \Client \Exception \NetworkException ;
97use Http \Client \HttpClient ;
108use Nyholm \Psr7 \Request ;
119use PHPUnit \Framework \TestCase ;
1210use Psr \Http \Message \ResponseInterface ;
1311use Symfony \Component \Cache \Simple \FilesystemCache ;
1412
15- class ResponseDecoderTest extends TestCase
13+ class JsonResponseDecoderTest extends TestCase
1614{
1715 /**
1816 * @var HttpClient|\Prophecy\Prophecy\ObjectProphecy
@@ -39,7 +37,7 @@ protected function setUp()
3937
4038 public function testGetDecodedResponse ()
4139 {
42- $ decoder = new ResponseDecoder (false , $ this ->client ->reveal (), $ this ->cache ->reveal ());
40+ $ decoder = new JsonResponseDecoder (false , $ this ->client ->reveal (), $ this ->cache ->reveal ());
4341
4442 $ request = new Request ('GET ' , 'endpoint/data.json ' );
4543 $ response = $ this ->prophesize (ResponseInterface::class);
@@ -56,7 +54,7 @@ public function testGetDecodedResponse()
5654
5755 public function testGetDecodedResponseEmptyOnRequestError ()
5856 {
59- $ decoder = new ResponseDecoder (false , $ this ->client ->reveal (), $ this ->cache ->reveal ());
57+ $ decoder = new JsonResponseDecoder (false , $ this ->client ->reveal (), $ this ->cache ->reveal ());
6058
6159 $ request = new Request ('GET ' , 'endpoint/data.json ' );
6260 $ response = $ this ->prophesize (ResponseInterface::class);
@@ -73,7 +71,7 @@ public function testGetDecodedResponseEmptyOnRequestError()
7371
7472 public function testGetDecodedResponseFromCacheOnRequestError ()
7573 {
76- $ decoder = new ResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
74+ $ decoder = new JsonResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
7775
7876 $ request = new Request ('GET ' , 'endpoint/data.json ' );
7977 $ response = $ this ->prophesize (ResponseInterface::class);
@@ -93,7 +91,7 @@ public function testGetDecodedResponseFromCacheOnRequestError()
9391
9492 public function testGetDecodedResponseCachesDataIfEnabled ()
9593 {
96- $ decoder = new ResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
94+ $ decoder = new JsonResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
9795
9896 $ request = new Request ('GET ' , 'endpoint/data.json ' );
9997 $ response = $ this ->prophesize (ResponseInterface::class);
@@ -113,7 +111,7 @@ public function testGetDecodedResponseCachesDataIfEnabled()
113111
114112 public function testGetDecodedResponseFromCacheWhenNetworkFails ()
115113 {
116- $ decoder = new ResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
114+ $ decoder = new JsonResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
117115
118116 $ request = new Request ('GET ' , 'endpoint/data.json ' );
119117
@@ -135,7 +133,7 @@ public function testGetDecodedResponseFromCacheWhenNetworkFails()
135133 */
136134 public function testGetDecodedResponseThrowsNetworkExceptionWhenClientFailsAndNoCachedVersion ()
137135 {
138- $ decoder = new ResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
136+ $ decoder = new JsonResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
139137 $ request = new Request ('GET ' , 'endpoint/data.json ' );
140138
141139 $ this ->simpleCache ->has ('4429b090fd82239e188859ae626162e5e790b4db ' )->willReturn (false );
@@ -151,7 +149,7 @@ public function testGetDecodedResponseThrowsNetworkExceptionWhenClientFailsAndNo
151149 */
152150 public function testGetDecodedResponseReturnsBodyWhenJsonDecodingFails ()
153151 {
154- $ decoder = new ResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
152+ $ decoder = new JsonResponseDecoder (true , $ this ->client ->reveal (), $ this ->cache ->reveal ());
155153
156154 $ request = new Request ('GET ' , 'endpoint/data.json ' );
157155 $ response = $ this ->prophesize (ResponseInterface::class);
0 commit comments