| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Postpay\Tests\Http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Postpay\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Postpay\Postpay; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class RequestTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     public function testGetMethod() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         $request = new Request('get'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         self::assertEquals('GET', $request->getMethod()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function testGetPath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $request = new Request('GET', '/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         self::assertEquals('/', $request->getPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function testAuth() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $auth = ['user', 'password']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $request->setAuth($auth); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         self::assertEquals($auth, $request->getAuth()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function testHeaders() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $headers = ['Test' => true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $request->setHeaders($headers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         self::assertArraySubset($headers, $request->getHeaders()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testParams() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $params = ['test' => true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $request->setParams($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         self::assertArraySubset($params, $request->getParams()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testJson() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $params = ['test' => true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $request->setParams($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         self::assertEmpty($request->json()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $request->setMethod('POST'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         self::assertNotEmpty($request->json()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     public function testApiVersion() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $version = 'v1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $request->setApiVersion($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         self::assertEquals($version, $request->getApiVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function testIsGraphQL() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $request = new Request('GET'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         self::assertFalse($request->isGraphQL()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $request->setApiVersion(Postpay::GRAPHQL_VERSION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         self::assertTrue($request->isGraphQL()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |     public function testGetUrl() | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |         $path = '/test'; | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |         $request = new Request('GET', $path); | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         self::assertStringEndsWith($path, $request->getUrl()); | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.