|
| 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