Skip to content

Commit e779928

Browse files
committed
updated the test code
1 parent 0304b66 commit e779928

File tree

5 files changed

+78
-282
lines changed

5 files changed

+78
-282
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
vendor
3-
phpunit.xml
3+
phpunit.xml
4+
test

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,92 @@
22

33
namespace Neo4j\QueryAPI\Tests\Integration;
44

5-
use GuzzleHttp\Client;
6-
use GuzzleHttp\Handler\MockHandler;
7-
use GuzzleHttp\HandlerStack;
8-
use GuzzleHttp\Psr7\Response;
95
use Neo4j\QueryAPI\Neo4jQueryAPI;
6+
use PHPUnit\Framework\Attributes\DataProvider;
107
use PHPUnit\Framework\TestCase;
11-
use function PHPUnit\Framework\assertEquals;
128

139
class Neo4jQueryAPIIntegrationTest extends TestCase
1410
{
1511

16-
protected function setUp(): void
12+
public static function setUpBeforeClass(): void
1713
{
18-
parent::setUp();
19-
// Use environment variables from phpunit.xml
20-
$this->address = getenv('NEO4J_ADDRESS');
21-
$this->username = getenv('NEO4J_USERNAME');
22-
$this->password = getenv('NEO4J_PASSWORD');
14+
$api = Neo4jQueryAPI::login(
15+
'https://bb79fe35.databases.neo4j.io',
16+
'neo4j',
17+
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'
18+
);
19+
20+
// Clear the database
21+
self::clearDatabase($api);
22+
23+
// Create necessary constraints
24+
self::createConstraints($api);
25+
26+
// Insert test data
27+
self::populateFixtures($api, ['bob1', 'alicy']);
28+
29+
// Validate fixtures
30+
self::validateFixtures($api);
31+
}
32+
33+
private static function clearDatabase(Neo4jQueryAPI $api): void
34+
{
35+
$api->run('MATCH (n) DETACH DELETE n',[]);
36+
}
37+
38+
private static function createConstraints(Neo4jQueryAPI $api): void
39+
{
40+
$api->run('CREATE CONSTRAINT IF NOT EXISTS FOR (p:Person1) REQUIRE p.name IS UNIQUE',[]);
2341
}
24-
public function testRunSuccess(): void
42+
43+
private static function populateFixtures(Neo4jQueryAPI $api, array $names): void
2544
{
26-
$api = Neo4jQueryAPI::login('https://bb79fe35.databases.neo4j.io', 'neo4j', 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0');
45+
foreach ($names as $name) {
46+
$api->run('CREATE (:Person {name: $name})', ['name' => $name]);
47+
}
48+
}
49+
50+
private static function validateFixtures(Neo4jQueryAPI $api): void
51+
{
52+
$results = $api->run('MATCH (p:Person) RETURN p.name',[]);
53+
print_r($results);
54+
}
55+
56+
#[DataProvider(methodName: 'queryProvider')]
57+
public function testRunSuccessWithParameters(
58+
string $address,
59+
string $username,
60+
string $password,
61+
string $query,
62+
array $parameters,
63+
array $expectedResults
64+
): void {
65+
$api = Neo4jQueryAPI::login($address, $username, $password);
66+
$results = $api->run($query, $parameters);
67+
68+
// Remove bookmarks if present
69+
unset($results['bookmarks']);
2770

28-
// Run the query and fetch results
29-
$results = $api->run('MATCH (n:Person) RETURN n LIMIT 10',[]);
3071
$this->assertIsArray($results);
72+
$this->assertEquals($expectedResults, $results);
73+
}
74+
75+
public static function queryProvider(): array
76+
{
77+
return [
78+
[
79+
'https://bb79fe35.databases.neo4j.io',
80+
'neo4j',
81+
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0',
82+
'MATCH (n:Person) WHERE n.name IN $names RETURN n.name',
83+
['names' => ['bob1', 'alicy']],
84+
[
85+
'data' => [
86+
['row' => ['n.name' => 'bob1']],
87+
['row' => ['n.name' => 'alicy']],
88+
],
89+
],
90+
],
91+
];
3192
}
3293
}

tests/Integration/Neo4jQueryAPIIntegrationTest1.php

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

tests/Integration/Neo4jQueryAPIIntegrationTest2.php

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

tests/Integration/Neo4jQueryAPIIntegrationTest3.php

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

0 commit comments

Comments
 (0)