/**
  *
  */
 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 testCreateCollection()
    {
        $createCollectionResponse = <<<TAG
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
location: /_db/_system/_api/collection/testCollectionBasics

{
  "id" : "1372591952",
  "name" : "testCollectionBasics",
  "waitForSync" : false,
  "isVolatile" : false,
  "isSystem" : false,
  "status" : 3,
  "type" : 2,
  "error" : false,
  "code" : 200
}
TAG;
        $options = ['waitForSync' => true];
        $this->connector->method('request')->willReturn($createCollectionResponse);
        $object = new Collection($this->client);
        /** @var $responseObject HttpResponse */
        $response = $object->create($this->collectionNames[0], $options);
        $this->assertInstanceOf('\\frankmayer\\ArangoDbPhpCore\\Protocols\\Http\\HttpResponse', $response);
        $this->assertEquals(200, $response->status);
    }
예제 #3
0
 /**
  * Test if we can get the server version
  */
 public function testCreateCollectionInBatchAndDeleteThemAgainInBatch()
 {
     $collectionOptions = ['waitForSync' => true];
     $batchParts = [];
     foreach ($this->collectionNames as $collectionName) {
         $collection = new Collection($this->client);
         /** @var $responseObject HttpResponse */
         $batchPart = $collection->create($collectionName, $collectionOptions, ['isBatchPart' => true]);
         $batchParts[] = $batchPart;
     }
     /** @var HttpResponse $responseObject */
     $batch = new Batch($this->client);
     $responseObject = $batch->send($this->client, $batchParts);
     $this->assertEquals(200, $responseObject->status);
     $batchResponseParts = $responseObject->batch;
     /** @var $batchPart HttpResponse */
     foreach ($batchResponseParts as $batchPart) {
         $body = $batchPart->body;
         $this->assertArrayHasKey('code', json_decode($body, true));
         $decodedJsonBody = json_decode($body, true);
         $this->assertEquals(200, $decodedJsonBody['code']);
     }
     $batchParts = [];
     foreach ($this->collectionNames as $collectionName) {
         $collection = new Collection($this->client);
         /** @var $responseObject HttpResponse */
         $batchParts[] = $collection->drop($collectionName, ['isBatchPart' => true]);
     }
     $batch = new Batch($this->client);
     $responseObject = $batch->send($this->client, $batchParts);
     $batchResponseParts = $responseObject->batch;
     foreach ($batchResponseParts as $batchPart) {
         $body = $batchPart->body;
         $this->assertArrayHasKey('code', json_decode($body, true));
         $decodedJsonBody = json_decode($body, true);
         $this->assertEquals(200, $decodedJsonBody['code']);
     }
 }
 /**
  * Test if we can get the server version
  */
 public function testCreateCollectionViaIocContainer()
 {
     $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;
     $this->assertArrayHasKey('code', json_decode($body, true));
     $decodedJsonBody = json_decode($body, true);
     $this->assertEquals(200, $decodedJsonBody['code']);
     $this->assertEquals($collectionName, $decodedJsonBody['name']);
 }
 /**
  *
  */
 public function testBuildBatchResponseAndSplitHeadersAndBodies()
 {
     $collectionOptions = ['waitForSync' => true];
     $batchRequests = [];
     foreach ($this->collectionNames as $collectionName) {
         $collection = new Collection($this->client);
         /** @var $responseObject HttpResponse */
         $batchRequest = $collection->create($collectionName, $collectionOptions, ['isBatchPart' => true]);
         //            $this->assertEquals(202, $batchRequest->status);
         $batchRequests[] = $batchRequest;
     }
     $this->batch = new Batch($this->client);
     $batchResponse = $this->batch->send($this->client, $batchRequests);
     // check that contentId property return correct value
     foreach ($batchResponse->batch as $key => $batchPartResponseObject) {
         $this->assertEquals($key + 1, $batchPartResponseObject->batchContentId);
     }
 }