Skip to content

Commit

Permalink
fixes phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
transistive committed Mar 28, 2024
1 parent 1ecbd9e commit ffdaf5b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
- uses: php-actions/composer@v6
with:
progress: yes
php_version: 8.2
php_version: 8.1
version: 2
- uses: php-actions/phpunit@v3
with:
configuration: phpunit.xml.dist
php_version: 8.2
php_version: 8.1
memory_limit: 1024M
version: 9
version: 10
testsuite: Unit
bootstrap: vendor/autoload.php
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ composer.lock
.env
/docs/_build
cachegrind.out.*
.phpunit.cache/
35 changes: 16 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<phpunit colors="true" verbose="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="Integration">
<directory>./tests/Integration</directory>
</testsuite>
<testsuite name="Performance">
<directory>./tests/Performance</directory>
</testsuite>
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687" />
</php>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Integration">
<directory>./tests/Integration</directory>
</testsuite>
<testsuite name="Performance">
<directory>./tests/Performance</directory>
</testsuite>
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687"/>
</php>
</phpunit>
16 changes: 10 additions & 6 deletions src/Bolt/BoltConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,18 @@ public function pull(?int $qid, ?int $fetchSize): array

public function __destruct()
{
if ($this->protocol()->serverState === ServerState::FAILED && $this->isOpen()) {
if ($this->protocol()->serverState === ServerState::STREAMING || $this->protocol()->serverState === ServerState::TX_STREAMING) {
$this->consumeResults();
}
try {
if ($this->boltProtocol->serverState === ServerState::FAILED && $this->isOpen()) {
if ($this->protocol()->serverState === ServerState::STREAMING || $this->protocol()->serverState === ServerState::TX_STREAMING) {
$this->consumeResults();
}

$this->protocol()->goodbye();

$this->protocol()->goodbye();
unset($this->boltProtocol); // has to be set to null as the sockets don't recover nicely contrary to what the underlying code might lead you to believe;
}
} catch (\Throwable) {

unset($this->boltProtocol); // has to be set to null as the sockets don't recover nicely contrary to what the underlying code might lead you to believe;
}
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/BoltConnectionPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Laudis\Neo4j\Tests\Unit;

use Bolt\protocol\V5;
use Generator;
use Laudis\Neo4j\Authentication\Authenticate;
use Laudis\Neo4j\Bolt\BoltConnection;
Expand Down Expand Up @@ -147,8 +148,12 @@ private function setupPool(Generator $semaphoreGenerator): void
->willReturn($semaphoreGenerator);

$this->factory = $this->createMock(BoltFactory::class);
$boltConnection = $this->createMock(BoltConnection::class);
$boltConnection->method('protocol')->willReturn($this->createMock(V5::class));
$this->factory->method('createConnection')
->willReturn($this->createMock(BoltConnection::class));
->willReturn($boltConnection);
$this->factory->method('reuseConnection')
->willReturnCallback(fn (MockObject $x): MockObject => $x);

$this->pool = new ConnectionPool(
$this->semaphore, $this->factory, new ConnectionRequestData(
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/DNSAddressResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void

public function testResolverGhlenDotCom(): void
{
$records = iterator_to_array($this->resolver->getAddresses('test.ghlen.com'));
$records = iterator_to_array($this->resolver->getAddresses('test.ghlen.com'), false);

$this->assertEqualsCanonicalizing(['test.ghlen.com', '123.123.123.123', '123.123.123.124'], $records);
$this->assertNotEmpty($records);
Expand All @@ -37,15 +37,15 @@ public function testResolverGhlenDotCom(): void

public function testResolverGoogleDotComReverse(): void
{
$records = iterator_to_array($this->resolver->getAddresses('8.8.8.8'));
$records = iterator_to_array($this->resolver->getAddresses('8.8.8.8'), false);

$this->assertNotEmpty($records);
$this->assertContains('8.8.8.8', $records);
}

public function testBogus(): void
{
$addresses = iterator_to_array($this->resolver->getAddresses('bogus'));
$this->assertEquals('bogus', $addresses);
$addresses = iterator_to_array($this->resolver->getAddresses('bogus'), false);
$this->assertEquals(['bogus'], $addresses);
}
}

0 comments on commit ffdaf5b

Please sign in to comment.