Skip to content

Commit 89a6821

Browse files
committed
greenlit tests
1 parent 6c07765 commit 89a6821

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

src/Bolt.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class Bolt
4848
/**
4949
* @var array
5050
*/
51-
private $versions = [4.1, 4, 3];
51+
private $versions = [4.3, 4.2, 4.1, 4, 3];
5252

5353
/**
5454
* @var float
@@ -138,7 +138,7 @@ private function handshake(): bool
138138
echo 'HANDSHAKE';
139139

140140
$this->connection->write(chr(0x60) . chr(0x60) . chr(0xb0) . chr(0x17));
141-
$this->connection->write($this->packProtocolVersions());
141+
$this->connection->write(chr(0x00) . chr(0x03) . chr(0x03) . chr(0x04) . chr(0x00) . chr(0x00) . chr(0x01) . chr(0x04) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x04) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x03));
142142

143143
$this->unpackProtocolVersion();
144144
if (empty($this->version)) {
@@ -396,14 +396,15 @@ public function __destruct()
396396
*
397397
* @param array|null $routing
398398
*
399-
* @return array|null
399+
* @return array{rt: array{servers: list<array{addresses: list<string>, role: 'WRITE'|'READ'|'ROUTE'}>, ttl: int}}|null
400400
*/
401401
public function route(?array $routing = null): ?array
402402
{
403403
if (!method_exists($this->protocol, 'route')) {
404404
return null;
405405
}
406406

407+
$routing = $routing ?? ['address' => $this->connection->getIp() . ':' . $this->connection->getPort()];
407408
return $this->protocol->route($routing);
408409
}
409410
}

src/connection/AConnection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ protected function printHex(string $str, bool $write = true)
5656
}
5757
echo '</pre>';
5858
}
59+
60+
public function getIp(): string
61+
{
62+
return $this->ip;
63+
}
64+
65+
public function getPort(): int
66+
{
67+
return $this->port;
68+
}
69+
70+
public function getTimeout(): float
71+
{
72+
return $this->timeout;
73+
}
5974
}

src/connection/IConnection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ public function write(string $buffer);
2525
public function read(int $length = 2048): string;
2626

2727
public function disconnect();
28+
29+
public function getIp(): string;
30+
31+
public function getPort(): int;
32+
33+
public function getTimeout(): float;
2834
}

src/connection/Socket.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,4 @@ public function disconnect()
125125
@socket_close($this->socket);
126126
}
127127
}
128-
129128
}

src/protocol/V4_3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
class V4_3 extends V4_1
1818
{
19-
public function route(?array $routing = null): array
19+
public function route(array $routing, ?array $bookmarks = null, ?string $database=null): array
2020
{
21-
$this->write($this->packer->pack(0x66, $routing ?? []));
21+
$this->write($this->packer->pack(0x66, (object) $routing, $bookmarks ?? [], $database));
2222

2323
$signature = 0;
2424
$output = $this->read($signature);

tests/BoltTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Bolt\tests;
44

55
use Bolt\Bolt;
6+
use Bolt\protocol\V4_3;
67
use Exception;
78

89
/**
@@ -165,4 +166,20 @@ private function formatParameter(Bolt $bolt, string $name): string
165166
return self::$parameterType ? ('{' . $name . '}') : ('$' . $name);
166167
}
167168

169+
170+
171+
/**
172+
* @depends testHello
173+
* @param Bolt $bolt
174+
*/
175+
public function testRoute(Bolt $bolt): void
176+
{
177+
$version = $bolt->getProtocolVersion();
178+
if ($version >= 4.3) {
179+
$route = $bolt->route();
180+
self::assertNotEmpty($route);
181+
} else {
182+
self::assertNull($bolt->route());
183+
}
184+
}
168185
}

tests/protocol/V4_3Test.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,4 @@ public function test__construct()
2929
return $cls;
3030
}
3131

32-
/**
33-
* @return V4_3
34-
*/
35-
public function testRoute(): void
36-
{
37-
$v4_3 = $this->test__construct();
38-
39-
self::assertEquals([], $v4_3->route());
40-
}
41-
4232
}

0 commit comments

Comments
 (0)