|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Laudis Neo4j package. |
| 7 | + * |
| 8 | + * (c) Laudis technologies <http://laudis.tech> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Laudis\Neo4j\Tests\Integration; |
| 15 | + |
| 16 | +use Laudis\Neo4j\ClientBuilder; |
| 17 | +use Laudis\Neo4j\Contracts\ClientInterface; |
| 18 | +use PHPUnit\Framework\TestCase; |
| 19 | + |
| 20 | +final class ComplexQueryTests extends TestCase |
| 21 | +{ |
| 22 | + private ClientInterface $client; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + parent::setUp(); |
| 27 | + $this->client = ClientBuilder::create() |
| 28 | + ->addBoltConnection('bolt', 'bolt://neo4j:test@neo4j') |
| 29 | + ->addHttpConnection('http', 'http://neo4j:test@neo4j') |
| 30 | + ->build(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @dataProvider transactionProvider |
| 35 | + */ |
| 36 | + public function testCreationAndResult(string $alias): void |
| 37 | + { |
| 38 | + $result = $this->client->run(<<<'CYPHER' |
| 39 | +MERGE (x:Node {x:$x}) |
| 40 | +RETURN x |
| 41 | +CYPHER |
| 42 | + , ['x' => 'x'], $alias)->first(); |
| 43 | + |
| 44 | + self::assertEquals(['x' => 'x'], $result->get('x')); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @dataProvider transactionProvider |
| 49 | + */ |
| 50 | + public function testPath(string $alias): void |
| 51 | + { |
| 52 | + $results = $this->client->run(<<<'CYPHER' |
| 53 | +MERGE (b:Node {x:$x}) - [:HasNode {attribute: $xy}] -> (:Node {y:$y}) - [:HasNode {attribute: $yz}] -> (:Node {z:$z}) |
| 54 | +WITH b |
| 55 | +MATCH (x:Node) - [y:HasNode*2] -> (z:Node) |
| 56 | +RETURN x, y, z |
| 57 | +CYPHER |
| 58 | + , ['x' => 'x', 'xy' => 'xy', 'y' => 'y', 'yz' => 'yz', 'z' => 'z'], $alias); |
| 59 | + |
| 60 | + self::assertEquals(1, $results->count()); |
| 61 | + $result = $results->first(); |
| 62 | + self::assertEquals(3, $result->count()); |
| 63 | + self::assertEquals(['x' => 'x'], $result->get('x')); |
| 64 | + self::assertEquals([['attribute' => 'xy'], ['attribute' => 'yz']], $result->get('y')); |
| 65 | + self::assertEquals(['z' => 'z'], $result->get('z')); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @dataProvider transactionProvider |
| 70 | + */ |
| 71 | + public function testNullListAndMap(string $alias): void |
| 72 | + { |
| 73 | + $results = $this->client->run(<<<'CYPHER' |
| 74 | +RETURN null as x, [1, 2, 3] as y, {x: 'x', y: 'y', z: 'z'} as z |
| 75 | +CYPHER |
| 76 | + , ['x' => 'x', 'xy' => 'xy', 'y' => 'y', 'yz' => 'yz', 'z' => 'z'], $alias); |
| 77 | + |
| 78 | + self::assertEquals(1, $results->count()); |
| 79 | + $result = $results->first(); |
| 80 | + self::assertEquals(3, $result->count()); |
| 81 | + self::assertNull($result->get('x')); |
| 82 | + self::assertEquals([1, 2, 3], $result->get('y')); |
| 83 | + self::assertEquals(['x' => 'x', 'y' => 'y', 'z' => 'z'], $result->get('z')); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @dataProvider transactionProvider |
| 88 | + */ |
| 89 | + public function testListAndMapInput(string $alias): void |
| 90 | + { |
| 91 | + $results = $this->client->run(<<<'CYPHER' |
| 92 | +MERGE (x:Node {x: $x.x}) |
| 93 | +WITH x |
| 94 | +MERGE (y:Node {list: $y}) |
| 95 | +RETURN x, y |
| 96 | +LIMIT 1 |
| 97 | +CYPHER |
| 98 | + , ['x' => ['x' => 'x'], 'y' => [1, 2, 3]], $alias); |
| 99 | + |
| 100 | + self::assertEquals(1, $results->count()); |
| 101 | + $result = $results->first(); |
| 102 | + self::assertEquals(2, $result->count()); |
| 103 | + self::assertEquals(['x' => 'x'], $result->get('x')); |
| 104 | + self::assertEquals(['list' => [1, 2, 3]], $result->get('y')); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @return array<int, array<int, string>> |
| 109 | + */ |
| 110 | + public function transactionProvider(): array |
| 111 | + { |
| 112 | + return [ |
| 113 | + ['http'], |
| 114 | + ['bolt'], |
| 115 | + ]; |
| 116 | + } |
| 117 | +} |
0 commit comments