Skip to content

Commit 69f3eb4

Browse files
committed
fixed bug when adding statements while beginning a transaction
2 parents 9fad650 + 59c8ad9 commit 69f3eb4

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ services:
2424
- readreplica1
2525
expose:
2626
- 9000
27-
environment:
28-
- XDEBUG_MODE=coverage
2927
neo4j:
3028
networks:
3129
- neo4j

src/Http/HttpSession.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function run(string $statement, iterable $parameters = [], ?TransactionCo
134134
public function beginTransaction(?iterable $statements = null, ?TransactionConfiguration $config = null): UnmanagedTransactionInterface
135135
{
136136
$request = $this->requestFactory->createRequest('POST', $this->uri);
137+
$request->getBody()->write(HttpHelper::statementsToString($this->formatter, $statements ?? []));
137138
$client = $this->pool->acquire($request->getUri(), $this->config->getAccessMode());
138139
$response = $client->sendRequest($request);
139140

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)