Skip to content

Commit 237f7df

Browse files
PratikshaPratiksha
authored andcommitted
Merge remote-tracking branch 'origin/main' into Psalm
2 parents d973060 + fba075f commit 237f7df

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ test
1313
#PHP-CS-FIXER
1414
.php-cs-fixer.php
1515
.php-cs-fixer.cache
16+
17+

src/OGM.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class OGM
1414
{
1515
/**
16-
* @param array{'$type': string, '_value': mixed} $object
16+
* @param array{'$type': string, ' $object _value': mixed} $object
1717
* @return mixed
1818
*/
1919
public function map(array $object): mixed
@@ -43,7 +43,7 @@ public static function parseWKT(string $wkt): Point
4343
$srid = (int)str_replace('SRID=', '', $sridPart);
4444

4545
$pointPart = substr($wkt, strpos($wkt, 'POINT') + 6);
46-
if (strpos($pointPart, 'Z') !== false) {
46+
if (str_contains($pointPart, 'Z')) {
4747
$pointPart = str_replace('Z', '', $pointPart);
4848
}
4949
$pointPart = trim($pointPart, ' ()');
@@ -67,8 +67,8 @@ public static function parseWKT(string $wkt): Point
6767
private function mapNode(array $nodeData): Node
6868
{
6969
return new Node(
70-
$nodeData['_labels'], // Labels of the node
71-
$this->mapProperties($nodeData['_properties']) // Mapped properties
70+
$nodeData['_labels'],
71+
$this->mapProperties($nodeData['_properties'])
7272
);
7373
}
7474

src/Transaction.php

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

33
namespace Neo4j\QueryAPI;
44

5+
use GuzzleHttp\Exception\GuzzleException;
56
use Neo4j\QueryAPI\Exception\Neo4jException;
67
use Neo4j\QueryAPI\Objects\Authentication;
78
use Neo4j\QueryAPI\Objects\Bookmarks;
@@ -25,11 +26,11 @@ public function __construct(
2526

2627
/**
2728
* Execute a Cypher query within the transaction.
28-
* @api
2929
* @param string $query The Cypher query to be executed.
3030
* @param array $parameters Parameters for the query.
3131
* @return ResultSet The result rows in ResultSet format.
32-
* @throws Neo4jException If the response structure is invalid.
32+
* @throws Neo4jException|GuzzleException If the response structure is invalid.
33+
*@api
3334
*/
3435
public function run(string $query, array $parameters): ResultSet
3536
{

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function testProfileExistence(): void
8787

8888
public function testProfileCreateQueryExistence(): void
8989
{
90+
9091
$query = "
9192
PROFILE UNWIND range(1, 100) AS i
9293
CREATE (:Person {
@@ -188,14 +189,16 @@ public function testProfileCreateKnowsBidirectionalRelationshipsMock(): void
188189

189190
$handler = HandlerStack::create($mockSack);
190191
$client = new Client(['handler' => $handler]);
191-
192-
$auth = Authentication::basic(getenv("NEO4J_USERNAME"), getenv("NEO4J_PASSWORD"));
192+
$auth = Authentication::fromEnvironment();
193193
$api = new Neo4jQueryAPI($client, $auth);
194+
194195
$result = $api->run($query);
195196

196197
$plan = $result->getProfiledQueryPlan();
197198
$this->assertNotNull($plan, "The result of the query should not be null.");
199+
198200
$expected = require __DIR__ . '/../resources/expected/complex-query-profile.php';
201+
199202
$this->assertEquals($expected->getProfiledQueryPlan(), $plan, "Profiled query plan does not match the expected value.");
200203
}
201204

@@ -227,9 +230,6 @@ public function testChildQueryPlanExistence(): void
227230
}
228231

229232

230-
231-
232-
233233
/**
234234
* @throws GuzzleException
235235
*/

tests/Integration/Neo4jTransactionIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private function populateTestData(): void
5656
}
5757
public function testTransactionCommit(): void
5858
{
59+
5960
$tsx = $this->api->beginTransaction();
6061

6162
$name = (string)mt_rand(1, 100000);

tests/Unit/Neo4jRequestFactoryTest.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use GuzzleHttp\Psr7\Request;
1111
use GuzzleHttp\Psr7\Utils;
1212
use Neo4j\QueryAPI\Neo4jRequestFactory;
13+
use Neo4j\QueryAPI\Objects\Authentication;
1314

1415
/**
1516
* @api
@@ -18,8 +19,8 @@ class Neo4jRequestFactoryTest extends TestCase
1819
{
1920
private $psr17Factory;
2021
private $streamFactory;
21-
private string $baseUri = 'https://6f72daa1.databases.neo4j.io';
22-
private string $authHeader = 'Basic dXNlcjpwYXNzd29yZA==';
22+
private string $address;
23+
private string $authHeader;
2324

2425
/**
2526
* @throws Exception
@@ -28,6 +29,11 @@ protected function setUp(): void
2829
{
2930
$this->psr17Factory = $this->createMock(RequestFactoryInterface::class);
3031
$this->streamFactory = $this->createMock(StreamFactoryInterface::class);
32+
33+
$this->address = getenv('NEO4J_ADDRESS');
34+
35+
$auth = Authentication::fromEnvironment();
36+
$this->authHeader = $auth->getHeader();
3137
}
3238

3339
/**
@@ -39,21 +45,16 @@ public function testBuildRunQueryRequest()
3945
$parameters = ['param1' => 'value1'];
4046
$database = 'neo4j';
4147

42-
4348
$payload = json_encode([
4449
'statement' => $cypher,
4550
'parameters' => $parameters,
4651
'includeCounters' => true,
4752
]);
48-
$uri = "{$this->baseUri}/db/{$database}/query/v2";
49-
53+
$uri = "{$this->address}/db/{$database}/query/v2";
5054

5155
$mockRequest = new Request('POST', $uri);
52-
53-
5456
$mockStream = Utils::streamFor($payload);
5557

56-
5758
$this->streamFactory->method('createStream')
5859
->willReturn($mockStream);
5960

@@ -63,7 +64,7 @@ public function testBuildRunQueryRequest()
6364
$factory = new Neo4jRequestFactory(
6465
$this->psr17Factory,
6566
$this->streamFactory,
66-
$this->baseUri,
67+
$this->address,
6768
$this->authHeader
6869
);
6970
$request = $factory->buildRunQueryRequest($database, $cypher, $parameters);
@@ -79,7 +80,7 @@ public function testBuildRunQueryRequest()
7980
public function testBuildBeginTransactionRequest()
8081
{
8182
$database = 'neo4j';
82-
$uri = "{$this->baseUri}/db/{$database}/query/v2/tx";
83+
$uri = "{$this->address}/db/{$database}/query/v2/tx";
8384

8485
$mockRequest = new Request('POST', $uri);
8586
$mockStream = Utils::streamFor('');
@@ -93,9 +94,10 @@ public function testBuildBeginTransactionRequest()
9394
$factory = new Neo4jRequestFactory(
9495
$this->psr17Factory,
9596
$this->streamFactory,
96-
$this->baseUri
97+
$this->address
9798
);
9899
$request = $factory->buildBeginTransactionRequest($database);
100+
99101
$this->assertEquals('POST', $request->getMethod());
100102
$this->assertEquals($uri, (string) $request->getUri());
101103
}
@@ -107,7 +109,7 @@ public function testBuildCommitRequest()
107109
{
108110
$database = 'neo4j';
109111
$transactionId = '12345';
110-
$uri = "{$this->baseUri}/db/{$database}/query/v2/tx/{$transactionId}/commit";
112+
$uri = "{$this->address}/db/{$database}/query/v2/tx/{$transactionId}/commit";
111113

112114
$mockRequest = new Request('POST', $uri);
113115
$mockStream = Utils::streamFor('');
@@ -121,7 +123,7 @@ public function testBuildCommitRequest()
121123
$factory = new Neo4jRequestFactory(
122124
$this->psr17Factory,
123125
$this->streamFactory,
124-
$this->baseUri
126+
$this->address
125127
);
126128
$request = $factory->buildCommitRequest($database, $transactionId);
127129

@@ -136,7 +138,7 @@ public function testBuildRollbackRequest()
136138
{
137139
$database = 'neo4j';
138140
$transactionId = '12345';
139-
$uri = "{$this->baseUri}/db/{$database}/query/v2/tx/{$transactionId}/rollback";
141+
$uri = "{$this->address}/db/{$database}/query/v2/tx/{$transactionId}/rollback";
140142

141143
$mockRequest = new Request('POST', $uri);
142144
$mockStream = Utils::streamFor('');
@@ -150,7 +152,7 @@ public function testBuildRollbackRequest()
150152
$factory = new Neo4jRequestFactory(
151153
$this->psr17Factory,
152154
$this->streamFactory,
153-
$this->baseUri
155+
$this->address
154156
);
155157
$request = $factory->buildRollbackRequest($database, $transactionId);
156158

@@ -159,14 +161,15 @@ public function testBuildRollbackRequest()
159161
}
160162

161163
/**
162-
* Test for the createRequest method (Private method should be tested indirectly through other public methods)
164+
* Test for createRequest method with headers and body
163165
*/
164166
public function testCreateRequestWithHeadersAndBody()
165167
{
166168
$cypher = 'MATCH (n) RETURN n';
167169
$parameters = ['param1' => 'value1'];
168170
$database = 'neo4j';
169-
$uri = "{$this->baseUri}/db/{$database}/query/v2";
171+
$uri = "{$this->address}/db/{$database}/query/v2";
172+
170173
$payload = json_encode([
171174
'statement' => $cypher,
172175
'parameters' => $parameters,
@@ -184,7 +187,7 @@ public function testCreateRequestWithHeadersAndBody()
184187
$factory = new Neo4jRequestFactory(
185188
$this->psr17Factory,
186189
$this->streamFactory,
187-
$this->baseUri,
190+
$this->address,
188191
$this->authHeader
189192
);
190193

@@ -196,13 +199,16 @@ public function testCreateRequestWithHeadersAndBody()
196199
$this->assertJsonStringEqualsJsonString($payload, (string) $request->getBody());
197200
}
198201

199-
202+
/**
203+
* Test createRequest without Authorization header
204+
*/
200205
public function testCreateRequestWithoutAuthorizationHeader()
201206
{
202207
$cypher = 'MATCH (n) RETURN n';
203208
$parameters = ['param1' => 'value1'];
204209
$database = 'neo4j';
205-
$uri = "{$this->baseUri}/db/{$database}/query/v2";
210+
$uri = "{$this->address}/db/{$database}/query/v2";
211+
206212
$payload = json_encode([
207213
'statement' => $cypher,
208214
'parameters' => $parameters,
@@ -220,15 +226,14 @@ public function testCreateRequestWithoutAuthorizationHeader()
220226
$factory = new Neo4jRequestFactory(
221227
$this->psr17Factory,
222228
$this->streamFactory,
223-
$this->baseUri
229+
$this->address
224230
);
225231

226232
$request = $factory->buildRunQueryRequest($database, $cypher, $parameters);
227233

228234
$this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
229235
$this->assertEquals('application/json', $request->getHeaderLine('Accept'));
230236
$this->assertEmpty($request->getHeaderLine('Authorization'));
231-
232237
$this->assertJsonStringEqualsJsonString($payload, (string) $request->getBody());
233238
}
234239
}

0 commit comments

Comments
 (0)