/** * */ public function setUp() { $connector = new Connector(); $this->connector = $connector; $this->client = getClient($connector); $this->client->bind('Request', function () { $request = $this->client->getRequest(); return $request; }); }
/** * @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); }
/** * 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']); }
/** * 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']); }
/** * 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']); }
/** * @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); }