Skip to content

Commit 7eeaaf2

Browse files
committed
made environment variables more flexible during tests
1 parent 537bb7c commit 7eeaaf2

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

tests/Integration/BasicDriverTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Laudis\Neo4j\Tests\Integration;
1313

14+
use Dotenv\Dotenv;
1415
use function explode;
1516
use function is_string;
1617
use Laudis\Neo4j\Basic\Driver;
@@ -27,7 +28,12 @@ public function getConnections(): array
2728
/** @var string|mixed $connections */
2829
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
2930
if (!is_string($connections)) {
30-
$connections = 'bolt://neo4j:test@neo4j,neo4j://neo4j:test@core1,http://neo4j:test@neo4j';
31+
Dotenv::createImmutable(__DIR__ . '/../../')->load();
32+
/** @var string|mixed $connections */
33+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
34+
if (!is_string($connections)) {
35+
$connections = 'bolt://neo4j:test@neo4j,neo4j://neo4j:test@core1,http://neo4j:test@neo4j';
36+
}
3137
}
3238

3339
$tbr = [];

tests/Integration/BoltDriverIntegrationTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Laudis\Neo4j\Tests\Integration;
1515

1616
use Bolt\error\ConnectException;
17+
use Dotenv\Dotenv;
1718
use Exception;
1819
use Laudis\Neo4j\Bolt\BoltDriver;
1920
use Laudis\Neo4j\Common\Uri;
@@ -22,31 +23,45 @@
2223

2324
final class BoltDriverIntegrationTest extends TestCase
2425
{
25-
private UriInterface $uri;
26+
private ?UriInterface $uri;
2627

2728
protected function setUp(): void
2829
{
2930
parent::setUp();
3031
$this->uri = $this->getBoltUri();
3132
}
3233

33-
private function getBoltUri(): UriInterface
34+
private function getBoltUri(): ?UriInterface
3435
{
35-
foreach (explode(',', (string) getenv('NEO4J_CONNECTIONS')) as $uri) {
36+
/** @var string|mixed $connections */
37+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
38+
if (!is_string($connections)) {
39+
Dotenv::createImmutable(__DIR__ . '/../../')->load();
40+
/** @var string|mixed $connections */
41+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
42+
if (!is_string($connections)) {
43+
$connections = 'bolt://neo4j:test@neo4j,neo4j://neo4j:test@core1,http://neo4j:test@neo4j';
44+
}
45+
}
46+
foreach (explode(',', $connections) as $uri) {
3647
$psrUri = Uri::create($uri);
3748
if ($psrUri->getScheme() === 'bolt') {
3849
return $psrUri;
3950
}
4051
}
4152

42-
return Uri::create('bolt://neo4j:test@neo4j');
53+
return null;
4354
}
4455

4556
/**
4657
* @throws Exception
4758
*/
4859
public function testValidHostname(): void
4960
{
61+
if ($this->uri === null) {
62+
self::markTestSkipped('No bolt uri provided');
63+
}
64+
5065
$results = BoltDriver::create($this->uri->__toString())->createSession()->run(<<<'CYPHER'
5166
RETURN 1 AS x
5267
CYPHER);
@@ -58,6 +73,10 @@ public function testValidHostname(): void
5873
*/
5974
public function testValidUrl(): void
6075
{
76+
if ($this->uri === null) {
77+
self::markTestSkipped('No bolt uri provided');
78+
}
79+
6180
$ip = gethostbyname($this->uri->getHost());
6281
$results = BoltDriver::create($this->uri->withHost($ip)->__toString())->createSession()->run(<<<'CYPHER'
6382
RETURN 1 AS x

tests/Integration/ClientBuilderTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,42 @@
1313

1414
namespace Laudis\Neo4j\Tests\Integration;
1515

16+
use Dotenv\Dotenv;
1617
use function explode;
17-
use function getenv;
1818
use Laudis\Neo4j\ClientBuilder;
1919
use Laudis\Neo4j\Common\Uri;
2020
use PHPUnit\Framework\TestCase;
2121

2222
final class ClientBuilderTest extends TestCase
2323
{
24-
private function getBoltUri(): string
24+
private function getBoltUri(): ?string
2525
{
26-
foreach (explode(',', (string) getenv('NEO4J_CONNECTIONS')) as $uri) {
26+
/** @var string|mixed $connections */
27+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
28+
if (!is_string($connections)) {
29+
Dotenv::createImmutable(__DIR__ . '/../../')->load();
30+
/** @var string|mixed $connections */
31+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
32+
if (!is_string($connections)) {
33+
$connections = '';
34+
}
35+
}
36+
foreach (explode(',', $connections) as $uri) {
2737
$psrUri = Uri::create($uri);
2838
if ($psrUri->getScheme() === 'bolt') {
2939
return $psrUri->__toString();
3040
}
3141
}
3242

33-
return 'bolt://neo4j:test@neo4j:7687';
43+
return null;
3444
}
3545

3646
public function testBoltSetupWithScheme(): void
3747
{
48+
if ($this->getBoltUri() === null) {
49+
self::markTestSkipped('No bolt uri provided');
50+
}
51+
3852
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
3953
$tsx = $client->beginTransaction();
4054
self::assertTrue(true);
@@ -43,6 +57,10 @@ public function testBoltSetupWithScheme(): void
4357

4458
public function testBoltSetupWithoutPort(): void
4559
{
60+
if ($this->getBoltUri() === null) {
61+
self::markTestSkipped('No bolt uri provided');
62+
}
63+
4664
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
4765
$tsx = $client->beginTransaction();
4866
self::assertTrue(true);
@@ -51,6 +69,10 @@ public function testBoltSetupWithoutPort(): void
5169

5270
public function testBoltSetupWrongScheme(): void
5371
{
72+
if ($this->getBoltUri() === null) {
73+
self::markTestSkipped('No bolt uri provided');
74+
}
75+
5476
$client = ClientBuilder::create()->addBoltConnection('bolt', $this->getBoltUri())->build();
5577
$tsx = $client->beginTransaction();
5678
self::assertTrue(true);

tests/Integration/EnvironmentAwareIntegrationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ protected static function buildConnections(): array
8888
{
8989
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
9090
if (!is_string($connections)) {
91-
return ['bolt://neo4j:test@neo4j', 'neo4j://neo4j:test@core1', 'http://neo4j:test@neo4j'];
91+
Dotenv::createImmutable(__DIR__ . '/../../')->load();
92+
/** @var string|mixed $connections */
93+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
94+
if (!is_string($connections)) {
95+
return ['bolt://neo4j:test@neo4j', 'neo4j://neo4j:test@core1', 'http://neo4j:test@neo4j'];
96+
}
9297
}
9398

9499
return explode(',', $connections);

0 commit comments

Comments
 (0)