Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/nornicdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
- 7687:7687
- 7474:7474
options: >-
--health-cmd "wget http://localhost:7474 || exit 1"
--health-cmd "curl -fsS http://localhost:7474/health || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 30

steps:
- name: Checkout
Expand Down
74 changes: 57 additions & 17 deletions tests/NornicDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace Bolt\tests;

use Bolt\protocol\IStructure;
use Bolt\Bolt;
use Bolt\protocol\AProtocol;
use Bolt\protocol\v1\structures\{
Duration,
};
use Bolt\enum\Signature;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -80,6 +76,9 @@ public function testQuery(AProtocol $protocol): void
*/
public function testTransaction(AProtocol $protocol): void
{
$this->clean($protocol);

// create node inside transaction and rollback
$res = iterator_to_array(
$protocol
->begin()
Expand All @@ -91,7 +90,10 @@ public function testTransaction(AProtocol $protocol): void
);

$this->assertInstanceOf(\Bolt\protocol\v1\structures\Node::class, $res[2]->content[0]);
// check if rollback was successful
$this->assertEquals(Signature::SUCCESS, $res[4]->signature);

// double check if creation of node was rolled back
$res = iterator_to_array(
$protocol
->run('MATCH (a:Test) WHERE ID(a) = $a RETURN COUNT(a)', [
Expand All @@ -106,31 +108,69 @@ public function testTransaction(AProtocol $protocol): void
}

/**
* Test additional data types
* Test relationship structure
* @depends testConnection
* @dataProvider structureProvider
* @param IStructure $structure
* @param AProtocol $protocol
*/
public function testStructure(IStructure $structure, AProtocol $protocol): void
public function testRelationship(AProtocol $protocol): void
{
$this->markTestSkipped('I don\'t know yet what structures NornicDB supports.');
$responses = iterator_to_array(
// clean up previous test data
$this->clean($protocol);

// create relationship
$res = iterator_to_array(
$protocol
->run('RETURN $s', [
's' => $structure
])
->run('CREATE (:A)-[r:RELATES_TO]->(:B) RETURN r')
->pull()
->getResponses(),
false
);

$this->assertInstanceOf(get_class($structure), $responses[1]->content[0]);
$this->assertEquals((string)$structure, (string)$responses[1]->content[0]);
$this->assertInstanceOf(\Bolt\protocol\v1\structures\Relationship::class, $res[1]->content[0]);
}

public function structureProvider(): \Generator
/**
* Test path structure
* @depends testConnection
* @param AProtocol $protocol
*/
public function testPath(AProtocol $protocol): void
{
yield 'Duration' => [new Duration(0, 4, 3, 2)];
$this->clean($protocol);

// create path
$res = iterator_to_array(
$protocol
->run('CREATE p=(:A)-[:RELATES_TO]->(:B) RETURN p')
->pull()
->getResponses(),
false
);

$this->assertInstanceOf(\Bolt\protocol\v1\structures\Path::class, $res[1]->content[0]);
$this->assertCount(2, $res[1]->content[0]->nodes);
$this->assertCount(1, $res[1]->content[0]->rels);
$this->assertCount(2, $res[1]->content[0]->indices);
$this->assertInstanceOf(\Bolt\protocol\v1\structures\UnboundRelationship::class, $res[1]->content[0]->rels[0]);
$this->assertInstanceOf(\Bolt\protocol\v1\structures\Node::class, $res[1]->content[0]->nodes[0]);
$this->assertInstanceOf(\Bolt\protocol\v1\structures\Node::class, $res[1]->content[0]->nodes[1]);
$this->assertEquals(['A'], $res[1]->content[0]->nodes[0]->labels);
$this->assertEquals(['B'], $res[1]->content[0]->nodes[$res[1]->content[0]->indices[1]]->labels);
$this->assertEquals('RELATES_TO', $res[1]->content[0]->rels[$res[1]->content[0]->indices[0] - 1]->type);
}

/**
* Clean up database
* @param AProtocol $protocol
*/
private function clean(AProtocol $protocol): void
{
iterator_to_array(
$protocol
->run('MATCH (n) DETACH DELETE n')
->pull()
->getResponses(),
false
);
}
}
6 changes: 6 additions & 0 deletions tests/structures/v5/StructuresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ public function testRelationship(AProtocol $protocol)

$protocol->rollback()->getResponse();
}

private string $expectedDateTimeClass = DateTime::class;
use DateTimeTrait;

private string $expectedDateTimeZoneIdClass = DateTimeZoneId::class;
use DateTimeZoneIdTrait;
}
Loading