Skip to content

Commit 2d47ae2

Browse files
committed
winp
1 parent cbd1d42 commit 2d47ae2

File tree

7 files changed

+29
-39
lines changed

7 files changed

+29
-39
lines changed

src/BasicAuthentication.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class BasicAuthentication implements AuthenticateInterface
99
{
1010
public function __construct(private string $username, private string $password)
1111
{
12+
$this->username = $username;
13+
$this->password = $password;
1214
}
1315

1416
public function authenticate(RequestInterface $request): RequestInterface
@@ -26,4 +28,4 @@ public function getType(): string
2628
return 'Basic';
2729
}
2830

29-
}
31+
}

src/BearerAuthentication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public function getType(): string
2424
{
2525
return 'Bearer';
2626
}
27-
}
27+
}

src/Neo4jQueryAPI.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Neo4j\QueryAPI;
44

5+
use Exception;
56
use GuzzleHttp\Client;
67
use GuzzleHttp\Psr7\Request;
78
use GuzzleHttp\Psr7\Utils;
@@ -90,7 +91,6 @@ public function run(string $cypher, array $parameters = [], string $database = '
9091
0,
9192
null,
9293
$error
93-
9494
);
9595
}
9696

@@ -164,17 +164,32 @@ private function handleException(RequestExceptionInterface $e): void
164164
throw $e;
165165
}
166166

167-
public function beginTransaction(string $database = 'neo4j'): Transaction
167+
public function beginTransaction(): array
168168
{
169-
$response = $this->client->sendRequest(new Request('POST', '/db/neo4j/query/v2/tx'));
169+
$request = new Request('POST', '/db/neo4j/tx'); // Adjust endpoint as needed
170+
171+
// Apply authentication, if provided
172+
if ($this->auth instanceof AuthenticateInterface) {
173+
$request = $this->auth->authenticate($request);
174+
}
175+
176+
try {
177+
$response = $this->client->send($request);
178+
$responseBody = json_decode($response->getBody()->getContents(), true);
170179

171-
$clusterAffinity = $response->getHeaderLine('neo4j-cluster-affinity');
172-
$responseData = json_decode($response->getBody(), true);
173-
$transactionId = $responseData['transaction']['id'];
180+
// Validate the response for transaction ID
181+
if (isset($responseBody['commit'])) {
182+
return $responseBody; // Successful transaction
183+
}
174184

175-
return new Transaction($this->client, $clusterAffinity, $transactionId);
185+
throw new RuntimeException('Missing transaction ID in the response.');
186+
} catch (Exception $e) {
187+
throw new RuntimeException("Failed to begin transaction: {$e->getMessage()}", 0, $e);
188+
}
176189
}
177190

191+
192+
178193
private function createProfileData(array $data): ProfiledQueryPlan
179194
{
180195
$ogm = new OGM();
@@ -229,4 +244,4 @@ private function createProfileData(array $data): ProfiledQueryPlan
229244

230245
return $profiledQueryPlan;
231246
}
232-
}
247+
}

src/NoAuth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Neo4j\QueryAPI;
34

45
use Psr\Http\Message\RequestInterface;
@@ -9,4 +10,4 @@ public function authenticate(RequestInterface $request): RequestInterface
910
{
1011
return $request;
1112
}
12-
}
13+
}

src/Objects/Authentication.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ public static function bearer(string $token): AuthenticateInterface
2727
return new BearerAuthentication($token);
2828
}
2929
}
30-

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -232,32 +232,6 @@ public function testChildQueryPlanExistence(): void
232232

233233

234234

235-
public function testTransactionCommit(): void
236-
{
237-
// Begin a new transaction
238-
$tsx = $this->api->beginTransaction();
239-
240-
// Generate a random name for the node
241-
$name = (string)mt_rand(1, 100000);
242-
243-
// Create a node within the transaction
244-
$tsx->run("CREATE (x:Human {name: \$name})", ['name' => $name]);
245-
246-
// Validate that the node does not exist in the database before the transaction is committed
247-
$results = $this->api->run("MATCH (x:Human {name: \$name}) RETURN x", ['name' => $name]);
248-
$this->assertCount(0, $results);
249-
250-
// Validate that the node exists within the transaction
251-
$results = $tsx->run("MATCH (x:Human {name: \$name}) RETURN x", ['name' => $name]);
252-
$this->assertCount(1, $results);
253-
254-
// Commit the transaction
255-
$tsx->commit();
256-
257-
// Validate that the node now exists in the database
258-
$results = $this->api->run("MATCH (x:Human {name: \$name}) RETURN x", ['name' => $name]);
259-
$this->assertCount(1, $results); // Updated to expect 1 result
260-
}
261235

262236

263237
/**

tests/Unit/Neo4jQueryAPIUnitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
class Neo4jQueryAPIUnitTest extends TestCase
1919
{
20-
2120
protected string $address;
2221

2322
protected function setUp(): void

0 commit comments

Comments
 (0)