Skip to content

Commit 9e391eb

Browse files
Merge pull request #29 from stefanak-michal/phpunit
Phpunit
2 parents 034be7c + ccb2bd2 commit 9e391eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1186
-37
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
2-
2+
.vscode/
3+
phpunit*.phar

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"ext-sockets": "*",
1313
"ext-mbstring": "*"
1414
},
15+
"require-dev": {
16+
"phpunit/phpunit": ">=7.5.0"
17+
},
1518
"support": {
1619
"issues": "https://github.com/stefanak-michal/Bolt/issues",
1720
"source": "https://github.com/stefanak-michal/Bolt"
@@ -30,7 +33,7 @@
3033
],
3134
"autoload": {
3235
"psr-4": {
33-
"Bolt\\": "/"
36+
"Bolt\\": "src/"
3437
}
3538
}
3639
}

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @link https://github.com/stefanak-michal/Bolt
99
*/
1010

11-
require_once 'autoload.php';
11+
require_once 'src' . DIRECTORY_SEPARATOR . 'autoload.php';
1212

1313
set_time_limit(3);
1414

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<phpunit bootstrap="src/autoload.php">
2+
<testsuites>
3+
<testsuite name="Bolt">
4+
<directory>tests</directory>
5+
</testsuite>
6+
</testsuites>
7+
<php>
8+
<var name="NEO_USER" value="neo4j"/>
9+
<var name="NEO_PASS" value="nothing"/>
10+
</php>
11+
<filter>
12+
<whitelist>
13+
<directory suffix=".php">connection</directory>
14+
<directory suffix=".php">PackStream</directory>
15+
<directory suffix=".php">protocol</directory>
16+
<file>Bolt.php</file>
17+
</whitelist>
18+
</filter>
19+
</phpunit>

Bolt.php renamed to src/Bolt.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Bolt\PackStream\{IPacker, IUnpacker};
77
use Bolt\protocol\AProtocol;
8+
use Bolt\connection\IConnection;
89

910
/**
1011
* Main class Bolt
@@ -32,9 +33,9 @@ final class Bolt
3233
private $protocol;
3334

3435
/**
35-
* @var Socket
36+
* @var IConnection
3637
*/
37-
private $socket;
38+
private $connection;
3839

3940
/**
4041
* @var array
@@ -77,7 +78,7 @@ final class Bolt
7778
*/
7879
public function __construct(string $ip = '127.0.0.1', int $port = 7687, int $timeout = 15)
7980
{
80-
$this->socket = new Socket($ip, $port, $timeout);
81+
$this->connection = new \Bolt\connection\Socket($ip, $port, $timeout);
8182

8283
$packerClass = "\\Bolt\\PackStream\\v" . $this->packStreamVersion . "\\Packer";
8384
if (!class_exists($packerClass)) {
@@ -142,8 +143,8 @@ private function handshake(): bool
142143
if (self::$debug)
143144
echo 'HANDSHAKE';
144145

145-
$this->socket->write(chr(0x60) . chr(0x60) . chr(0xb0) . chr(0x17));
146-
$this->socket->write($this->packProtocolVersions());
146+
$this->connection->write(chr(0x60) . chr(0x60) . chr(0xb0) . chr(0x17));
147+
$this->connection->write($this->packProtocolVersions());
147148

148149
$this->unpackProtocolVersion();
149150
if (empty($this->version)) {
@@ -155,7 +156,7 @@ private function handshake(): bool
155156
if (!class_exists($protocolClass)) {
156157
Bolt::error('Requested Protocol version (' . $this->version . ') not yet implemented');
157158
} else {
158-
$this->protocol = new $protocolClass($this->packer, $this->unpacker, $this->socket);
159+
$this->protocol = new $protocolClass($this->packer, $this->unpacker, $this->connection);
159160
}
160161

161162
return $this->protocol instanceof AProtocol;
@@ -168,7 +169,7 @@ private function unpackProtocolVersion()
168169
{
169170
$result = [];
170171

171-
foreach (str_split($this->socket->read(4)) as $ch)
172+
foreach (str_split($this->connection->read(4)) as $ch)
172173
$result[] = unpack('C', $ch)[1] ?? 0;
173174

174175
$result = array_filter($result);
@@ -218,6 +219,9 @@ private function packProtocolVersions(): string
218219
*/
219220
public function init(string $name, string $user, string $password, array $routing = null): bool
220221
{
222+
if (!$this->connection->connect())
223+
return false;
224+
221225
if (!$this->handshake())
222226
return false;
223227

@@ -397,6 +401,8 @@ public function __destruct()
397401
echo 'GOODBYE';
398402
$this->protocol->goodbye();
399403
}
404+
405+
$this->connection->disconnect();
400406
}
401407

402408
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

autoload.php renamed to src/autoload.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
spl_autoload_register(function ($name) {
66
$parts = explode("\\", $name);
77
$parts = array_filter($parts);
8-
array_shift($parts);
8+
if ($parts[0] != 'Bolt')
9+
return;
10+
array_shift($parts);
911

1012
/*
1113
* namespace calls
1214
*/
1315

1416
//compose standart namespaced path to file
15-
$path = '.' . DS . implode(DS, $parts) . '.php';
17+
$path = __DIR__ . DS . implode(DS, $parts) . '.php';
1618
if (file_exists($path)) {
1719
require_once $path;
1820
return;

0 commit comments

Comments
 (0)