/** * */ public function testCreateCollectionAndStoredAsyncDocumentCreation() { $job = new Async($this->client); $job->deleteJobResult('all'); // todo 1 Frank Write real test for deleting job results with stamp $job->deleteJobResult('all', time()); $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-Collection'; $collectionOptions = ['waitForSync' => true]; $collection = new Collection($this->client); /** @var $responseObject HttpResponse */ $responseObject = $collection->create($collectionName, $collectionOptions); $body = $responseObject->body; $decodedJsonBody = json_decode($body, true); static::assertEquals(200, $decodedJsonBody['code']); static::assertEquals($collectionName, $decodedJsonBody['name']); $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-Collection'; $requestBody = ['name' => 'frank', '_key' => '1']; $document = new Document($this->client); $responseObject = $document->create($collectionName, $requestBody, null, ['async' => 'store']); static::assertEquals(202, $responseObject->status); sleep(1); $jobId = $responseObject->headers['X-Arango-Async-Id'][0]; $jobList = $job->listJobResults('done', 1); $jobArray = json_decode($jobList->body, true); static::assertTrue(in_array($jobId, $jobArray, true)); $jobResult = $job->fetchJobResult($responseObject->headers['X-Arango-Async-Id'][0]); static::assertSame($jobResult->headers['X-Arango-Async-Id'], $responseObject->headers['X-Arango-Async-Id']); static::assertArrayHasKey('X-Arango-Async-Id', $jobResult->headers); $document = new Document($this->client); $responseObject = $document->get($collectionName . '/1', $requestBody); $responseBody = $responseObject->body; $decodedJsonBody = json_decode($responseBody, true); static::assertEquals($collectionName . '/1', $decodedJsonBody['_id']); }
/** * */ public function testListJobResults() { $deleteCollectionResponse = <<<TAG HTTP/1.1 200 OK content-type: application/json; charset=utf-8 [ "270459873" ] TAG; $options = ['waitForSync' => true]; $this->connector->method('request')->willReturn($deleteCollectionResponse); $object = new Async($this->client); /** @var $responseObject HttpResponse */ $response = $object->listJobResults('done'); $this->assertInstanceOf('\\frankmayer\\ArangoDbPhpCore\\Protocols\\Http\\HttpResponse', $response); $this->assertEquals(200, $response->status); }