|
4 | 4 |
|
5 | 5 | use ArangoClient\Admin\AdminManager;
|
6 | 6 | use ArangoClient\ArangoClient;
|
| 7 | +use ArangoClient\Http\HttpClientConfig; |
7 | 8 | use ArangoClient\Schema\SchemaManager;
|
8 | 9 | use ArangoClient\Statement\Statement;
|
9 | 10 | use GuzzleHttp\Client;
|
| 11 | +use GuzzleHttp\Client as GuzzleClient; |
10 | 12 | use GuzzleHttp\Handler\MockHandler;
|
11 | 13 | use GuzzleHttp\HandlerStack;
|
12 | 14 | use GuzzleHttp\Middleware;
|
13 | 15 | use GuzzleHttp\Psr7\Response;
|
14 | 16 |
|
| 17 | +use function PHPUnit\Framework\assertTrue; |
| 18 | + |
15 | 19 | uses(Tests\TestCase::class);
|
16 | 20 |
|
17 | 21 | test('get config', function () {
|
|
46 | 50 | test('client with host port config', function () {
|
47 | 51 | $config = [
|
48 | 52 | 'host' => 'http://127.0.0.1',
|
49 |
| - 'port' => '1234', |
| 53 | + 'port' => '8529', |
50 | 54 | 'username' => 'root',
|
51 | 55 | ];
|
52 | 56 | $client = new ArangoClient($config);
|
53 | 57 | $retrievedConfig = $client->getConfig();
|
54 | 58 |
|
55 |
| - expect($retrievedConfig['endpoint'])->toEqual('http://127.0.0.1:1234'); |
| 59 | + expect($retrievedConfig['endpoint'])->toEqual('http://127.0.0.1:8529'); |
56 | 60 | });
|
57 | 61 |
|
58 | 62 | test('config with alien properties', function () {
|
59 | 63 | $config = [
|
60 | 64 | 'name' => 'arangodb',
|
61 | 65 | 'driver' => 'arangodb',
|
62 | 66 | 'host' => 'http://127.0.0.1',
|
63 |
| - 'port' => '1234', |
| 67 | + 'port' => '8529', |
64 | 68 | 'username' => 'root',
|
65 | 69 | ];
|
66 | 70 | $client = new ArangoClient($config);
|
|
73 | 77 | test('set and get http client', function () {
|
74 | 78 | $oldClient = $this->arangoClient->getHttpClient();
|
75 | 79 |
|
76 |
| - $newClient = Mockery::mock(Client::class); |
| 80 | + $defaultConfig = [ |
| 81 | + 'endpoint' => 'http://localhost:8529', |
| 82 | + 'host' => null, |
| 83 | + 'port' => null, |
| 84 | + 'version' => 1.1, |
| 85 | + 'connection' => 'Keep-Alive', |
| 86 | + 'allow_redirects' => false, |
| 87 | + 'connect_timeout' => 0.0, |
| 88 | + 'username' => 'root', |
| 89 | + 'password' => null, |
| 90 | + 'database' => $this->testDatabaseName, |
| 91 | + 'jsonStreamDecoderThreshold' => 1048576, |
| 92 | + ]; |
| 93 | + |
| 94 | + $config = new HttpClientConfig($defaultConfig); |
| 95 | + |
| 96 | + $newClient = new GuzzleClient($config->mapGuzzleHttpClientConfig()); |
| 97 | + |
77 | 98 | $this->arangoClient->setHttpClient($newClient);
|
| 99 | + |
78 | 100 | $retrievedClient = $this->arangoClient->getHttpClient();
|
79 | 101 |
|
80 | 102 | expect($oldClient)->toBeInstanceOf(Client::class);
|
|
89 | 111 | expect($result->version)->toBeString();
|
90 | 112 | });
|
91 | 113 |
|
| 114 | + |
| 115 | +test('rawRequest', function () { |
| 116 | + $response = $this->arangoClient->rawRequest('get', '/_api/version', []); |
| 117 | + |
| 118 | + expect($response->getStatusCode())->toBe(200); |
| 119 | + expect($response->getHeader('Connection')[0])->toBe('Keep-Alive'); |
| 120 | +}); |
| 121 | + |
92 | 122 | test('get user', function () {
|
93 | 123 | $user = $this->arangoClient->getUser();
|
94 | 124 | expect($user)->toBe('root');
|
|
103 | 133 |
|
104 | 134 | $database = $this->arangoClient->getDatabase();
|
105 | 135 | expect($database)->toBe($newDatabaseName);
|
| 136 | + |
| 137 | + // Reset DB name |
| 138 | + $this->arangoClient->setDatabase($this->testDatabaseName); |
106 | 139 | });
|
107 | 140 |
|
108 | 141 | test('database name is used in requests', function () {
|
109 |
| - $database = 'some_database'; |
| 142 | + $database = 'arangodb_php_client__test'; |
110 | 143 | if (!$this->arangoClient->schema()->hasDatabase($database)) {
|
111 | 144 | $this->arangoClient->schema()->createDatabase($database);
|
112 | 145 | }
|
|
234 | 267 |
|
235 | 268 | $this->schemaManager->deleteCollection($collection);
|
236 | 269 | });
|
| 270 | + |
| 271 | + |
| 272 | +test('connect', function () { |
| 273 | + $oldHttpClient = $this->arangoClient->getHttpClient(); |
| 274 | + $oldHttpClientObjectId = spl_object_id($oldHttpClient); |
| 275 | + |
| 276 | + $newConfig = [ |
| 277 | + 'endpoint' => 'http://localhost:8529', |
| 278 | + 'version' => 2, |
| 279 | + 'connection' => 'Close', |
| 280 | + 'username' => 'root', |
| 281 | + 'password' => null, |
| 282 | + 'database' => $this->testDatabaseName, |
| 283 | + 'jsonStreamDecoderThreshold' => 1048576, |
| 284 | + ]; |
| 285 | + |
| 286 | + $response = $this->arangoClient->connect($newConfig); |
| 287 | + |
| 288 | + $newHttpClient = $this->arangoClient->getHttpClient(); |
| 289 | + $newHttpClientObjectId = spl_object_id($newHttpClient); |
| 290 | + |
| 291 | + expect($oldHttpClientObjectId)->not()->toBe($newHttpClientObjectId); |
| 292 | + expect($response)->toBeTrue(); |
| 293 | + |
| 294 | + $this->arangoClient->setHttpClient($oldHttpClient); |
| 295 | +}); |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | +test('disconnect', function () { |
| 300 | + $disconnected = $this->arangoClient->disconnect(); |
| 301 | + |
| 302 | + assertTrue($disconnected); |
| 303 | +}); |
0 commit comments