Skip to content

Commit d904acf

Browse files
fix: host/port endpoint configuration
test: added tests for transactionManager getter/setter.
1 parent f47ec0f commit d904acf

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/ArangoClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function generateEndpoint(array $config): string
6161
$endpoint = (string) $config['host'];
6262
}
6363
if (isset($config['port'])) {
64-
$endpoint .= (string) $config['port'];
64+
$endpoint .= ':' . (string) $config['port'];
6565
}
6666

6767
return $endpoint;

src/Http/HttpClientConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class HttpClientConfig extends DataTransferObject
2121
*/
2222
public string $endpoint = 'http://localhost:8529';
2323

24+
/**
25+
* @var string|null
26+
*/
27+
public ?string $host = null;
28+
29+
/**
30+
* @var string|int|null
31+
*/
32+
public $port = null;
33+
2434
/**
2535
* @var float|int
2636
*/

tests/ArangoClientTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function testGetConfig()
2121
{
2222
$defaultConfig = [
2323
'endpoint' => 'http://localhost:8529',
24+
'host' => null,
25+
'port' => null,
2426
'version' => 1.1,
2527
'connection' => 'Keep-Alive',
2628
'allow_redirects' => false,
@@ -34,6 +36,18 @@ public function testGetConfig()
3436
$this->assertSame($defaultConfig, $config);
3537
}
3638

39+
public function testClientWithHostPortConfig()
40+
{
41+
$config = [
42+
'host' => 'http://127.0.0.1',
43+
'port' => '1234',
44+
'username' => 'root',
45+
];
46+
$client = new ArangoClient($config);
47+
$retrievedConfig = $client->getConfig();
48+
49+
$this->assertEquals('http://127.0.0.1:1234', $retrievedConfig['endpoint']);
50+
}
3751

3852
public function testSetAndGetHttpClient()
3953
{

tests/SupportsTransactionsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,16 @@ public function testCommit()
107107
$this->arangoClient->schema()->deleteCollection('Users');
108108
$this->arangoClient->schema()->deleteCollection('Customers');
109109
}
110+
111+
public function testTransactionManagerSetterAndGetter()
112+
{
113+
$oldTransactionManager = $this->arangoClient->getTransactionManager();
114+
$newTransactionManager = new TransactionManager($this->arangoClient);
115+
$this->arangoClient->setTransactionManager($newTransactionManager);
116+
$retrievedNewTransactionManager = $this->arangoClient->getTransactionManager();
117+
118+
$this->assertNull($oldTransactionManager);
119+
$this->assertEquals(spl_object_id($newTransactionManager), spl_object_id($retrievedNewTransactionManager));
120+
121+
}
110122
}

0 commit comments

Comments
 (0)