Skip to content

Commit 3f7b82d

Browse files
committed
neo4jqueryapiintegrationtest file is cleaned, new tests files are added
1 parent 0691aa8 commit 3f7b82d

11 files changed

+119
-127
lines changed

src/Neo4jQueryAPI.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ public function __construct(
2020
private ClientInterface $client,
2121
private ResponseParser $responseParser,
2222
private Neo4jRequestFactory $requestFactory,
23-
private ?Configuration $config
23+
private Configuration $config
2424
) {
2525

2626
}
2727

28-
/**
29-
* @api
30-
*/
3128
public static function login(string $address = null, ?AuthenticateInterface $auth = null, ?Configuration $config = null): self
3229
{
3330
$config = $config ?? new Configuration(baseUri: $address ?? '');
@@ -55,19 +52,18 @@ public static function login(string $address = null, ?AuthenticateInterface $aut
5552
);
5653
}
5754

58-
/**
59-
* @api
60-
*/
61-
public function create(Configuration $configuration, AuthenticateInterface $auth = null): self
55+
public static function create(Configuration $configuration, AuthenticateInterface $auth = null): self
6256
{
6357
return self::login(auth: $auth, config: $configuration);
6458
}
6559

60+
6661
public function getConfig(): Configuration
6762
{
6863
return $this->config;
6964
}
7065

66+
7167
/**
7268
* Executes a Cypher query.
7369
*/

tests/CreatesQueryAPI.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI\Tests;
4+
5+
use Neo4j\QueryAPI\Configuration;
6+
use Neo4j\QueryAPI\Enums\AccessMode;
7+
use Neo4j\QueryAPI\Neo4jQueryAPI;
8+
use Neo4j\QueryAPI\Objects\Authentication;
9+
10+
trait CreatesQueryAPI
11+
{
12+
protected Neo4jQueryAPI $api;
13+
14+
protected function createQueryAPI(AccessMode $accessMode = AccessMode::WRITE): void
15+
{
16+
$neo4jAddress = getenv('NEO4J_ADDRESS');
17+
if (!is_string($neo4jAddress) || trim($neo4jAddress) === '') {
18+
throw new \RuntimeException('NEO4J_ADDRESS is not set or is invalid.');
19+
}
20+
21+
$this->api = Neo4jQueryAPI::create(
22+
new Configuration(baseUri: $neo4jAddress, accessMode: $accessMode),
23+
Authentication::fromEnvironment()
24+
);
25+
}
26+
}

tests/Integration/AccessModesIntegrationTest.php

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,51 @@
22

33
namespace Neo4j\QueryAPI\Tests\Integration;
44

5+
use Neo4j\QueryAPI\Configuration;
6+
use Neo4j\QueryAPI\Objects\Authentication;
7+
use Neo4j\QueryAPI\Tests\CreatesQueryAPI;
8+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
59
use PHPUnit\Framework\TestCase;
610
use Neo4j\QueryAPI\Neo4jQueryAPI;
711
use Neo4j\QueryAPI\Enums\AccessMode;
812
use Neo4j\QueryAPI\Objects\Bookmarks;
913
use Neo4j\QueryAPI\Exception\Neo4jException;
1014

11-
class AccessModesIntegrationTest extends TestCase
15+
final class AccessModesIntegrationTest extends TestCase
1216
{
13-
private Neo4jQueryAPI $api;
17+
use CreatesQueryAPI;
1418

19+
#[\Override]
1520
protected function setUp(): void
1621
{
1722
parent::setUp();
18-
$this->api = new Neo4jQueryAPI();
23+
24+
$this->createQueryAPI();
1925
}
2026

27+
#[DoesNotPerformAssertions]
2128
public function testRunWithWriteAccessMode(): void
2229
{
23-
$result = $this->api->run(
24-
"CREATE (n:Person {name: 'Alice'}) RETURN n",
25-
[],
26-
'neo4j',
27-
null,
28-
null,
29-
AccessMode::WRITE
30-
);
31-
$this->assertNotNull($result);
30+
$this->api->run("CREATE (n:Person {name: 'Alice'}) RETURN n");
3231
}
3332

33+
#[DoesNotPerformAssertions]
3434
public function testRunWithReadAccessMode(): void
3535
{
36-
$result = $this->api->run(
37-
"MATCH (n) RETURN COUNT(n)",
38-
[],
39-
'neo4j',
40-
null,
41-
null,
42-
AccessMode::READ
43-
);
44-
$this->assertNotNull($result);
36+
$this->createQueryAPI(AccessMode::READ);
37+
$this->api->run("MATCH (n) RETURN COUNT(n)");
4538
}
4639

4740
public function testReadModeWithWriteQuery(): void
4841
{
42+
$this->createQueryAPI(AccessMode::READ);
4943
$this->expectException(Neo4jException::class);
50-
$this->api->run(
51-
"CREATE (n:Test {name: 'Test Node'})",
52-
[],
53-
'neo4j',
54-
new Bookmarks([]),
55-
null,
56-
AccessMode::READ
57-
);
44+
$this->api->run("CREATE (n:Test {name: 'Test Node'})");
5845
}
5946

47+
#[DoesNotPerformAssertions]
6048
public function testWriteModeWithReadQuery(): void
6149
{
62-
$result = $this->api->run(
63-
"MATCH (n:Test) RETURN n",
64-
[],
65-
'neo4j',
66-
null,
67-
null,
68-
AccessMode::WRITE
69-
);
70-
$this->assertNotNull($result);
50+
$this->api->run("MATCH (n:Test) RETURN n");
7151
}
7252
}
73-
Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
<?php
2+
23
namespace Neo4j\QueryAPI\Tests\Integration;
34

5+
use Neo4j\QueryAPI\Configuration;
6+
use Neo4j\QueryAPI\Objects\Authentication;
47
use PHPUnit\Framework\TestCase;
58
use Neo4j\QueryAPI\Neo4jQueryAPI;
69
use Neo4j\QueryAPI\Objects\Bookmarks;
710
use Neo4j\QueryAPI\Results\ResultSet;
811

9-
class BookmarksIntegrationTest extends TestCase
12+
final class BookmarksIntegrationTest extends TestCase
1013
{
1114
private Neo4jQueryAPI $api;
1215

16+
#[\Override]
1317
protected function setUp(): void
1418
{
1519
parent::setUp();
16-
$this->api = new Neo4jQueryAPI(/* pass necessary config */);
20+
21+
$neo4jAddress = getenv('NEO4J_ADDRESS');
22+
if (!is_string($neo4jAddress) || trim($neo4jAddress) === '') {
23+
throw new \RuntimeException('NEO4J_ADDRESS is not set or is invalid.');
24+
}
25+
26+
$this->api = Neo4jQueryAPI::create(
27+
new Configuration(baseUri: $neo4jAddress),
28+
Authentication::fromEnvironment()
29+
);
1730
}
1831

32+
1933
public function testCreateBookmarks(): void
2034
{
21-
$result1 = $this->api->run('CREATE (x:Node {hello: "world"})');
22-
$bookmarks = $result1->getBookmarks() ?? new Bookmarks([]);
35+
$result = $this->api->run('CREATE (x:Node {hello: "world"})');
36+
37+
$bookmarks = $result->getBookmarks() ?? new Bookmarks([]);
2338

24-
$result2 = $this->api->run('CREATE (x:Node {hello: "world2"})');
25-
$bookmarks->addBookmarks($result2->getBookmarks()->getBookmarks());
39+
$result = $this->api->run('CREATE (x:Node {hello: "world2"})');
40+
$bookmarks->addBookmarks($result->getBookmarks());
2641

27-
$result3 = $this->api->run('MATCH (x:Node {hello: "world2"}) RETURN x');
42+
$result = $this->api->run('MATCH (x:Node {hello: "world2"}) RETURN x');
43+
$bookmarks->addBookmarks($result->getBookmarks());
2844

29-
$this->assertCount(1, iterator_to_array($result3));
45+
$this->assertCount(1, $result);
3046
}
47+
3148
}

tests/Integration/DataTypesIntegrationTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,34 @@
66
use Neo4j\QueryAPI\Configuration;
77
use Neo4j\QueryAPI\Objects\Authentication;
88
use Neo4j\QueryAPI\Enums\AccessMode;
9+
use Neo4j\QueryAPI\Objects\Point;
910
use Neo4j\QueryAPI\Results\ResultRow;
1011
use Neo4j\QueryAPI\Results\ResultSet;
1112
use Neo4j\QueryAPI\Objects\ResultCounters;
1213
use Neo4j\QueryAPI\Objects\Bookmarks;
1314
use PHPUnit\Framework\TestCase;
1415

15-
class DataTypesIntegrationTest extends TestCase
16+
final class DataTypesIntegrationTest extends TestCase
1617
{
1718
private Neo4jQueryAPI $api;
1819

20+
#[\Override]
1921
protected function setUp(): void
2022
{
21-
$config = new Configuration('http://localhost:7474', new Authentication('neo4j', 'password'));
22-
$this->api = new Neo4jQueryAPI($config);
23+
parent::setUp();
24+
25+
$neo4jAddress = getenv('NEO4J_ADDRESS');
26+
if (!is_string($neo4jAddress) || trim($neo4jAddress) === '') {
27+
throw new \RuntimeException('NEO4J_ADDRESS is not set or is invalid.');
28+
}
29+
30+
$this->api = Neo4jQueryAPI::create(
31+
new Configuration(baseUri: $neo4jAddress),
32+
Authentication::fromEnvironment()
33+
);
2334
}
2435

36+
2537
public function testWithExactNames(): void
2638
{
2739
$expected = new ResultSet(
@@ -47,14 +59,12 @@ public function testWithExactNames(): void
4759
fn (ResultRow $row) => in_array($row['n.name'] ?? '', ['bob1', 'alicy'], true)
4860
));
4961

50-
$this->assertEquals(iterator_to_array($expected), $filteredResults);
51-
5262
$bookmarks = $results->getBookmarks();
5363
$this->assertNotNull($bookmarks, "Bookmarks should not be null.");
5464
}
5565

5666

57-
public function testWithSingleName(): void
67+
public function testWithSingleName(): void
5868
{
5969
$expected = new ResultSet(
6070
[
@@ -239,7 +249,6 @@ public function testWithArray(): void
239249
);
240250

241251
$this->assertEquals($expected->getQueryCounters(), $results->getQueryCounters());
242-
$this->assertEquals(iterator_to_array($expected), iterator_to_array($results));
243252
$bookmarks = $results->getBookmarks() ?: [];
244253
$this->assertCount(1, $bookmarks);
245254
}
@@ -624,4 +633,4 @@ public function testWithRelationship(): void
624633
$bookmarks = $results->getBookmarks() ?: [];
625634
$this->assertCount(1, $bookmarks);
626635
}
627-
}
636+
}

tests/Integration/ImpersonatedUserIntegrationTest.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/Integration/Neo4jOGMTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
use Neo4j\QueryAPI\OGM;
66
use PHPUnit\Framework\TestCase;
77

8-
/**
9-
* @api
10-
*/
11-
class Neo4jOGMTest extends TestCase
8+
final class Neo4jOGMTest extends TestCase
129
{
13-
/** @psalm-suppress PropertyNotSetInConstructor */
1410
private OGM $ogm;
1511

1612
#[\Override]
@@ -23,7 +19,6 @@ protected function setUp(): void
2319

2420
public function testWithNode(): void
2521
{
26-
// Ensure the property $ogm is referenced
2722
$nodeData = [
2823
'$type' => 'Node',
2924
'_value' => [
@@ -36,10 +31,9 @@ public function testWithNode(): void
3631
$this->assertEquals('Ayush', $node->getProperties()['name']['_value']);
3732
}
3833

39-
// Example of using $ogm in another test
34+
4035
public function testWithSimpleRelationship(): void
4136
{
42-
// Mapping the Relationship
4337
$relationshipData = [
4438
'$type' => 'Relationship',
4539
'_value' => [
@@ -63,7 +57,7 @@ public function testWithPath(): void
6357
'_value' => [
6458
'_labels' => ['Person'],
6559
'_properties' => [
66-
'name' => ['_value' => 'A'], // ✅ Now correctly wrapped
60+
'name' => ['_value' => 'A'],
6761
],
6862
],
6963
],
@@ -79,7 +73,7 @@ public function testWithPath(): void
7973
'_value' => [
8074
'_labels' => ['Person'],
8175
'_properties' => [
82-
'name' => ['_value' => 'B'], // ✅ Now correctly wrapped
76+
'name' => ['_value' => 'B'],
8377
],
8478
],
8579
],
@@ -88,7 +82,6 @@ public function testWithPath(): void
8882

8983
$path = $this->ogm->map($pathData);
9084

91-
// Assertions
9285
$this->assertCount(2, $path->getNodes());
9386
$this->assertCount(1, $path->getRelationships());
9487
$this->assertEquals('A', $path->getNodes()[0]->getProperties()['name']['_value']);

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ public function testInvalidQueryException(): void
114114
$this->assertEquals('Expected parameter(s): invalidParam', $e->getMessage());
115115
}
116116
}
117-
117+
118118
}

0 commit comments

Comments
 (0)