| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace GuillermoandraeTest\Highrise; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Guillermoandrae\Highrise\Http\GuzzleAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Guillermoandrae\Highrise\Resources\ResourceFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Guillermoandrae\Highrise\Resources\ResourceInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use GuzzleHttp\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use GuzzleHttp\Handler\MockHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use GuzzleHttp\HandlerStack; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use GuzzleHttp\Psr7\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PHPUnit\Framework\TestCase as PHPUnitTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class TestCase extends PHPUnitTestCase | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     protected function assertSameLastRequestUri(string $uri, ResourceInterface $resource) | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         $this->assertSame($uri, $resource->getAdapter()->getLastRequest()->getUri()->getPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     protected function getMockResource(string $name, string $expectedBody) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $client = $this->getMockClient(200, [], $expectedBody); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $adapter = $this->getAdapter($client); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return ResourceFactory::factory($name, $adapter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected function getAdapter(Client $client): GuzzleAdapter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $adapter = new GuzzleAdapter('test', '123456'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $adapter->setClient($client); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         return $adapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     protected function getMockClient($expectedHttpStatusCode, array $expectedHeaders = [], $expectedBody = ''): Client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $mock = new MockHandler([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             new Response($expectedHttpStatusCode, $expectedHeaders, $expectedBody) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $handler = HandlerStack::create($mock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return new Client(['handler' => $handler]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |  |