Skip to content

Commit ac26865

Browse files
committed
fixed .env dependency in tests
1 parent 8bdf0d6 commit ac26865

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

tests/Integration/BoltDriverIntegrationTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,32 @@
1616
use Bolt\error\ConnectException;
1717
use Exception;
1818
use Laudis\Neo4j\Bolt\BoltDriver;
19+
use Laudis\Neo4j\Common\Uri;
1920
use PHPUnit\Framework\TestCase;
21+
use Psr\Http\Message\UriInterface;
2022

2123
final class BoltDriverIntegrationTest extends TestCase
2224
{
25+
private UriInterface $uri;
26+
27+
protected function setUp(): void
28+
{
29+
parent::setUp();
30+
$this->uri = $this->getBoltUri();
31+
}
32+
33+
private function getBoltUri(): UriInterface
34+
{
35+
foreach (explode(',', (string) getenv('NEO4J_CONNECTIONS')) as $uri) {
36+
$psrUri = Uri::create($uri);
37+
if ($psrUri->getScheme() === 'bolt') {
38+
return $psrUri;
39+
}
40+
}
41+
42+
return Uri::create('bolt://neo4j:test@neo4j');
43+
}
44+
2345
/**
2446
* @throws Exception
2547
*/
@@ -36,8 +58,8 @@ public function testValidHostname(): void
3658
*/
3759
public function testValidUrl(): void
3860
{
39-
$ip = gethostbyname('neo4j');
40-
$results = BoltDriver::create('bolt://neo4j:test@'.$ip)->createSession()->run(<<<'CYPHER'
61+
$ip = gethostbyname($this->uri->getHost());
62+
$results = BoltDriver::create($this->uri->withHost($ip)->__toString())->createSession()->run(<<<'CYPHER'
4163
RETURN 1 AS x
4264
CYPHER);
4365
self::assertEquals(1, $results->first()->get('x'));

tests/Unit/ClientBuilderTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,45 @@
1414
namespace Laudis\Neo4j\Tests\Unit;
1515

1616
use Laudis\Neo4j\ClientBuilder;
17+
use Laudis\Neo4j\Common\Uri;
1718
use PHPUnit\Framework\TestCase;
19+
use Psr\Http\Message\UriInterface;
20+
use function explode;
21+
use function getenv;
1822

1923
final class ClientBuilderTest extends TestCase
2024
{
25+
private function getBoltUri(): string
26+
{
27+
foreach (explode(',', (string) getenv('NEO4J_CONNECTIONS')) as $uri) {
28+
$psrUri = Uri::create($uri);
29+
if ($psrUri->getScheme() === 'bolt') {
30+
return $psrUri->__toString();
31+
}
32+
}
33+
34+
return 'bolt://neo4j:test@neo4j:7687';
35+
}
36+
2137
public function testBoltSetupWithScheme(): void
2238
{
23-
$client = ClientBuilder::create()->addBoltConnection('bolt', 'bolt://neo4j:test@neo4j:7687')->build();
39+
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
2440
$tsx = $client->beginTransaction();
2541
self::assertTrue(true);
2642
$tsx->rollback();
2743
}
2844

2945
public function testBoltSetupWithoutPort(): void
3046
{
31-
$client = ClientBuilder::create()->addBoltConnection('bolt', 'bolt://neo4j:test@neo4j')->build();
47+
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
3248
$tsx = $client->beginTransaction();
3349
self::assertTrue(true);
3450
$tsx->rollback();
3551
}
3652

3753
public function testBoltSetupWrongScheme(): void
3854
{
39-
$client = ClientBuilder::create()->addBoltConnection('bolt', 'neo4j://neo4j:test@neo4j:7687')->build();
55+
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
4056
$tsx = $client->beginTransaction();
4157
self::assertTrue(true);
4258
$tsx->rollback();

0 commit comments

Comments
 (0)