Skip to content

Commit e31d22b

Browse files
authored
Integration test cleanup
* add coverage to gitignore * guzzle was replaced by psr client and discovery * psr has been applied, guzzle is altered * remove composer.lock file * initial working of readme * neo4jqueryapiintegrationtest file is cleaned, new tests files are added * cleaning up getters
1 parent 61c9476 commit e31d22b

27 files changed

+1064
-1095
lines changed

Contributing.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Contributing to Neo4j QueryAPI he PHP Client
2+
3+
Thank you for your interest in contributing to the Neo4j QueryAPI PHP Client! We welcome all contributions, whether it's bug fixes, feature enhancements, or documentation improvements.
4+
5+
## Getting Started
6+
7+
1. **Fork the Repository**\
8+
Click the "Fork" button at the top right of the repository page.
9+
10+
2. **Clone Your Fork**
11+
12+
```bash
13+
git clone https://github.com/your-username/Neo4j-Client.git
14+
cd Neo4j-Client
15+
```
16+
17+
3. **Set Up the Environment**
18+
19+
- Ensure you have PHP installed (compatible with PHP < 7.1).
20+
- Install dependencies using Composer:
21+
22+
```bash
23+
composer install
24+
```
25+
26+
- Copy the `phpunit.dist.xml` file to `phpunit.xml` and configure the necessary environment variables like `NEO4J_ADDRESS`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`.
27+
28+
29+
30+
4. **Run Tests**\
31+
Our tests use PHPUnit. To run tests:
32+
33+
```bash
34+
composer/phpunit
35+
```
36+
37+
## Code Guidelines
38+
39+
- Ensure your code is **PSR-12 compliant**.
40+
- Use **Psalm** for static analysis. Run:
41+
```bash
42+
composer psalm
43+
```
44+
- Apply **code style fixes** using:
45+
```bash
46+
composer cs:fix
47+
```
48+
49+
## Making Changes
50+
51+
1. **Create a New Branch**\
52+
Use a descriptive branch name:
53+
54+
```bash
55+
git checkout -b fix/issue-123
56+
```
57+
58+
2. **Make Your Edits**\
59+
Ensure all tests pass and code is properly formatted.
60+
61+
3. **Commit Your Changes**\
62+
Write clear commit messages:
63+
64+
```bash
65+
git commit -m "Fix: Corrected query parsing for ProfiledQueryPlan"
66+
```
67+
68+
4. **Push Your Branch**
69+
70+
```bash
71+
git push origin fix/issue-123
72+
```
73+
74+
## Submitting a Pull Request
75+
76+
1. Go to your forked repository on GitHub.
77+
2. Click on the "New pull request" button.
78+
3. Select your branch and submit the pull request.
79+
4. Add a clear description of the changes you made.
80+
81+
## Review Process
82+
83+
- All PRs are reviewed by the maintainers.
84+
- Ensure CI tests pass before requesting a review.
85+
- Be open to feedback and make revisions as needed.
86+
87+
## Reporting Issues
88+
89+
If you spot a bug or want to suggest a new feature, please [open an issue](https://github.com/NagelsIT/Neo4j-Client/issues) and provide detailed information.
90+
91+
---
92+
93+
We appreciate your contribution — let’s build something powerful together!
94+

README.md

Lines changed: 132 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,138 @@
1+
Neo4jQueryAPI client
2+
3+
The Neo4j QueryAPI client is for developers and data engineers who want to interact programmatically with Neo4j databases — running queries, handling results, and managing database configurations. It offers:
4+
5+
- Easy configuration to pick and choose drivers
6+
- An intuitive API for smooth query execution
7+
- Extensibility for custom use cases
8+
- Built and tested under close collaboration with the official Neo4j driver team
9+
- Easier to start with, just need a client to any neo4j instance
10+
- Fully typed with Psalm and CS fixed for code quality
11+
- It does not supports Bolt, Rather compatible with HTTP, and auto-routed drivers
12+
13+
14+
115
# Query API
216

3-
Usage example:
17+
A PHP client for Neo4j, a graph database.
18+
19+
## Installation
20+
21+
You can install the package via Composer:
22+
23+
```sh
24+
composer require this-repo/neo4j-client
25+
```
26+
27+
## Usage
28+
29+
### Connecting to Neo4j
430

531
```php
632
use Neo4j\QueryAPI\Neo4jQueryAPI;
7-
use Neo4j\QueryAPI\Objects\Authentication;
33+
use Neo4j\QueryAPI\Authentication\AuthenticateInterface;
34+
35+
$client = Neo4jQueryAPI::login('http://localhost:7474', new AuthenticateInterface('username', 'password'));
36+
```
37+
38+
### Running a Query
39+
40+
```php
41+
$query = 'MATCH (n) RETURN n';
42+
$result = $client->run($query);
43+
44+
foreach ($result as $record) {
45+
print_r($record);
46+
}
47+
```
48+
49+
### Transactions
50+
51+
#### Begin a Transaction
52+
53+
```php
54+
$transaction = $client->beginTransaction();
55+
```
56+
57+
#### Run a Query in a Transaction
58+
59+
```php
60+
$query = 'CREATE (n:Person {name: $name}) RETURN n';
61+
$parameters = ['name' => 'John Doe'];
62+
$result = $transaction->run($query, $parameters);
63+
```
64+
65+
#### Commit a Transaction
66+
67+
```php
68+
$transaction->commit();
69+
```
70+
71+
#### Rollback a Transaction
72+
73+
```php
74+
$transaction->rollback();
75+
```
76+
77+
## Testing
78+
79+
To run the tests, execute the following command:
80+
81+
```sh
82+
vendor/bin/phpunit
83+
```
84+
85+
Cypher values and types map to these php types and classes:
86+
87+
| Cypher | PHP |
88+
|--------------------|:-----------------:|
89+
| Single name | |
90+
| Integer | ``` * int ``` |
91+
| Float | ``` * float ``` |
92+
| Boolean | ``` * bool ``` |
93+
| Null | ``` * null ``` |
94+
| String | ``` * string ``` |
95+
| Array | |
96+
| Date | |
97+
| Duration | |
98+
| 2D Point | |
99+
| 3D Point | |
100+
| Cartesian 2D Point | |
101+
| Cartesian 3D Point | |
102+
| Node | |
103+
| Path | |
104+
| Map | |
105+
| Exact name | |
106+
| Bookmarks | Yes |
107+
108+
## Diving deeper:
109+
110+
| Feature | Supported? |
111+
|----------|:-------------:|
112+
| Authentication | Yes |
113+
| Transaction | Yes |
114+
| HTTP | Yes |
115+
| Cluster | Yes |
116+
| Aura | Partly (recent versions) |
117+
| Bookmarks | Yes |
118+
119+
> **_NOTE:_** It supports neo4j databases versions > 5.25 (which has QueryAPI enabled.)
120+
121+
122+
123+
## Contributing
124+
125+
Please see CONTRIBUTING for details.
126+
127+
## Security
128+
129+
If you discover any security-related issues, please email *[email protected]* instead of using the issue tracker.
130+
131+
## Credits
132+
133+
- [Your Name](https://github.com/your-github-username)
134+
- [All Contributors](https://github.com/your-repo/neo4j-client/graphs/contributors)
135+
136+
## License
8137

9-
$client = Neo4jQueryAPI::login('https://myaddress.com', Authentication::bearer('mytokken'))
10-
```
138+
The MIT License (MIT). Please see License File for more information.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"scripts": {
5252
"cs": "vendor/bin/php-cs-fixer fix --dry-run --diff --allow-risky=yes",
5353
"cs:fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
54-
"psalm": "vendor/bin/psalm --no-cache --show-info=true"
54+
"psalm": "vendor/bin/psalm --no-cache --show-info=true",
55+
"phpunit" : "vendor/bin/phpunit"
5556
}
5657

5758
}

phpunit.dist.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
<log type="testdox" target="php://stdout" />
1414
</logging>
1515
-->
16+
17+
<!-- <env name="NEO4J_ADDRESS" value="<put your address here>"/>-->
18+
<!-- <env name="NEO4J_USERNAME" value="<put your name here>"/>-->
19+
<!-- <env name="NEO4J_PASSWORD" value="<put your password here>"/>-->
1620
<!-- No need to set sensitive information here -->
1721
</phpunit>

src/Neo4jQueryAPI.php

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

55
use Http\Discovery\Psr17FactoryDiscovery;
66
use Http\Discovery\Psr18ClientDiscovery;
7-
use http\Exception\RuntimeException;
87
use InvalidArgumentException;
98
use Neo4j\QueryAPI\Exception\Neo4jException;
109
use Psr\Http\Client\ClientInterface;
@@ -16,20 +15,15 @@
1615

1716
final class Neo4jQueryAPI
1817
{
19-
private Configuration $config;
20-
2118
public function __construct(
2219
private ClientInterface $client,
2320
private ResponseParser $responseParser,
2421
private Neo4jRequestFactory $requestFactory,
25-
?Configuration $config = null
22+
private Configuration $config
2623
) {
27-
$this->config = $config ?? new Configuration(baseUri: 'http://myaddress'); // Default configuration if not provided
24+
2825
}
2926

30-
/**
31-
* @api
32-
*/
3327
public static function login(string $address = null, ?AuthenticateInterface $auth = null, ?Configuration $config = null): self
3428
{
3529
$config = $config ?? new Configuration(baseUri: $address ?? '');
@@ -57,19 +51,18 @@ public static function login(string $address = null, ?AuthenticateInterface $aut
5751
);
5852
}
5953

60-
/**
61-
* @api
62-
*/
63-
public function create(Configuration $configuration, AuthenticateInterface $auth = null): self
54+
public static function create(Configuration $configuration, AuthenticateInterface $auth = null): self
6455
{
6556
return self::login(auth: $auth, config: $configuration);
6657
}
6758

59+
6860
public function getConfig(): Configuration
6961
{
7062
return $this->config;
7163
}
7264

65+
7366
/**
7467
* Executes a Cypher query.
7568
*/
@@ -122,7 +115,7 @@ private function handleRequestException(RequestExceptionInterface $e): void
122115
$response = method_exists($e, 'getResponse') ? $e->getResponse() : null;
123116

124117
if ($response instanceof ResponseInterface) {
125-
$errorResponse = json_decode((string) $response->getBody(), true);
118+
$errorResponse = json_decode((string)$response->getBody(), true);
126119
throw Neo4jException::fromNeo4jResponse($errorResponse, $e);
127120
}
128121

src/Neo4jRequestFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\StreamFactoryInterface;
1010

11-
/**
12-
* @api
13-
*/
1411
class Neo4jRequestFactory
1512
{
1613
public function __construct(

src/OGM.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use Neo4j\QueryAPI\Objects\Path;
99
use InvalidArgumentException;
1010

11-
/**
12-
* @api
13-
*/
1411
class OGM
1512
{
1613
/**
@@ -57,14 +54,14 @@ private function mapNode(array $nodeData): Node
5754
{
5855
return new Node(
5956
labels: $nodeData['_labels'] ?? [],
60-
properties: $this->mapProperties($nodeData['_properties'] ?? []) // ✅ Fix: Ensure properties exist
57+
properties: $this->mapProperties($nodeData['_properties'] ?? [])
6158
);
6259
}
6360

6461
private function mapRelationship(array $relationshipData): Relationship
6562
{
6663
return new Relationship(
67-
type: $relationshipData['_type'] ?? 'UNKNOWN', // ✅ Fix: Default to 'UNKNOWN'
64+
type: $relationshipData['_type'] ?? 'UNKNOWN',
6865
properties: $this->mapProperties($relationshipData['_properties'] ?? [])
6966
);
7067
}

src/Objects/Authentication.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use Neo4j\QueryAPI\Authentication\BearerAuthentication;
88
use Neo4j\QueryAPI\Authentication\NoAuth;
99

10-
/**
11-
* @api
12-
*/
1310
class Authentication
1411
{
1512
public static function basic(string $username, string $password): AuthenticateInterface
@@ -32,9 +29,6 @@ public static function fromEnvironment(): AuthenticateInterface
3229
);
3330
}
3431

35-
36-
37-
3832
public static function noAuth(): AuthenticateInterface
3933
{
4034
return new NoAuth();

src/Objects/Bookmarks.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use JsonSerializable;
66

7-
/**
8-
* @api
9-
*/
10-
class Bookmarks implements \Countable, JsonSerializable
7+
final class Bookmarks implements \Countable, JsonSerializable
118
{
129
public function __construct(private array $bookmarks)
1310
{

0 commit comments

Comments
 (0)