Skip to content

Commit

Permalink
updated tests configuration (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanak-michal authored Jan 5, 2023
1 parent d72be84 commit d2ee743
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests with a database PHP8
name: Tests with Neo4j 4.4 on PHP^8

on:
push:
Expand All @@ -7,21 +7,21 @@ on:
branches: [ master ]

jobs:
tests:
runs-on: ubuntu-20.04
db-tests-44-2204:
runs-on: ubuntu-22.04
name: "Running Integration tests for PHP ${{ matrix.php-version }} on Neo4j ${{ matrix.neo4j-version }}"
strategy:
fail-fast: false
matrix:
neo4j-version: ["4.4", "5.1", "5.2"]
php-version: ['8.0', '8.1']
neo4j-version: ['4.4']
php-version: ['8.0', '8.1', '8.2']

services:
neo4j:
image: neo4j:${{ matrix.neo4j-version }}
env:
NEO4J_AUTH: neo4j/nothing
NEO4JLABS_PLUGINS: '["apoc"]'
NEO4JLABS_PLUGINS: '["apoc-core"]'
ports:
- 7687:7687
- 7474:7474
Expand All @@ -44,4 +44,7 @@ jobs:
run: composer install --no-progress

- name: Test with phpunit
env:
GDB_USERNAME: neo4j
GDB_PASSWORD: nothing
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Database"
50 changes: 50 additions & 0 deletions .github/workflows/db.50.2204.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Tests with Neo4j^5 on PHP^8

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
db-tests-50-2204:
runs-on: ubuntu-22.04
name: "Running Integration tests for PHP ${{ matrix.php-version }} on Neo4j ${{ matrix.neo4j-version }}"
strategy:
fail-fast: false
matrix:
neo4j-version: ['5.1', '5.2', '5.3']
php-version: ['8.0', '8.1', '8.2']

services:
neo4j:
image: neo4j:${{ matrix.neo4j-version }}
env:
NEO4J_AUTH: neo4j/nothing123
NEO4J_PLUGINS: '["apoc"]'
ports:
- 7687:7687
- 7474:7474
options: >-
--health-cmd "wget http://localhost:7474 || exit 1"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, sockets
coverage: xdebug
ini-values: max_execution_time=0

- name: Install dependencies
run: composer install --no-progress

- name: Test with phpunit
env:
GDB_USERNAME: neo4j
GDB_PASSWORD: nothing123
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Database"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests without a database PHP8
name: Tests without a database PHP^8

on:
push:
Expand All @@ -7,13 +7,13 @@ on:
branches: [ master ]

jobs:
tests:
runs-on: ubuntu-20.04
no-db-tests-2204:
runs-on: ubuntu-22.04
name: "Running Tests for PHP ${{ matrix.php-version }}"
strategy:
fail-fast: false
matrix:
php-version: ['8.0', '8.1']
php-version: ['8.0', '8.1', '8.2']

steps:
- name: Checkout
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Bolt
PHP library for communication with graph database over TCP socket with Bolt protocol specification. Bolt protocol was created by [Neo4j](https://neo4j.com/) and documentation is available at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support all available versions and keep up with protocol messages architecture and specifications.

![DB Tests PHP8](https://github.com/neo4j-php/Bolt/actions/workflows/db-test-php-8.yml/badge.svg?branch=master)
![No DB Tests PHP8](https://github.com/neo4j-php/Bolt/actions/workflows/no-db-test-php-8.yml/badge.svg?branch=master)

[![](https://img.shields.io/github/stars/stefanak-michal/Bolt)](https://github.com/neo4j-php/Bolt/stargazers)
[![](https://img.shields.io/packagist/dt/stefanak-michal/bolt)](https://packagist.org/packages/stefanak-michal/bolt/stats)
[![](https://img.shields.io/github/v/release/stefanak-michal/bolt)](https://github.com/neo4j-php/Bolt/releases)
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="src/autoload.php">
<testsuites>
<testsuite name="Database">
<directory>./tests/connection</directory>
<file>./tests/BoltTest.php</file>
<directory>./tests/connection</directory>
<directory>./tests/error</directory>
<directory>./tests/packstream</directory>
<directory>./tests/structures</directory>
<file>./tests/PerformanceTest.php</file>
</testsuite>
<testsuite name="NoDatabase">
<directory>./tests/protocol</directory>
Expand Down
27 changes: 27 additions & 0 deletions tests/ATest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Bolt\tests;

/**
* Class ATest
* @package Bolt\tests
*/
class ATest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
$user = getenv('GDB_USERNAME');
if (!empty($user))
$GLOBALS['NEO_USER'] = $user;
$pwd = getenv('GDB_PASSWORD');
if (!empty($pwd))
$GLOBALS['NEO_PASS'] = $pwd;
$host = getenv('GDB_HOST');
if (!empty($host))
$GLOBALS['NEO_HOST'] = $host;
$port = getenv('GDB_PORT');
if (!empty($port))
$GLOBALS['NEO_PORT'] = $port;
}
}
5 changes: 2 additions & 3 deletions tests/BoltTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Bolt\Bolt;
use Exception;
use PHPUnit\Framework\TestCase;
use Bolt\protocol\{
AProtocol,
Response,
Expand All @@ -26,9 +25,8 @@
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests
*/
class BoltTest extends TestCase
class BoltTest extends ATest
{

public function testSockets(): void
{
if (!extension_loaded('sockets'))
Expand Down Expand Up @@ -100,6 +98,7 @@ public function testPull(AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5 $protocol)
$res = $protocol->getResponse()->getContent();
$this->assertEquals(1, $res[0] ?? 0);
$this->assertEquals(2, $res[1] ?? 0);
$protocol->getResponse(); // last success message
}

/**
Expand Down
50 changes: 27 additions & 23 deletions tests/PerformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Bolt\tests;

use Bolt\Bolt;
use Bolt\connection\StreamSocket;
use Bolt\connection\Socket;
use Bolt\helpers\Auth;
use Bolt\protocol\{
AProtocol,
Response,
V1,
V2,
V3,
Expand All @@ -18,52 +19,55 @@
V5
};
use Bolt\tests\packstream\v1\generators\RandomDataGenerator;
use PHPUnit\Framework\TestCase;

/**
* Class PerformanceTest
* @author Ghlen Nagels
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests
*/
class PerformanceTest extends TestCase
class PerformanceTest extends ATest
{
public function test50KRecords(): void
{
$amount = 50000;

$conn = new StreamSocket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687, 60);
$conn = new Socket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687, 60);
/** @var AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5 $protocol */
$protocol = (new Bolt($conn))->build();
$this->assertEquals(\Bolt\protocol\Response::SIGNATURE_SUCCESS, $protocol->hello(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']))->getSignature());

//prevent multiple runs at once
while (true) {
$protocol->run('MATCH (n:Test50k) RETURN count(n)')->getResponse();
$response = $protocol->pull()->getResponse();
if ($response !== Response::SIGNATURE_RECORD)
$this->markTestSkipped();
$runs = $response->getContent()[0];
$protocol->getResponse();
if ($runs > 0) {
sleep(60);
} else {
$protocol->run('CREATE (n:Test50k)')->getResponse();
break;
}
}

$generator = new RandomDataGenerator($amount);
$protocol
->run('UNWIND $x as x RETURN x', ['x' => $generator])
->getResponse();

$count = 0;
while (true) {
$gen = $protocol
->pull(['n' => 1])
->getResponses();

if ($gen->current()->getSignature() != \Bolt\protocol\Response::SIGNATURE_RECORD)
$this->markTestIncomplete('Response does not contains record message');

$gen->next();

if ($gen->current()->getSignature() != \Bolt\protocol\Response::SIGNATURE_SUCCESS)
$this->markTestIncomplete('Response does not contains success message');

$count++;

if ($gen->current()->getContent()['has_more'] ?? false)
continue;
else
break;
$iterator = $protocol->pull()->getResponses();
$count = 0;
/** @var Response $response */
foreach ($iterator as $response) {
if ($response->getSignature() === Response::SIGNATURE_RECORD)
$count++;
}

$protocol->run('MATCH (n:Test50k) DELETE n');
$this->assertEquals($amount, $count);
}
}
4 changes: 2 additions & 2 deletions tests/connection/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
V4_4,
V5
};
use Bolt\tests\ATest;
use Bolt\connection\{
IConnection,
Socket,
StreamSocket
};
use Bolt\error\ConnectionTimeoutException;
use Bolt\helpers\Auth;
use PHPUnit\Framework\TestCase;

/**
* Class ConnectionTest
*
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests\connection
*/
final class ConnectionTest extends TestCase
final class ConnectionTest extends ATest
{
public function provideConnections(): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/packstream/v1/BytesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
V4_4,
V5
};
use PHPUnit\Framework\TestCase;
use Bolt\tests\ATest;

/**
* Class BytesTest
* @package Bolt\tests\packstream\v1
*/
class BytesTest extends TestCase
class BytesTest extends ATest
{
public function testInit(): AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5
{
Expand Down
4 changes: 2 additions & 2 deletions tests/packstream/v1/PackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
V4_4,
V5
};
use PHPUnit\Framework\TestCase;
use Bolt\tests\ATest;

/**
* Class PackerTest
Expand All @@ -25,7 +25,7 @@
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests\packstream\v1
*/
class PackerTest extends TestCase
class PackerTest extends ATest
{
public function testInit(): AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5
{
Expand Down
6 changes: 3 additions & 3 deletions tests/packstream/v1/UnpackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Bolt\Bolt;
use Bolt\protocol\{AProtocol, Response, V1, V2, V3, V4, V4_1, V4_2, V4_3, V4_4, V5};
use PHPUnit\Framework\TestCase;
use Bolt\tests\ATest;

/**
* Class UnpackerTest
Expand All @@ -13,7 +13,7 @@
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests\packstream\v1
*/
class UnpackerTest extends TestCase
class UnpackerTest extends ATest
{
public function testInit(): AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5
{
Expand All @@ -29,7 +29,7 @@ public function testInit(): AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5

$this->assertNotEmpty($protocol->hello(\Bolt\helpers\Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS'])));

$conn->setTimeout(120);
$conn->setTimeout(60 * 10);
return $protocol;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/structures/AStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\tests\structures;

use PHPUnit\Framework\TestCase;
use Bolt\tests\ATest;
use Exception;

/**
Expand All @@ -11,7 +11,7 @@
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests\protocol
*/
class AStructures extends TestCase
class AStructures extends ATest
{
/**
* How many iterations do for each date/time test
Expand Down

0 comments on commit d2ee743

Please sign in to comment.