Skip to content

Commit 1a29234

Browse files
committed
creating a Ci integration for github action
1 parent f9339ac commit 1a29234

File tree

5 files changed

+86
-37
lines changed

5 files changed

+86
-37
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- '**' # Ignore all branches pushed as part of a pull request
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
concurrency:
12+
group: ${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
tests:
17+
name: Run PHPUnit Tests
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
24+
- name: Set up PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: 8.2
28+
tools: composer, xdebug
29+
30+
- name: Cache Composer dependencies
31+
uses: actions/cache@v3
32+
with:
33+
path: vendor
34+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
35+
restore-keys: ${{ runner.os }}-composer-
36+
37+
- name: Install dependencies
38+
run: composer install --no-progress --prefer-dist
39+
40+
- name: Verify phpunit.xml
41+
run: |
42+
if [ ! -f phpunit.xml ]; then
43+
echo "phpunit.xml not found, ensure the configuration file exists."
44+
exit 1
45+
fi
46+
47+
- name: Run Tests
48+
run: vendor/bin/phpunit

src/query-api-test.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<?php
22

33
use Neo4j\QueryAPI\Neo4jQueryAPI;
4+
use GuzzleHttp\Exception\RequestException;
45

56
require __DIR__ . '/../vendor/autoload.php';
67

7-
$api = Neo4jQueryAPI::login('https://bb79fe35.databases.neo4j.io', 'neo4j', 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0');
88

9-
// Run the query and fetch results
10-
$results = $api->run('MATCH (n:Person) RETURN n.name LIMIT 10');
9+
// Login to the Neo4j instance
10+
$api = Neo4jQueryAPI::login(
11+
'https://bb79fe35.databases.neo4j.io',
12+
'neo4j',
13+
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'
14+
);
1115

16+
// Run a query to fetch results
17+
$query = 'MATCH (n:Person) RETURN n.name LIMIT 10';
18+
$results = $api->run($query, []);
19+
20+
// Display the results
1221
echo "<pre>";
1322
print_r($results);
14-
echo "</pre>";
23+
echo "</pre>";
24+
25+

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class Neo4jQueryAPIIntegrationTest extends TestCase
1616
protected function setUp(): void
1717
{
1818
parent::setUp();
19-
$this->address = 'https://bb79fe35.databases.neo4j.io';
20-
$this->username = 'neo4j';
21-
$this->password = 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0';
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');
2223
}
2324
public function testRunSuccess(): void
2425
{

tests/Integration/Neo4jQueryAPIIntegrationTest1.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Neo4jQueryAPIIntegrationTest1 extends TestCase
99
{
10-
1110
public static function setUpBeforeClass(): void
1211
{
1312
$api = Neo4jQueryAPI::login(
@@ -16,65 +15,55 @@ public static function setUpBeforeClass(): void
1615
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'
1716
);
1817

19-
2018
self::clearDatabase($api);
21-
2219
self::populateFixtures($api);
2320
}
2421

25-
protected function setUp(): void
26-
{
27-
parent::setUp();
28-
$this->address = 'https://bb79fe35.databases.neo4j.io';
29-
$this->username = 'neo4j';
30-
$this->password = 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0';
31-
$this->query = 'MATCH (n:Person) WHERE n.name IN ["neo4j-php-client", "neo4j-symfony"] RETURN n.name';
32-
}
33-
3422
private static function clearDatabase(Neo4jQueryAPI $api): void
3523
{
36-
3724
$api->run('MATCH (n) DETACH DELETE n', []);
3825
}
3926

40-
4127
private static function populateFixtures(Neo4jQueryAPI $api): void
4228
{
43-
4429
$api->run('CREATE (:Person {name: "neo4j-php-client"})', []);
4530
$api->run('CREATE (:Person {name: "neo4j-symfony"})', []);
4631
}
4732

33+
/**
34+
* @dataProvider queryProvider
35+
*/
4836
public function testRunSuccessWithParameters(
4937
string $address,
5038
string $username,
5139
string $password,
5240
string $query,
53-
array $expectedResults
54-
): void
55-
{
56-
41+
array $expectedResults
42+
): void {
43+
// Login to Neo4j
5744
$api = Neo4jQueryAPI::login($address, $username, $password);
5845

46+
// Execute the query
5947
$results = $api->run($query, []);
6048

49+
// Remove unnecessary data from results
6150
if (isset($results['bookmarks'])) {
6251
unset($results['bookmarks']);
6352
}
6453

54+
// Validate the results
6555
$this->assertIsArray($results);
6656
$this->assertEquals($expectedResults, $results);
6757
}
6858

69-
7059
public static function queryProvider(): array
7160
{
7261
return [
7362
[
74-
'https://bb79fe35.databases.neo4j.io',
75-
'neo4j',
76-
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0',
77-
'MATCH (n:Person) WHERE n.name IN ["neo4j-php-client", "neo4j-symfony"] RETURN n.name',
63+
'https://bb79fe35.databases.neo4j.io', // Address
64+
'neo4j', // Username
65+
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0', // Password
66+
'MATCH (n:Person) WHERE n.name IN ["neo4j-php-client", "neo4j-symfony"] RETURN n.name', // Query
7867
[
7968
'data' => [
8069
['row' => ['n.name' => 'neo4j-php-client']],

tests/Integration/Neo4jQueryAPIIntegrationTest2.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class Neo4jQueryAPIIntegrationTest2 extends TestCase
1212
public static function setUpBeforeClass(): void
1313
{
1414
$api = Neo4jQueryAPI::login(
15-
'https://bb79fe35.databases.neo4j.io',
16-
'neo4j',
17-
'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'
15+
getenv('NEO4J_ADDRESS'),
16+
getenv('NEO4J_USERNAME'),
17+
getenv('NEO4J_PASSWORD')
1818
);
1919

2020
// Clear the database
@@ -30,9 +30,9 @@ public static function setUpBeforeClass(): void
3030
protected function setUp(): void
3131
{
3232
parent::setUp();
33-
$this->address = 'https://bb79fe35.databases.neo4j.io';
34-
$this->username = 'neo4j';
35-
$this->password = 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0';
33+
$this->address = getenv('NEO4J_ADDRESS');
34+
$this->username = getenv('NEO4J_USERNAME');
35+
$this->password = getenv('NEO4J_PASSWORD');
3636
$this->query = 'MATCH (n:Person) RETURN n.name LIMIT 2';
3737
}
3838

0 commit comments

Comments
 (0)