/** * Test if we can get the server version */ public function testCreateGetListGetDocumentAndDeleteDocumentInExistingCollection() { $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-Collection'; $requestBody = ['name' => 'frank', '_key' => '1']; $document = new Document($this->client); /** @var HttpResponse $responseObject */ $responseObject = $document->create($collectionName, $requestBody); $responseBody = $responseObject->body; $decodedJsonBody = json_decode($responseBody, true); $this->assertArrayNotHasKey('error', $decodedJsonBody); $this->assertEquals($collectionName . '/1', $decodedJsonBody['_id']); $responseObject = $document->getAll($collectionName); $responseBody = $responseObject->body; $this->assertArrayHasKey('documents', json_decode($responseBody, true)); $decodedJsonBody = json_decode($responseBody, true); $this->assertEquals('/_api/document/ArangoDB-PHP-Core-CollectionTestSuite-Collection/1', $decodedJsonBody['documents'][0]); $responseObject = $document->delete($collectionName . '/1'); $responseBody = $responseObject->body; $decodedJsonBody = json_decode($responseBody, true); $this->assertArrayNotHasKey('error', $decodedJsonBody); // Try to delete a second time .. should throw an error $responseObject = $document->delete($collectionName . '/1'); $responseBody = $responseObject->body; $decodedJsonBody = json_decode($responseBody, true); $this->assertArrayHasKey('error', $decodedJsonBody); $this->assertEquals(true, $decodedJsonBody['error']); $decodedJsonBody = json_decode($responseBody, true); $this->assertEquals(true, $decodedJsonBody['error']); $this->assertEquals(404, $decodedJsonBody['code']); $this->assertEquals(1202, $decodedJsonBody['errorNum']); }
/** * */ public function testGetAllDocuments() { $deleteCollectionResponse = <<<TAG HTTP/1.1 200 OK content-type: application/json; charset=utf-8 { "documents" : [ "/_api/document/products/1495340880", "/_api/document/products/1494685520", "/_api/document/products/1495013200" ] } TAG; $options = ['excludeSystem' => true]; $this->connector->method('request')->willReturn($deleteCollectionResponse); $object = new Document($this->client); /** @var $responseObject HttpResponse */ $response = $object->getAll($this->collectionNames[0], $options); $this->assertInstanceOf('\\frankmayer\\ArangoDbPhpCore\\Protocols\\Http\\HttpResponse', $response); $this->assertEquals(200, $response->status); }