Skip to content

Commit 1157dc5

Browse files
added memgraph test and workflow
1 parent 705b5ee commit 1157dc5

File tree

6 files changed

+194
-4
lines changed

6 files changed

+194
-4
lines changed

.github/workflows/memgraph.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Tests with Memgraph on PHP 8.5
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
7+
jobs:
8+
memgraph-tests:
9+
runs-on: ubuntu-22.04
10+
name: "Running Integration tests for PHP on Memgraph"
11+
12+
services:
13+
memgraph:
14+
image: memgraph/memgraph
15+
ports:
16+
- 7687:7687
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v6
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '8.5'
26+
extensions: mbstring, sockets
27+
coverage: xdebug
28+
ini-values: max_execution_time=0
29+
30+
- name: Install dependencies
31+
run: composer install --no-progress
32+
33+
- name: Test with phpunit
34+
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Memgraph"

.github/workflows/neo4j.2025.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
env:
4646
GDB_USERNAME: neo4j
4747
GDB_PASSWORD: nothing123
48-
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Database"
48+
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Neo4j"

.github/workflows/neo4j.4.4.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
env:
4646
GDB_USERNAME: neo4j
4747
GDB_PASSWORD: nothing
48-
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Database"
48+
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Neo4j"

.github/workflows/neo4j.5.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
env:
4646
GDB_USERNAME: neo4j
4747
GDB_PASSWORD: nothing123
48-
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Database"
48+
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite "Neo4j"

phpunit.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="src/autoload.php">
33
<testsuites>
4-
<testsuite name="Database">
4+
<testsuite name="Neo4j">
55
<file>./tests/BoltTest.php</file>
66
<directory>./tests/connection</directory>
77
<directory>./tests/error</directory>
@@ -13,6 +13,9 @@
1313
<directory>./tests/protocol</directory>
1414
<file>./tests/helpers/FileCacheTest.php</file>
1515
</testsuite>
16+
<testsuite name="Memgraph">
17+
<file>./tests/MemgraphTest.php</file>
18+
</testsuite>
1619
</testsuites>
1720
<php>
1821
<var name="NEO_USER" value="neo4j"/>

tests/MemgraphTest.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
3+
namespace Bolt\tests;
4+
5+
use Bolt\protocol\IStructure;
6+
use Bolt\Bolt;
7+
use Bolt\protocol\AProtocol;
8+
use Bolt\protocol\v1\structures\{
9+
Date,
10+
Duration,
11+
LocalTime,
12+
LocalDateTime
13+
};
14+
use Bolt\enum\Signature;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Class MemgraphTest
19+
*
20+
* @author Michal Stefanak
21+
* @link https://github.com/neo4j-php/Bolt
22+
* @package Bolt\tests
23+
*/
24+
class MemgraphTest extends TestCase
25+
{
26+
/**
27+
* @return AProtocol
28+
*/
29+
public function testConnection(): AProtocol
30+
{
31+
if (!extension_loaded('sockets'))
32+
$this->markTestSkipped('Sockets extension not available');
33+
34+
$conn = new \Bolt\connection\Socket('127.0.0.1', 7687, 3);
35+
$this->assertInstanceOf(\Bolt\connection\Socket::class, $conn);
36+
37+
$bolt = new Bolt($conn);
38+
$this->assertInstanceOf(Bolt::class, $bolt);
39+
40+
$protocol = $bolt->setProtocolVersions(5.2, 4.3, 4.1, 4.0)->build();
41+
$this->assertInstanceOf(AProtocol::class, $protocol);
42+
43+
if (version_compare($protocol->getVersion(), '5.2', '>=')) {
44+
$protocol->hello()->getResponse();
45+
$protocol->logon(['scheme' => 'none'])->getResponse();
46+
} else {
47+
$protocol->hello(['scheme' => 'none'])->getResponse();
48+
}
49+
50+
return $protocol;
51+
}
52+
53+
/**
54+
* Basic query test with basic data types
55+
* @depends testConnection
56+
* @param AProtocol $protocol
57+
*/
58+
public function testQuery(AProtocol $protocol): void
59+
{
60+
$params = [
61+
'number' => 123,
62+
'string' => 'abc',
63+
'null' => null,
64+
'bool' => true,
65+
'float' => 0.4591563,
66+
'list' => [1, 2, 3],
67+
'dictionary' => ['a' => 1, 'b' => 2, 'c' => 3]
68+
];
69+
70+
$query = implode(', ', array_map(function (string $key) {
71+
return '$' . $key . ' AS ' . $key;
72+
}, array_keys($params)));
73+
74+
$runResponse = $protocol->run('RETURN ' . $query, $params)->getResponse();
75+
$this->assertEquals(Signature::SUCCESS, $runResponse->signature);
76+
77+
$pullResponses = iterator_to_array($protocol->pull()->getResponses(), false);
78+
$this->assertCount(2, $pullResponses);
79+
$this->assertEquals(Signature::RECORD, $pullResponses[0]->signature);
80+
$this->assertEquals(Signature::SUCCESS, $pullResponses[1]->signature);
81+
82+
$this->assertEquals($params, array_combine($runResponse->content['fields'], $pullResponses[0]->content));
83+
}
84+
/**
85+
* Test transaction handling
86+
* @depends testConnection
87+
* @param AProtocol $protocol
88+
*/
89+
public function testTransaction(AProtocol $protocol): void
90+
{
91+
if (version_compare($protocol->getVersion(), 3, '<')) {
92+
$this->markTestSkipped('Old Memgraph version does not support transactions');
93+
}
94+
95+
$res = iterator_to_array(
96+
$protocol
97+
->begin()
98+
->run('CREATE (a:Test) RETURN a, ID(a)')
99+
->pull()
100+
->rollback()
101+
->getResponses(),
102+
false
103+
);
104+
105+
$id = $res[2]->content[1];
106+
$this->assertIsInt($id);
107+
108+
$res = iterator_to_array(
109+
$protocol
110+
->run('MATCH (a:Test) WHERE ID(a) = '
111+
. (version_compare($protocol->getVersion(), 4, '<') ? '{a}' : '$a')
112+
. ' RETURN COUNT(a)', [
113+
'a' => $id
114+
])
115+
->pull()
116+
->getResponses(),
117+
false
118+
);
119+
120+
$this->assertEquals(0, $res[1]->content[0]);
121+
}
122+
123+
/**
124+
* Test additional data types
125+
* @depends testConnection
126+
* @dataProvider structureProvider
127+
* @param IStructure $structure
128+
* @param AProtocol $protocol
129+
*/
130+
public function testStructure(IStructure $structure, AProtocol $protocol): void
131+
{
132+
$responses = iterator_to_array(
133+
$protocol
134+
->run('RETURN $s', [
135+
's' => $structure
136+
])
137+
->pull()
138+
->getResponses(),
139+
false
140+
);
141+
142+
$this->assertInstanceOf(get_class($structure), $responses[1]->content[0]);
143+
$this->assertEquals((string)$structure, (string)$responses[1]->content[0]);
144+
}
145+
146+
public function structureProvider(): \Generator
147+
{
148+
yield 'Duration' => [new Duration(0, 4, 3, 2)];
149+
yield 'Date' => [new Date(intval(floor(time() / 86400)))];
150+
yield 'LocalTime' => [new LocalTime(intval(microtime(true) * 1000))];
151+
yield 'LocalDateTime' => [new LocalDateTime(time(), 1234)];
152+
}
153+
}

0 commit comments

Comments
 (0)