Skip to content

Commit 2b266b8

Browse files
moved structures to protocol. added new protocol version structures. moved Bytes as data type into PackStream. updated tests.
1 parent 26f7af1 commit 2b266b8

File tree

18 files changed

+586
-226
lines changed

18 files changed

+586
-226
lines changed

.github/workflows/db-test-php-7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
neo4j-version: ["4.3", "4.4"]
16+
neo4j-version: ["4.3", "4.4", "5.0", "5.1"]
1717
php-version: ['7.4']
1818

1919
services:

.github/workflows/db-test-php-8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
neo4j-version: ["4.3", "4.4"]
16+
neo4j-version: ["4.3", "4.4", "5.0", "5.1"]
1717
php-version: ['8.0', '8.1']
1818

1919
services:

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<file>./tests/BoltTest.php</file>
77
<directory>./tests/error</directory>
88
<directory>./tests/PackStream</directory>
9+
<directory>./tests/structures</directory>
910
</testsuite>
1011
<testsuite name="NoDatabase">
1112
<directory>./tests/protocol</directory>

src/Bolt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class Bolt
3434
public function __construct(IConnection $connection)
3535
{
3636
$this->connection = $connection;
37-
$this->setProtocolVersions(4.4, 4.3, 4.2, 3);
37+
$this->setProtocolVersions(5.1, 5.0, 4.4, 4.3);
3838
$this->setPackStreamVersion();
3939
}
4040

tests/BoltTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
* @covers \Bolt\protocol\ServerState
2929
*
3030
* @package Bolt\tests
31-
* @requires PHP >= 7.1
32-
* @requires extension sockets
33-
* @requires extension mbstring
3431
*/
3532
class BoltTest extends TestCase
3633
{

tests/PackStream/v1/BytesTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Bolt\tests\PackStream\v1;
4+
5+
use Bolt\Bolt;
6+
use Bolt\PackStream\Bytes;
7+
use Bolt\protocol\AProtocol;
8+
use Bolt\protocol\Response;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Class BytesTest
13+
* @package Bolt\tests\PackStream\v1
14+
*/
15+
class BytesTest extends TestCase
16+
{
17+
public function testInit(): AProtocol
18+
{
19+
$conn = new \Bolt\connection\StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', $GLOBALS['NEO_PORT'] ?? 7687);
20+
$this->assertInstanceOf(\Bolt\connection\StreamSocket::class, $conn);
21+
22+
$bolt = new Bolt($conn);
23+
$this->assertInstanceOf(Bolt::class, $bolt);
24+
25+
$protocol = $bolt->build();
26+
$this->assertInstanceOf(AProtocol::class, $protocol);
27+
28+
$this->assertEquals(Response::SIGNATURE_SUCCESS, $protocol->hello(\Bolt\helpers\Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']))->getSignature());
29+
30+
return $protocol;
31+
}
32+
33+
/**
34+
* @depends testInit
35+
* @dataProvider providerBytes
36+
* @param Bytes $arr
37+
* @param AProtocol $protocol
38+
*/
39+
public function testBytes(Bytes $arr, AProtocol $protocol)
40+
{
41+
$res = iterator_to_array(
42+
$protocol
43+
->run('RETURN $arr', ['arr' => $arr])
44+
->pull()
45+
->getResponses(),
46+
false
47+
);
48+
$this->assertEquals($arr, $res[1]->getContent()[0]);
49+
}
50+
51+
public function providerBytes(): \Generator
52+
{
53+
foreach ([1, 200, 60000, 70000] as $size) {
54+
$arr = new Bytes();
55+
while (count($arr) < $size) {
56+
$arr[] = pack('H', mt_rand(0, 255));
57+
}
58+
yield 'bytes: ' . count($arr) => [$arr];
59+
}
60+
}
61+
}

tests/PackStream/v1/PackerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
* @covers \Bolt\PackStream\v1\Packer
1717
*
1818
* @package Bolt\tests\PackStream\v1
19-
* @requires PHP >= 7.1
20-
* @requires extension mbstring
21-
* @requires extension json
2219
*/
2320
class PackerTest extends TestCase
2421
{

tests/PackStream/v1/UnpackerTest.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
* @covers \Bolt\PackStream\v1\Unpacker
1818
*
1919
* @package Bolt\tests\PackStream\v1
20-
* @requires PHP >= 7.1
21-
* @requires extension mbstring
22-
* @requires extension json
2320
*/
2421
class UnpackerTest extends TestCase
2522
{
@@ -31,7 +28,6 @@ public function testInit(): AProtocol
3128
$bolt = new Bolt($conn);
3229
$this->assertInstanceOf(Bolt::class, $bolt);
3330

34-
/** @var AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol */
3531
$protocol = $bolt->build();
3632
$this->assertInstanceOf(AProtocol::class, $protocol);
3733

@@ -43,7 +39,7 @@ public function testInit(): AProtocol
4339

4440
/**
4541
* @depends testInit
46-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
42+
* @param AProtocol $protocol
4743
*/
4844
public function testNull(AProtocol $protocol)
4945
{
@@ -61,7 +57,7 @@ public function testNull(AProtocol $protocol)
6157

6258
/**
6359
* @depends testInit
64-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
60+
* @param AProtocol $protocol
6561
*/
6662
public function testBoolean(AProtocol $protocol)
6763
{
@@ -81,7 +77,7 @@ public function testBoolean(AProtocol $protocol)
8177

8278
/**
8379
* @depends testInit
84-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
80+
* @param AProtocol $protocol
8581
*/
8682
public function testInteger(AProtocol $protocol)
8783
{
@@ -102,7 +98,7 @@ public function testInteger(AProtocol $protocol)
10298

10399
/**
104100
* @depends testInit
105-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
101+
* @param AProtocol $protocol
106102
*/
107103
public function testFloat(AProtocol $protocol)
108104
{
@@ -127,7 +123,7 @@ public function testFloat(AProtocol $protocol)
127123
* @depends testInit
128124
* @dataProvider stringProvider
129125
* @param string $str
130-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
126+
* @param AProtocol $protocol
131127
*/
132128
public function testString(string $str, AProtocol $protocol)
133129
{
@@ -162,7 +158,7 @@ private function randomString(int $length): string
162158
* @depends testInit
163159
* @dataProvider listProvider
164160
* @param int $size
165-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
161+
* @param AProtocol $protocol
166162
*/
167163
public function testList(int $size, AProtocol $protocol)
168164
{
@@ -190,10 +186,21 @@ public function listProvider(): \Generator
190186
* @dataProvider dictionaryProvider
191187
* @param string $query
192188
* @param int $size
193-
* @param AProtocol|\Bolt\protocol\V4_3|\Bolt\protocol\V4_4 $protocol
189+
* @param AProtocol $protocol
194190
*/
195191
public function testDictionary(string $query, int $size, AProtocol $protocol)
196192
{
193+
$apocRequest = iterator_to_array(
194+
$protocol
195+
->run('SHOW PROCEDURES YIELD name WHERE name STARTS WITH "apoc." RETURN count(*) > 0 AS apoc')
196+
->pull()
197+
->getResponses(),
198+
false
199+
);
200+
if (!$apocRequest[1]->getContent()[0]) {
201+
$this->markTestSkipped('Neo4j not running with apoc');
202+
}
203+
197204
$gen = $protocol
198205
->run($query, [], ['mode' => 'r'])
199206
->pull()
@@ -203,6 +210,8 @@ public function testDictionary(string $query, int $size, AProtocol $protocol)
203210
foreach ($gen as $response) {
204211
if ($response->getSignature() == Response::SIGNATURE_RECORD) {
205212
$this->assertCount($size, $response->getContent()[0]);
213+
} elseif ($response->getSignature() == Response::SIGNATURE_FAILURE) {
214+
$this->markTestIncomplete(print_r($response->getContent(), true));
206215
}
207216
}
208217
}

tests/connection/ConnectionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* @covers \Bolt\connection\StreamSocket
2424
*
2525
* @package Bolt\tests\connection
26-
* @requires PHP >= 7.1
27-
* @requires extension sockets
2826
*/
2927
final class ConnectionTest extends TestCase
3028
{

tests/error/ErrorsTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
* @covers \Bolt\error\UnpackException
1717
*
1818
* @package Bolt\tests
19-
* @requires PHP >= 7.1
20-
* @requires extension sockets
21-
* @requires extension mbstring
2219
*/
2320
class ErrorsTest extends TestCase
2421
{

0 commit comments

Comments
 (0)