|
| 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 Laudis\Neo4j\Databags\Statement; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +final class HttpConsistencyTest extends TestCase |
| 22 | +{ |
| 23 | + private ClientInterface $client; |
| 24 | + |
| 25 | + protected function setUp(): void |
| 26 | + { |
| 27 | + parent::setUp(); |
| 28 | + $this->client = ClientBuilder::create() |
| 29 | + ->withDriver('http', 'http://neo4j:test@neo4j') |
| 30 | + ->withDriver('bolt', 'bolt://neo4j:test@neo4j') |
| 31 | + ->withDriver('neo4j', 'neo4j://neo4j:test@neo4j') |
| 32 | + ->build(); |
| 33 | + |
| 34 | + $this->client->run('MATCH (x) DETACH DELETE x'); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @dataProvider aliases |
| 39 | + */ |
| 40 | + public function testConsistency(string $alias): void |
| 41 | + { |
| 42 | + $res = $this->client->run('MERGE (n:zzz {name: "bbbb"}) RETURN n', [], $alias); |
| 43 | + self::assertEquals(1, $res->count()); |
| 44 | + self::assertEquals(['name' => 'bbbb'], $res->first()->get('n')); |
| 45 | + |
| 46 | + $res = $this->client->run('MATCH (n:zzz {name: $name}) RETURN n', ['name' => 'bbbb'], $alias); |
| 47 | + self::assertEquals(1, $res->count()); |
| 48 | + self::assertEquals(['name' => 'bbbb'], $res->first()->get('n')); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @dataProvider aliases |
| 53 | + */ |
| 54 | + public function testConsistencyTransaction(string $alias): void |
| 55 | + { |
| 56 | + $tsx = $this->client->openTransaction([ |
| 57 | + Statement::create('CREATE (n:aaa) SET n.name="aaa" return n'), |
| 58 | + ], $alias); |
| 59 | + |
| 60 | + $tsx->run('CREATE (n:ccc) SET n.name="ccc"'); |
| 61 | + |
| 62 | + $tsx->commit([Statement::create('CREATE (n:bbb) SET n.name="bbb" return n')]); |
| 63 | + |
| 64 | + $results = $this->client->run('MATCH (n) RETURN n ORDER BY n.name', [], $alias); |
| 65 | + |
| 66 | + self::assertEquals(3, $results->count()); |
| 67 | + self::assertEquals(['name' => 'aaa'], $results->first()->get('n')); |
| 68 | + self::assertEquals(['name' => 'bbb'], $results->get(1)->get('n')); |
| 69 | + self::assertEquals(['name' => 'ccc'], $results->last()->get('n')); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @return list<list<string>> |
| 74 | + */ |
| 75 | + public function aliases(): array |
| 76 | + { |
| 77 | + return [ |
| 78 | + ['http'], |
| 79 | + ['bolt'], |
| 80 | + ['neo4j'], |
| 81 | + ]; |
| 82 | + } |
| 83 | +} |
0 commit comments