Skip to content

Commit 397d6a3

Browse files
Merge pull request #33 from stefanak-michal/issue/31_unpacker_test
Issue/31 unpacker test
2 parents 66c39a7 + d73a57b commit 397d6a3

File tree

9 files changed

+239
-116
lines changed

9 files changed

+239
-116
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Bolt
22
Bolt protocol library over TCP socket. Bolt protocol is primary used for communication with [Neo4j](https://neo4j.com/) Graph database. The documentation is available at [https://7687.org/](https://7687.org/).
33

4-
![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-70%25-yellowgreen) ![](https://img.shields.io/github/stars/stefanak-michal/Bolt) ![](https://img.shields.io/packagist/dt/stefanak-michal/bolt) ![](https://img.shields.io/github/v/release/stefanak-michal/bolt) ![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)
4+
![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-74%25-yellowgreen) ![](https://img.shields.io/github/stars/stefanak-michal/Bolt) ![](https://img.shields.io/packagist/dt/stefanak-michal/bolt) ![](https://img.shields.io/github/v/release/stefanak-michal/bolt) ![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)
55

6-
## Supported version
6+
## Version support
77
Bolt <= 4.1
88

99
| Neo4j Version | Bolt 1 | Bolt 2 | Bolt 3 | Bolt 4.0 | Bolt 4.1 |
@@ -25,7 +25,7 @@ Bolt <= 4.1
2525
## [Errors](https://github.com/stefanak-michal/Bolt/wiki/Errors)
2626

2727
## Author note
28-
I really like Neo4j and I wanted to use it with PHP. But after I looked on official php library, I was really disappointed. Too much dependencies. I don't like if I need to install 10 things because of one. First I decided to use HTTP API for communication, but it wasn't fast enough. I went through bolt protocol documentation and I said to myself, why not to create own simpler library?
28+
I really like Neo4j and I wanted to use it with PHP. But after I looked on official php library, I was really disappointed. Too much dependencies. I don't like if I have to install 10 things because of one. First I decided to use HTTP API for communication, but it wasn't fast enough. I went through bolt protocol documentation and I said to myself, why not to create own simpler library?
2929

3030
[Speed comparison](https://github.com/stefanak-michal/Bolt/wiki/Speed-comparison)
3131

index.php

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/autoload.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
return;
1010
array_shift($parts);
1111

12-
/*
13-
* namespace calls
14-
*/
12+
if ($parts[0] == 'tests')
13+
array_unshift($parts,'..');
1514

1615
//compose standart namespaced path to file
1716
$path = __DIR__ . DS . implode(DS, $parts) . '.php';

tests/ATest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Bolt\connection\IConnection;
77

88
/**
9-
* Class TestBase
9+
* Class ATest
1010
* @author Michal Stefanak
1111
* @link https://github.com/stefanak-michal/Bolt
1212
* @package Bolt\tests

tests/PackStream/v1/PackerTest.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public function test__construct(): Packer
4141
*/
4242
public function testPack(string $bin, array $args, Packer $packer)
4343
{
44-
array_unshift($args, 0x88);
45-
$this->assertEquals($bin, $this->getMethod($packer, 'pack')->invokeArgs($packer, $args));
44+
$this->assertEquals($bin, $packer->pack(0x88, $args));
4645
}
4746

4847
/**
@@ -87,7 +86,7 @@ public function integerProvider(): array
8786
*/
8887
public function testPackFloat(Packer $packer)
8988
{
90-
$this->assertEquals('c1400921f9f01b866e', $this->toHex($this->getMethod($packer)->invoke($packer, 3.14159)));
89+
$this->assertEquals('c1400921f9f01b866e', bin2hex($this->getMethod($packer)->invoke($packer, 3.14159)));
9190
}
9291

9392
/**
@@ -97,7 +96,7 @@ public function testPackFloat(Packer $packer)
9796
*/
9897
public function testPackNull(Packer $packer)
9998
{
100-
$this->assertEquals('c0', $this->toHex($this->getMethod($packer)->invoke($packer, null)));
99+
$this->assertEquals('c0', bin2hex($this->getMethod($packer)->invoke($packer, null)));
101100
}
102101

103102
/**
@@ -107,8 +106,8 @@ public function testPackNull(Packer $packer)
107106
*/
108107
public function testPackBool(Packer $packer)
109108
{
110-
$this->assertEquals('c2', $this->toHex($this->getMethod($packer)->invoke($packer, false)));
111-
$this->assertEquals('c3', $this->toHex($this->getMethod($packer)->invoke($packer, true)));
109+
$this->assertEquals('c2', bin2hex($this->getMethod($packer)->invoke($packer, false)));
110+
$this->assertEquals('c3', bin2hex($this->getMethod($packer)->invoke($packer, true)));
112111
}
113112

114113
/**
@@ -198,27 +197,16 @@ public function testException(Packer $packer)
198197
/**
199198
* Get method from Packer as accessible
200199
* @param Packer $packer
201-
* @param string $name
202200
* @return \ReflectionMethod
203201
*/
204-
private function getMethod(Packer $packer, string $name = 'p'): \ReflectionMethod
202+
private function getMethod(Packer $packer): \ReflectionMethod
205203
{
206204
$reflection = new \ReflectionClass(get_class($packer));
207-
$method = $reflection->getMethod($name);
205+
$method = $reflection->getMethod('p');
208206
$method->setAccessible(true);
209207
return $method;
210208
}
211209

212-
/**
213-
* Bin to Hex convert
214-
* @param string $str
215-
* @return string
216-
*/
217-
private function toHex(string $str): string
218-
{
219-
return implode(unpack('H*', $str));
220-
}
221-
222210
/**
223211
* "Abstract" provider to read content of directory as provider array
224212
* @param string $fnc

0 commit comments

Comments
 (0)