Skip to content

Commit

Permalink
refactor: Fix Psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Nov 25, 2024
1 parent 5306c17 commit dfb7eff
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/Bolt/BoltDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Laudis\Neo4j\Bolt;

use Bolt\error\ConnectException;
use Exception;

use function is_string;
Expand Down Expand Up @@ -104,7 +105,7 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
try {
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
} catch (ConnectException $e) {
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
$this->pool->getLogger()?->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/DriverSetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function verifyConnectivity(SessionConfiguration $config, ?string $alias
try {
$this->getDriver($config, $alias);
} catch (ConnectException $e) {
$this->getLogger()->log(
$this->getLogger()?->log(
LogLevel::WARNING,
sprintf('Could not connect to server using alias (%s)', $alias ?? '<default>'),
['exception' => $e]
Expand Down
2 changes: 1 addition & 1 deletion src/Neo4j/Neo4jDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
try {
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
} catch (ConnectException $e) {
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
$this->pool->getLogger()?->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);

return false;
}
Expand Down
48 changes: 36 additions & 12 deletions tests/Integration/ClientIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use ReflectionClass;
use RuntimeException;

final class ClientIntegrationTest extends EnvironmentAwareIntegrationTest
{
public function testDriverAuthFailureVerifyConnectivity(): void
{
$connection = $_ENV['CONNECTION'] ?? false;
if (str_starts_with($connection, 'http')) {
if (str_starts_with((string) $connection, 'http')) {
$this->markTestSkipped('HTTP does not support auth failure connectivity passing');
}

Expand All @@ -61,14 +62,16 @@ public function testDriverAuthFailureVerifyConnectivity(): void
$driver = Driver::create($uri, $conf);

$this->expectException(Neo4jException::class);
$this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."');
$this->expectExceptionMessage(
'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."'
);
$driver->verifyConnectivity();
}

public function testClientAuthFailureVerifyConnectivity(): void
{
$connection = $_ENV['CONNECTION'] ?? false;
if (str_starts_with($connection, 'http')) {
if (str_starts_with((string) $connection, 'http')) {
$this->markTestSkipped('HTTP does not support auth failure connectivity passing');
}

Expand Down Expand Up @@ -100,7 +103,9 @@ public function testClientAuthFailureVerifyConnectivity(): void
$driver = $client->getDriver(null);

$this->expectException(Neo4jException::class);
$this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."');
$this->expectExceptionMessage(
'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."'
);
$driver->verifyConnectivity();
}

Expand Down Expand Up @@ -128,28 +133,37 @@ public function testAvailabilityFullImplementation(): void

public function testTransactionFunction(): void
{
$result = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
$result = $this->getSession()->transaction(
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
);

self::assertEquals(1, $result);

$result = $this->getSession()->readTransaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
$result = $this->getSession()->readTransaction(
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
);

self::assertEquals(1, $result);

$result = $this->getSession()->writeTransaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
$result = $this->getSession()->writeTransaction(
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
);

self::assertEquals(1, $result);
}

public function testValidRun(): void
{
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run(<<<'CYPHER'
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run(
<<<'CYPHER'
MERGE (x:TestNode {test: $test})
WITH x
MERGE (y:OtherTestNode {test: $otherTest})
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
RETURN x, y, x.test AS test, map, list
CYPHER, ['test' => 'a', 'otherTest' => 'b']));
CYPHER,
['test' => 'a', 'otherTest' => 'b']
));

self::assertEquals(1, $response->count());
$map = $response->first();
Expand All @@ -164,7 +178,12 @@ public function testValidRun(): void
public function testInvalidRun(): void
{
$this->expectException(Neo4jException::class);
$this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run('MERGE (x:Tes0342hdm21.())', ['test' => 'a', 'otherTest' => 'b']));
$this->getSession()->transaction(
static fn (TransactionInterface $tsx) => $tsx->run(
'MERGE (x:Tes0342hdm21.())',
['test' => 'a', 'otherTest' => 'b']
)
);
}

public function testInvalidRunRetry(): void
Expand All @@ -183,13 +202,18 @@ public function testInvalidRunRetry(): void

public function testValidStatement(): void
{
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->runStatement(Statement::create(<<<'CYPHER'
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->runStatement(
Statement::create(
<<<'CYPHER'
MERGE (x:TestNode {test: $test})
WITH x
MERGE (y:OtherTestNode {test: $otherTest})
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
RETURN x, y, x.test AS test, map, list
CYPHER, ['test' => 'a', 'otherTest' => 'b'])));
CYPHER,
['test' => 'a', 'otherTest' => 'b']
)
));

self::assertEquals(1, $response->count());
$map = $response->first();
Expand Down

0 comments on commit dfb7eff

Please sign in to comment.