'Foo', 'details' => [ 'age' => 40, 'human' => 'yes', ], ]); // Sample response headers $this->headers = $headers = [ "Access-Control-Allow-Credentials" => [ 0 => "true", ], "Access-Control-Allow-Headers" => [ 0 => "Content-Type,Authorization,X-User-Agent", ], "Content-Type" => [ 0 => "application/json", ], "Expires" => [ 0 => "Sat, 30 Dec 2017 09:00:32 GMT", ], "Strict-Transport-Security" => [ 0 => "max-age=31536000", ], "X-Esi-Error-Limit-Remain" => [ 0 => "64", ], "X-Esi-Error-Limit-Reset" => [ 0 => "52", ], "X-Pages" => [ 0 => "4", ], "Date" => [ 0 => "Sat, 30 Dec 2017 08:23:08 GMT", ], ]; $this->esi_response = new EsiResponse($data, $headers, 'now', 200); } public function testEsiResponseInstantiation() { $this->assertInstanceOf(EsiResponse::class, $this->esi_response); } public function testEsiResponseTestPayloadIsExpired() { $this->assertTrue($this->esi_response->expired()); } public function testEsiResponseTestPayloadIsNotExpired() { $data = json_encode(['foo' => 'bar']); $esi = new EsiResponse($data, [], '3000-01-01 00:00:00', 200); $this->assertFalse($esi->expired()); } public function testEsiResponseDoesNotHaveError() { $this->assertNull($this->esi_response->error()); } public function testEsiResponseDoesHaveError() { $data = json_encode(['error' => 'Test Error']); $esi = new EsiResponse($data, [], 'now', 500); $this->assertEquals('Test Error', $esi->error()); } public function testEsiResponseDoesHaveErrorAndDescription() { $data = json_encode(['error' => 'Test Error', 'error_description' => 'Test Description']); $esi = new EsiResponse($data, [], 'now', 500); $this->assertEquals('Test Error: Test Description', $esi->error()); } public function testEsiResponseSerializableSingleValueResponse() { $data = '29500.01'; $esi = new EsiResponse($data, [], 'now', 200); $serialized = serialize($esi); $esi = unserialize($serialized); $this->assertInstanceOf(EsiResponse::class, $esi); } public function testEsiResponseSerializableObjectResponse() { $data = '{"foo": "bar"}'; $esi = new EsiResponse($data, [], 'now', 200); $serialized = serialize($esi); $esi = unserialize($serialized); $this->assertInstanceOf(EsiResponse::class, $esi); } public function testEsiResponseSerializableArrayResponse() { $data = '[1, 2, 3, 4, 5, 6, 7, 8]'; $esi = new EsiResponse($data, [], 'now', 200); $serialized = serialize($esi); $esi = unserialize($serialized); $this->assertInstanceOf(EsiResponse::class, $esi); } public function testEsiResponseSerializableArrayObjectResponse() { $data = '[{"id": 646465444, "amount": 6546546.33}, {"id": 6568794131, "amount": 464657896584.17}]'; $esi = new EsiResponse($data, [], 'now', 200); $serialized = serialize($esi); $esi = unserialize($serialized); $this->assertInstanceOf(EsiResponse::class, $esi); } public function testEsiResponseCanGetErrorCode() { $this->assertEquals(200, $this->esi_response->getErrorCode()); } public function testEsiResponseCanGetDataValue() { $this->assertEquals('Foo', $this->esi_response->name); } public function testEsiResponseCanGetNestedDataValue() { $this->assertEquals('yes', $this->esi_response->details->human); } public function testEsiResponseCanGetRawDataFromContainer() { $this->assertEquals('{"name":"Foo","details":{"age":40,"human":"yes"}}', $this->esi_response->raw); } public function testEsiResponseCanGetRawResponseHeaders() { $this->assertEquals($this->headers, $this->esi_response->raw_headers); } public function testEsiResponseCanGetParseHeaderValue() { $this->assertEquals('Content-Type,Authorization,X-User-Agent', $this->esi_response->headers['Access-Control-Allow-Headers']); } public function testEsiResponseCanGetParsedPagesFromHeaders() { $this->assertEquals(4, $this->esi_response->pages); } public function testEsiResponseCanGetParsedErrorLomitFromHeaders() { $this->assertEquals(64, $this->esi_response->error_limit); } public function testEsiResponseIsNotCachedByDefault() { $this->assertFalse($this->esi_response->isCachedLoad()); } public function testEsiResponseMarksResponseAsCached() { $this->esi_response->setIsCachedload(); $this->assertTrue($this->esi_response->isCachedLoad()); } public function testEsiResponseCanSetExpires() { $old_expires = $this->esi_response->expires(); $new_expires = carbon()->addHour(); $this->esi_response->setExpires($new_expires); $this->assertNotEquals($old_expires, $this->esi_response->expires()); $this->assertNotEquals($old_expires->toRfc7231String(), $this->esi_response->getHeader('expires')); } }