Skip to content

Commit

Permalink
feat: Make EnvironmentAwareIntegrationTest non-static
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Oct 4, 2024
1 parent 7765e11 commit 907d539
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions tests/EnvironmentAwareIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use RuntimeException;

abstract class EnvironmentAwareIntegrationTest extends TestCase
{
private static bool $isSetUp = false;
protected static Session $session;
protected static Driver $driver;
protected static Uri $uri;
protected static Neo4jLogger $logger;
protected Session $session;
protected Driver $driver;
protected Uri $uri;
protected Neo4jLogger $logger;

public function setUp(): void
{
Expand All @@ -41,17 +41,16 @@ public function setUp(): void
$connection = 'bolt://localhost';
}

if (self::$isSetUp) {
return;
}

/** @noinspection PhpUnhandledExceptionInspection */
$conf = DriverConfiguration::default()->withLogger(LogLevel::DEBUG, $this->createMock(LoggerInterface::class));
self::$logger = $conf->getLogger();
self::$uri = Uri::create($connection);
self::$driver = Driver::create(self::$uri, $conf);
self::$session = self::$driver->createSession();
self::$isSetUp = true;
$logger = $conf->getLogger();
if ($logger === null) {
throw new RuntimeException('Logger not set');
}
$this->logger = $logger;
$this->uri = Uri::create($connection);
$this->driver = Driver::create($this->uri, $conf);
$this->session = $this->driver->createSession();
}

/**
Expand All @@ -61,7 +60,7 @@ public function getSession(array|string|null $forceScheme = null): Session
{
$this->skipUnsupportedScheme($forceScheme);

return self::$session;
return $this->session;
}

/**
Expand All @@ -71,7 +70,7 @@ public function getUri(array|string|null $forceScheme = null): Uri
{
$this->skipUnsupportedScheme($forceScheme);

return self::$uri;
return $this->uri;
}

/**
Expand All @@ -94,7 +93,7 @@ private function skipUnsupportedScheme(array|string|null $forceScheme): void
$options[] = $scheme.'+ssc';
}

if (!in_array(self::$uri->getScheme(), $options)) {
if (!in_array($this->uri->getScheme(), $options)) {
/** @psalm-suppress MixedArgumentTypeCoercion */
$this->markTestSkipped(sprintf(
'Connection only for types: "%s"',
Expand All @@ -110,11 +109,11 @@ protected function getDriver(array|string|null $forceScheme = null): Driver
{
$this->skipUnsupportedScheme($forceScheme);

return self::$driver;
return $this->driver;
}

protected function getNeo4jLogger(): Neo4jLogger
{
return self::$logger;
return $this->logger;
}
}

0 comments on commit 907d539

Please sign in to comment.