Skip to content

Commit ffdaf5b

Browse files
committed
fixes phpunit
1 parent 1ecbd9e commit ffdaf5b

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

.github/workflows/unit-test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ jobs:
2323
- uses: php-actions/composer@v6
2424
with:
2525
progress: yes
26-
php_version: 8.2
26+
php_version: 8.1
2727
version: 2
2828
- uses: php-actions/phpunit@v3
2929
with:
3030
configuration: phpunit.xml.dist
31-
php_version: 8.2
31+
php_version: 8.1
3232
memory_limit: 1024M
33-
version: 9
33+
version: 10
3434
testsuite: Unit
3535
bootstrap: vendor/autoload.php

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ composer.lock
1313
.env
1414
/docs/_build
1515
cachegrind.out.*
16+
.phpunit.cache/

phpunit.xml.dist

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
<phpunit colors="true" verbose="true"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
convertDeprecationsToExceptions="true"
5-
>
6-
<testsuites>
7-
<testsuite name="Integration">
8-
<directory>./tests/Integration</directory>
9-
</testsuite>
10-
<testsuite name="Performance">
11-
<directory>./tests/Performance</directory>
12-
</testsuite>
13-
<testsuite name="Unit">
14-
<directory>./tests/Unit</directory>
15-
</testsuite>
16-
</testsuites>
17-
<php>
18-
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687" />
19-
</php>
1+
<?xml version="1.0"?>
2+
<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">
3+
<testsuites>
4+
<testsuite name="Integration">
5+
<directory>./tests/Integration</directory>
6+
</testsuite>
7+
<testsuite name="Performance">
8+
<directory>./tests/Performance</directory>
9+
</testsuite>
10+
<testsuite name="Unit">
11+
<directory>./tests/Unit</directory>
12+
</testsuite>
13+
</testsuites>
14+
<php>
15+
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687"/>
16+
</php>
2017
</phpunit>

src/Bolt/BoltConnection.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,18 @@ public function pull(?int $qid, ?int $fetchSize): array
284284

285285
public function __destruct()
286286
{
287-
if ($this->protocol()->serverState === ServerState::FAILED && $this->isOpen()) {
288-
if ($this->protocol()->serverState === ServerState::STREAMING || $this->protocol()->serverState === ServerState::TX_STREAMING) {
289-
$this->consumeResults();
290-
}
287+
try {
288+
if ($this->boltProtocol->serverState === ServerState::FAILED && $this->isOpen()) {
289+
if ($this->protocol()->serverState === ServerState::STREAMING || $this->protocol()->serverState === ServerState::TX_STREAMING) {
290+
$this->consumeResults();
291+
}
292+
293+
$this->protocol()->goodbye();
291294

292-
$this->protocol()->goodbye();
295+
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;
296+
}
297+
} catch (\Throwable) {
293298

294-
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;
295299
}
296300
}
297301

tests/Unit/BoltConnectionPoolTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Tests\Unit;
1515

16+
use Bolt\protocol\V5;
1617
use Generator;
1718
use Laudis\Neo4j\Authentication\Authenticate;
1819
use Laudis\Neo4j\Bolt\BoltConnection;
@@ -147,8 +148,12 @@ private function setupPool(Generator $semaphoreGenerator): void
147148
->willReturn($semaphoreGenerator);
148149

149150
$this->factory = $this->createMock(BoltFactory::class);
151+
$boltConnection = $this->createMock(BoltConnection::class);
152+
$boltConnection->method('protocol')->willReturn($this->createMock(V5::class));
150153
$this->factory->method('createConnection')
151-
->willReturn($this->createMock(BoltConnection::class));
154+
->willReturn($boltConnection);
155+
$this->factory->method('reuseConnection')
156+
->willReturnCallback(fn (MockObject $x): MockObject => $x);
152157

153158
$this->pool = new ConnectionPool(
154159
$this->semaphore, $this->factory, new ConnectionRequestData(

tests/Unit/DNSAddressResolverTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828

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

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

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

4242
$this->assertNotEmpty($records);
4343
$this->assertContains('8.8.8.8', $records);
4444
}
4545

4646
public function testBogus(): void
4747
{
48-
$addresses = iterator_to_array($this->resolver->getAddresses('bogus'));
49-
$this->assertEquals('bogus', $addresses);
48+
$addresses = iterator_to_array($this->resolver->getAddresses('bogus'), false);
49+
$this->assertEquals(['bogus'], $addresses);
5050
}
5151
}

0 commit comments

Comments
 (0)