コード例 #1
0
 /**
  *
  */
 public function testRegisterPluginsWithDifferentPrioritiesTestAndUnRegisterPlugin()
 {
     $this->client->setPluginManager(new PluginManager($this->client));
     static::assertInstanceOf('\\frankmayer\\ArangoDbPhpCore\\Plugins\\PluginManager', $this->client->getPluginManager());
     $tracer = new TestPlugin();
     $tracer->priority = 0;
     $tracer2 = new TestPlugin();
     $tracer2->priority = 20;
     $tracer3 = new TestPlugin();
     $tracer3->priority = -30;
     $tracer4 = new TestPlugin();
     $tracer4->priority = 20;
     $this->clientOptions['plugins'] = ['tracer1' => $tracer, 'tracer2' => $tracer2, 'tracer3' => $tracer3, 'tracer4' => $tracer4];
     $this->client->setPluginsFromPluginArray($this->clientOptions['plugins']);
     static::assertArrayHasKey('tracer3', $this->client->pluginManager->pluginStorage);
     $e = null;
     try {
         $this->client->setPluginsFromPluginArray(['tracer5' => new \stdClass()]);
     } catch (\Exception $e) {
     }
     static::assertInstanceOf('\\Exception', $e);
     /** @var $responseObject HttpResponse */
     $collection = new Collection($this->client);
     /** @var $responseObject HttpResponse */
     $responseObject = $collection->getAll();
     static::assertInstanceOf('frankmayer\\ArangoDbPhpCore\\Protocols\\Http\\HttpRequestInterface', $responseObject->request);
 }
コード例 #2
0
 public function testFailureWhenRegisteringNonPlugin()
 {
     $this->client->setPluginManager(new PluginManager($this->client));
     $e = null;
     try {
         $this->client->setPluginsFromPluginArray(['tracer5' => new \stdClass()]);
     } catch (\Exception $e) {
     }
     $this->assertInstanceOf('\\Exception', $e);
 }
コード例 #3
0
 /**
  *
  */
 public function setUp()
 {
     $connector = new Connector();
     $this->connector = $connector;
     $this->client = getClient($connector);
     $this->client->bind('Request', function () {
         $request = $this->client->getRequest();
         return $request;
     });
 }
コード例 #4
0
 /**
  * @throws ClientException
  */
 public function testBindAndMakeHttpResponsePlusGettersSetters()
 {
     $this->request = $this->client->make('Request');
     $this->request->path = '/_admin/version';
     $this->request->method = HttpRequest::METHOD_GET;
     $this->request->send();
     $this->client->bind('Response', function () {
         $request = $this->client->getResponse();
         return $request;
     });
     // And here's how one gets an HttpRequest object through the IOC.
     // Note that the type-name 'httpRequest' is the name we bound our HttpRequest class creation-closure to. (see above)
     $this->response = $this->client->make('Response');
     $this->response->build($this->request);
     //        echo get_class($this->request);
     $this->assertInstanceOf('frankmayer\\ArangoDbPhpCore\\Protocols\\Http\\HttpResponseInterface', $this->response);
     $decodedBody = json_decode($this->response->body, true);
     $this->assertSame($decodedBody['server'], 'arango');
     $this->assertAttributeEmpty('protocol', $this->response);
     // test verboseExtractStatusLine
     $this->response = $this->client->make('Response');
     $this->response->verboseExtractStatusLine = true;
     $this->response->build($this->request);
     $this->assertAttributeNotEmpty('protocol', $this->response);
     $testValue = $this->response->getBatch();
     $this->assertEmpty($testValue);
     $this->response->setBatch(true);
     $testValue = $this->response->getBatch();
     $this->assertTrue($testValue);
     $testValue = $this->response->getBody();
     $this->assertNotEmpty($testValue);
     $this->response->setBody('testBody');
     $testValue = $this->response->getBody();
     $this->assertEquals('testBody', $testValue);
     $testValue = $this->response->getHeaders();
     $this->assertNotEmpty($testValue);
     $this->response->setHeaders('testHeaders');
     $testValue = $this->response->getHeaders();
     $this->assertEquals('testHeaders', $testValue);
     $testValue = $this->response->getRequest();
     $this->assertInternalType('object', $testValue);
     $this->response->setRequest($testValue);
     $testValue = $this->response->getRequest();
     $this->assertInternalType('object', $testValue);
     $testValue = $this->response->getStatus();
     $this->assertNotEmpty($testValue);
     $this->response->setStatus(202);
     $testValue = $this->response->getStatus();
     $this->assertEquals(202, $testValue);
     $testValue = $this->response->getProtocol();
     $this->assertEquals('HTTP/1.1', $testValue);
     $testValue = $this->response->getStatusPhrase();
     $this->assertEquals('OK', $testValue);
     $testValue = $this->response->getVerboseExtractStatusLine();
     $this->assertEquals(true, $testValue);
     $this->response->setVerboseExtractStatusLine(false);
     $testValue = $this->response->getVerboseExtractStatusLine();
     $this->assertEquals(false, $testValue);
 }
コード例 #5
0
 /**
  * Test if we can get the server version
  */
 public function testDeleteDatabaseWithoutApiClasses()
 {
     $databaseName = 'ArangoDB-PHP-Core-DatabaseTestSuite-Database';
     $databaseOptions = [];
     $options = $databaseOptions;
     $this->client->bind('Request', function () {
         return $this->client->getRequest();
     });
     $request = $this->client->make('Request');
     $request->options = $options;
     $request->path = $this->client->fullDatabasePath . self::API_DATABASE . '/' . $databaseName;
     $request->method = self::METHOD_DELETE;
     $responseObject = $request->send();
     $body = $responseObject->body;
     static::assertArrayHasKey('code', json_decode($body, true));
     $decodedJsonBody = json_decode($body, true);
     static::assertEquals(200, $decodedJsonBody['code']);
 }
コード例 #6
0
 /**
  * Test if we can get the server version
  */
 public function testDeleteCollectionWithoutApiClasses()
 {
     $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-Collection';
     $collectionOptions = ['waitForSync' => true];
     $options = $collectionOptions;
     $this->client->bind('Request', function () {
         return $this->client->getRequest();
     });
     $request = $this->client->make('Request');
     $request->options = $options;
     $request->path = $this->client->fullDatabasePath . self::API_COLLECTION . '/' . $collectionName;
     $request->method = self::METHOD_DELETE;
     $responseObject = $request->send();
     $body = $responseObject->body;
     static::assertArrayHasKey('code', json_decode($body, true));
     $decodedJsonBody = json_decode($body, true);
     static::assertEquals(200, $decodedJsonBody['code']);
 }
コード例 #7
0
 /**
  * Test if we can get the server version
  */
 public function testSync()
 {
     $collectionParameters = [];
     $this->client->bind('Request', function () {
         return $this->client->getRequest();
     });
     $query = 'RETURN SLEEP(1)';
     $statement = ['query' => $query];
     // And here's how one gets an HttpRequest object through the IOC.
     // Note that the type-name 'httpRequest' is the name we bound our HttpRequest class creation-closure to. (see above)
     $request = $this->client->make('Request');
     $request->body = $statement;
     //        $request->connectorOptions = ['future' => true];
     $request->body = self::array_merge_recursive_distinct($request->body, $collectionParameters);
     $request->body = json_encode($request->body);
     $request->path = $this->client->fullDatabasePath . self::URL_CURSOR;
     $request->method = self::METHOD_POST;
     $responseObject = $request->send();
     $body = $responseObject->body;
     static::assertArrayHasKey('code', json_decode($body, true));
     $decodedJsonBody = json_decode($body, true);
     static::assertEquals(201, $decodedJsonBody['code']);
 }
コード例 #8
0
 /**
  * @throws ClientException
  */
 public function tearDown()
 {
     $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-Collection';
     $collectionOptions = ["waitForSync" => true];
     $options = $collectionOptions;
     $this->client->bind('Request', function () {
         $request = $this->client->getRequest();
         return $request;
     });
     $request = $this->client->make('Request');
     $request->options = $options;
     $request->path = $this->client->fullDatabasePath . self::API_COLLECTION . '/' . $collectionName;
     $request->method = self::METHOD_DELETE;
     /** @var HttpResponse $responseObject */
     $responseObject = $request->send();
     $body = $responseObject->body;
     $this->assertArrayHasKey('code', json_decode($body, true));
     $decodedJsonBody = json_decode($body, true);
     $this->assertEquals(200, $decodedJsonBody['code']);
     $collectionName = 'ArangoDB-PHP-Core-CollectionTestSuite-NonExistingCollection';
     $collection = new Collection($this->client);
     /** @var $responseObject HttpResponse */
     $collection->drop($collectionName);
 }
コード例 #9
0
 /**
  *
  */
 public function testSetGetResponseClass()
 {
     $client = new Client($this->connector, getClientOptions());
     $responseClass = new HttpResponse();
     $client->setResponseClass($responseClass);
     $this->assertEquals($responseClass, $client->getResponseClass());
 }