Skip to content

Commit 3179ea9

Browse files
committed
invalidbooktest is created
1 parent 5e7d697 commit 3179ea9

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

tests/CreatesQueryAPI.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI\Tests;
4+
5+
use Neo4j\QueryAPI\Configuration;
6+
use Neo4j\QueryAPI\Enums\AccessMode;
7+
use Neo4j\QueryAPI\Neo4jQueryAPI;
8+
use Neo4j\QueryAPI\Objects\Authentication;
9+
use Neo4j\QueryAPI\Objects\Bookmarks;
10+
11+
trait CreatesQueryAPI
12+
{
13+
protected Neo4jQueryAPI $api;
14+
15+
protected function createQueryAPI(AccessMode $accessMode = AccessMode::WRITE, ?Bookmarks $bookmarks = null): void
16+
{
17+
$neo4jAddress = getenv('NEO4J_ADDRESS');
18+
if (!is_string($neo4jAddress) || trim($neo4jAddress) === '') {
19+
throw new \RuntimeException('NEO4J_ADDRESS is not set or is invalid.');
20+
}
21+
22+
$this->api = Neo4jQueryAPI::create(
23+
new Configuration(baseUri: $neo4jAddress, bookmarks: $bookmarks ?? new Bookmarks([]), accessMode: $accessMode),
24+
Authentication::fromEnvironment()
25+
);
26+
}
27+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI\Tests\Integration;
4+
5+
use Neo4j\QueryAPI\Configuration;
6+
use Neo4j\QueryAPI\Exception\Neo4jException;
7+
use Neo4j\QueryAPI\Neo4jQueryAPI;
8+
use Neo4j\QueryAPI\Tests\CreatesQueryAPI;
9+
use PHPUnit\Framework\TestCase;
10+
use Neo4j\QueryAPI\Objects\Bookmarks;
11+
use Neo4j\QueryAPI\Exception\InvalidBookmarkException;
12+
13+
final class BookmarksIntegrationTest extends TestCase
14+
{
15+
use CreatesQueryAPI;
16+
17+
#[\Override]
18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
22+
$this->createQueryAPI();
23+
}
24+
25+
26+
public function testCreateBookmarks(): void
27+
{
28+
$result = $this->api->run('CREATE (x:Node {hello: "world"})');
29+
30+
$bookmarks = $result->getBookmarks() ?? new Bookmarks([]);
31+
32+
$result = $this->api->run('CREATE (x:Node {hello: "world2"})');
33+
$bookmarks->addBookmarks($result->getBookmarks());
34+
35+
$result = $this->api->run('MATCH (x:Node {hello: "world2"}) RETURN x');
36+
$bookmarks->addBookmarks($result->getBookmarks());
37+
38+
$this->assertCount(1, $result);
39+
}
40+
41+
42+
public function testInvalidBookmarkThrowsException(): void
43+
{
44+
$exceptionCaught = false;
45+
46+
$invalidBookmark = new Bookmarks(['invalid:bookmark']);
47+
$this->createQueryAPI(bookmarks: $invalidBookmark);
48+
49+
try {
50+
$this->api->run('MATCH (n) RETURN n');
51+
} catch (Neo4jException $e) {
52+
$exceptionCaught = true;
53+
$this->assertEquals('Parsing of supplied bookmarks failed with message: Illegal base64 character 3a', $e->getMessage());
54+
$this->assertEquals('InvalidBookmark', $e->getName());
55+
$this->assertEquals('Transaction', $e->getSubType());
56+
$this->assertEquals('ClientError', $e->getType());
57+
}
58+
59+
$this->assertTrue($exceptionCaught);
60+
}
61+
62+
63+
}

0 commit comments

Comments
 (0)