Skip to content

Commit

Permalink
setup tests and bugfix for configuration parameter passing
Browse files Browse the repository at this point in the history
  • Loading branch information
transistive committed Dec 4, 2023
1 parent fb7a468 commit b8e7662
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 172 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ x-definitions:
build:
context: .
dockerfile: Dockerfile
image: neo4j-php-client:latest
# image: neo4j-php-client:latest
volumes:
- .:/opt/project
x-common-cluster:
Expand Down
171 changes: 1 addition & 170 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,171 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Authentication/Authenticate.php">
<PossiblyUndefinedIntArrayOffset>
<code>$pass</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Bolt/SslConfigurationFactory.php">
<LessSpecificReturnStatement>
<code><![CDATA[[$sslConfig, $this->enableSsl($uri->getHost(), $sslConfig, $config)]]]></code>
<code>[$sslConfig, []]</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[array{0: 's'|'ssc'|'', 1: array{verify_peer?: bool, peer_name?: string, SNI_enabled?: bool, allow_self_signed?: bool}}]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Common/SysVSemaphore.php">
<InvalidArgument>
<code><![CDATA[$this->semaphore]]></code>
<code><![CDATA[$this->semaphore]]></code>
<code>sem_get(hexdec($key), $max)</code>
</InvalidArgument>
</file>
<file src="src/Databags/DatabaseInfo.php">
<MissingTemplateParam>
<code>DatabaseInfo</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/Plan.php">
<MissingTemplateParam>
<code>Plan</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/ProfiledPlan.php">
<MissingTemplateParam>
<code>ProfiledPlan</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/ResultSummary.php">
<MissingTemplateParam>
<code>ResultSummary</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/ServerInfo.php">
<MissingTemplateParam>
<code>ServerInfo</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/Statement.php">
<MissingTemplateParam>
<code>Statement</code>
</MissingTemplateParam>
</file>
<file src="src/Databags/SummaryCounters.php">
<MissingTemplateParam>
<code>SummaryCounters</code>
</MissingTemplateParam>
</file>
<file src="src/Formatter/BasicFormatter.php">
<ImplementedParamTypeMismatch>
<code>$meta</code>
</ImplementedParamTypeMismatch>
</file>
<file src="src/Formatter/Specialised/JoltHttpOGMTranslator.php">
<PossiblyUndefinedArrayOffset>
<code>$coordinates</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="src/Formatter/Specialised/LegacyHttpOGMTranslator.php">
<ArgumentTypeCoercion>
<code>$value</code>
<code>$value</code>
</ArgumentTypeCoercion>
<InvalidReturnStatement>
<code><![CDATA[$this->translateCypherList($value, $meta)]]></code>
<code>[new CypherList($tbr), $meta]</code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>array{0: OGMTypes, 1: HttpMetaInfo}</code>
</InvalidReturnType>
<PossiblyUndefinedIntArrayOffset>
<code>$milliseconds</code>
<code>$milliseconds</code>
<code>$secondsFraction</code>
<code>$time</code>
<code>$time</code>
<code>$timezone</code>
<code>$tzMinutes</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Formatter/SummarizedResultFormatter.php">
<InvalidArgument>
<code>$response</code>
</InvalidArgument>
<InvalidArrayOffset>
<code><![CDATA[$response['db']]]></code>
</InvalidArrayOffset>
</file>
<file src="src/Types/Abstract3DPoint.php">
<ImplementedReturnTypeMismatch>
<code>array{x: float, y: float, z: float, srid: int, crs: Crs}</code>
</ImplementedReturnTypeMismatch>
</file>
<file src="src/Types/AbstractCypherSequence.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->keyCache]]></code>
<code><![CDATA[$this->keyCache]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="src/Types/AbstractPoint.php">
<MissingTemplateParam>
<code>AbstractPoint</code>
</MissingTemplateParam>
</file>
<file src="src/Types/ArrayList.php">
<ImplementedReturnTypeMismatch>
<code><![CDATA[static<TValue|NewValue>]]></code>
</ImplementedReturnTypeMismatch>
</file>
<file src="src/Types/Map.php">
<ImplementedReturnTypeMismatch>
<code><![CDATA[static<TValue|NewValue>]]></code>
</ImplementedReturnTypeMismatch>
</file>
<file src="tests/Unit/CypherListTest.php">
<NoValue>
<code>$item</code>
</NoValue>
<UnevaluatedCode>
<code>++$counter;</code>
<code>self::assertEquals(0, $counter);</code>
<code><![CDATA[self::assertEquals(['A', 'B', 'C'][$key], $item);]]></code>
</UnevaluatedCode>
<UnusedVariable>
<code>$counter</code>
<code>$key</code>
</UnusedVariable>
</file>
<file src="tests/Unit/CypherMapTest.php">
<MissingTemplateParam>
<code>IteratorAggregate</code>
</MissingTemplateParam>
<NoValue>
<code>$item</code>
</NoValue>
<UnevaluatedCode>
<code>++$counter;</code>
<code>self::assertEquals(0, $counter);</code>
<code><![CDATA[self::assertEquals(['A' => 'x'][$key], $item);]]></code>
</UnevaluatedCode>
<UnusedVariable>
<code>$counter</code>
<code>$key</code>
</UnusedVariable>
</file>
<file src="tests/Unit/DNSAddressResolverTest.php">
<InvalidOperand>
<code><![CDATA[$this->resolver->getAddresses('8.8.8.8')]]></code>
<code><![CDATA[$this->resolver->getAddresses('bogus')]]></code>
<code><![CDATA[$this->resolver->getAddresses('test.ghlen.com')]]></code>
</InvalidOperand>
<NoValue>
<code>$records</code>
</NoValue>
</file>
<file src="tests/Unit/ParameterHelperTest.php">
<MissingTemplateParam>
<code>Iterator</code>
</MissingTemplateParam>
</file>
</files>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352"/>
15 changes: 15 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ public function __construct(
private TransactionConfiguration $defaultTransactionConfiguration
) {}

public function getDriverSetups(): DriverSetupManager
{
return $this->driverSetups;
}

public function getDefaultSessionConfiguration(): SessionConfiguration
{
return $this->defaultSessionConfiguration;
}

public function getDefaultTransactionConfiguration(): TransactionConfiguration
{
return $this->defaultTransactionConfiguration;
}

public function run(string $statement, iterable $parameters = [], ?string $alias = null)
{
return $this->runStatement(Statement::create($statement, $parameters), $alias);
Expand Down
3 changes: 2 additions & 1 deletion src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public function build(): ClientInterface
public function withDefaultDriverConfiguration(DriverConfiguration $config): self
{
$tbr = clone $this;
$tbr->defaultDriverConfig = $config;

$tbr->driverSetups = $tbr->driverSetups->withDriverConfiguration($config);

return $tbr;
}
Expand Down
14 changes: 14 additions & 0 deletions src/Common/DriverSetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public function __construct(
private DriverConfiguration $configuration
) {}

public function getDriverConfiguration(): DriverConfiguration
{
return $this->configuration;
}

public function withDriverConfiguration(DriverConfiguration $config): self
{
$tbr = clone $this;

$tbr->configuration = $config;

return $tbr;
}

/**
* @psalm-mutation-free
*/
Expand Down
48 changes: 48 additions & 0 deletions tests/Integration/ClientBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Neo4j PHP Client and Driver package.
*
* (c) Nagels <https://nagels.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Integration;

use Laudis\Neo4j\Client;
use Laudis\Neo4j\ClientBuilder;
use Laudis\Neo4j\Databags\DriverConfiguration;
use Laudis\Neo4j\Databags\SessionConfiguration;
use Laudis\Neo4j\Databags\SslConfiguration;
use Laudis\Neo4j\Databags\TransactionConfiguration;
use Laudis\Neo4j\Enum\SslMode;
use PHPUnit\Framework\TestCase;

class ClientBuilderTest extends TestCase
{
public function testGetClient(): void
{
$sslConfig = SslConfiguration::default()->withVerifyPeer(false)->withMode(SslMode::FROM_URL());
$driverconfig = DriverConfiguration::default()
->withSslConfiguration($sslConfig)
->withMaxPoolSize(4096)
->withAcquireConnectionTimeout(2.5);
$sessionConfig = SessionConfiguration::default()->withDatabase('neo4j');
$transactionConfig = TransactionConfiguration::default()->withTimeout(120.0);
$client = ClientBuilder::create()
->withDefaultDriverConfiguration($driverconfig)
->withDefaultSessionConfiguration($sessionConfig)
->withDefaultTransactionConfiguration($transactionConfig)
->build();

self::assertInstanceOf(Client::class, $client);
self::assertEquals($driverconfig, $client->getDriverSetups()->getDriverConfiguration());
self::assertEquals($sslConfig, $client->getDriverSetups()->getDriverConfiguration()->getSslConfiguration());
self::assertEquals($sessionConfig, $client->getDefaultSessionConfiguration());
self::assertEquals($transactionConfig, $client->getDefaultTransactionConfiguration());
}
}

0 comments on commit b8e7662

Please sign in to comment.