Skip to content

Commit

Permalink
Merge pull request #33 from stefanak-michal/issue/31_unpacker_test
Browse files Browse the repository at this point in the history
Issue/31 unpacker test
  • Loading branch information
stefanak-michal authored Oct 24, 2020
2 parents 66c39a7 + d73a57b commit 397d6a3
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 116 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Bolt
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/).

![](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)
![](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)

## Supported version
## Version support
Bolt <= 4.1

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

## Author note
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?
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?

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

Expand Down
90 changes: 0 additions & 90 deletions index.php

This file was deleted.

5 changes: 2 additions & 3 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
return;
array_shift($parts);

/*
* namespace calls
*/
if ($parts[0] == 'tests')
array_unshift($parts,'..');

//compose standart namespaced path to file
$path = __DIR__ . DS . implode(DS, $parts) . '.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/ATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Bolt\connection\IConnection;

/**
* Class TestBase
* Class ATest
* @author Michal Stefanak
* @link https://github.com/stefanak-michal/Bolt
* @package Bolt\tests
Expand Down
26 changes: 7 additions & 19 deletions tests/PackStream/v1/PackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function test__construct(): Packer
*/
public function testPack(string $bin, array $args, Packer $packer)
{
array_unshift($args, 0x88);
$this->assertEquals($bin, $this->getMethod($packer, 'pack')->invokeArgs($packer, $args));
$this->assertEquals($bin, $packer->pack(0x88, $args));
}

/**
Expand Down Expand Up @@ -87,7 +86,7 @@ public function integerProvider(): array
*/
public function testPackFloat(Packer $packer)
{
$this->assertEquals('c1400921f9f01b866e', $this->toHex($this->getMethod($packer)->invoke($packer, 3.14159)));
$this->assertEquals('c1400921f9f01b866e', bin2hex($this->getMethod($packer)->invoke($packer, 3.14159)));
}

/**
Expand All @@ -97,7 +96,7 @@ public function testPackFloat(Packer $packer)
*/
public function testPackNull(Packer $packer)
{
$this->assertEquals('c0', $this->toHex($this->getMethod($packer)->invoke($packer, null)));
$this->assertEquals('c0', bin2hex($this->getMethod($packer)->invoke($packer, null)));
}

/**
Expand All @@ -107,8 +106,8 @@ public function testPackNull(Packer $packer)
*/
public function testPackBool(Packer $packer)
{
$this->assertEquals('c2', $this->toHex($this->getMethod($packer)->invoke($packer, false)));
$this->assertEquals('c3', $this->toHex($this->getMethod($packer)->invoke($packer, true)));
$this->assertEquals('c2', bin2hex($this->getMethod($packer)->invoke($packer, false)));
$this->assertEquals('c3', bin2hex($this->getMethod($packer)->invoke($packer, true)));
}

/**
Expand Down Expand Up @@ -198,27 +197,16 @@ public function testException(Packer $packer)
/**
* Get method from Packer as accessible
* @param Packer $packer
* @param string $name
* @return \ReflectionMethod
*/
private function getMethod(Packer $packer, string $name = 'p'): \ReflectionMethod
private function getMethod(Packer $packer): \ReflectionMethod
{
$reflection = new \ReflectionClass(get_class($packer));
$method = $reflection->getMethod($name);
$method = $reflection->getMethod('p');
$method->setAccessible(true);
return $method;
}

/**
* Bin to Hex convert
* @param string $str
* @return string
*/
private function toHex(string $str): string
{
return implode(unpack('H*', $str));
}

/**
* "Abstract" provider to read content of directory as provider array
* @param string $fnc
Expand Down
Loading

0 comments on commit 397d6a3

Please sign in to comment.