|
2 | 2 |
|
3 | 3 | namespace Neo4j\QueryAPI\Tests\Integration; |
4 | 4 |
|
5 | | -use GuzzleHttp\Client; |
6 | | -use GuzzleHttp\Handler\MockHandler; |
7 | | -use GuzzleHttp\HandlerStack; |
8 | | -use GuzzleHttp\Psr7\Response; |
9 | 5 | use Neo4j\QueryAPI\Neo4jQueryAPI; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
10 | 7 | use PHPUnit\Framework\TestCase; |
11 | | -use function PHPUnit\Framework\assertEquals; |
12 | 8 |
|
13 | 9 | class Neo4jQueryAPIIntegrationTest extends TestCase |
14 | 10 | { |
15 | 11 |
|
16 | | - protected function setUp(): void |
| 12 | + public static function setUpBeforeClass(): void |
17 | 13 | { |
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',[]); |
23 | 41 | } |
24 | | - public function testRunSuccess(): void |
| 42 | + |
| 43 | + private static function populateFixtures(Neo4jQueryAPI $api, array $names): void |
25 | 44 | { |
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']); |
27 | 70 |
|
28 | | -// Run the query and fetch results |
29 | | - $results = $api->run('MATCH (n:Person) RETURN n LIMIT 10',[]); |
30 | 71 | $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 | + ]; |
31 | 92 | } |
32 | 93 | } |
0 commit comments