Skip to content

Commit 5c6e5ab

Browse files
authored
Fix Testkit basic-query tests and cleanup (remove broken CC link) (#267)
- fixed all the basic-query testkit tests - removed broken cc link - Improve exception taxonomy (SSLConnectionxceiptn, TimeoutException) - Improve element ID support - Add proper feature suport for testkit
1 parent fb146d9 commit 5c6e5ab

27 files changed

+1549
-59
lines changed

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PHP_VERSION
1+
ARG PHP_VERSION=8.1
22

33
FROM php:${PHP_VERSION}-cli
44
RUN apt-get update \
@@ -8,9 +8,6 @@ RUN apt-get update \
88
git \
99
wget \
1010
&& docker-php-ext-install -j$(nproc) bcmath sockets \
11-
&& wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 \
12-
&& mv test-reporter-latest-linux-amd64 /usr/bin/cc-test-reporter \
13-
&& chmod +x /usr/bin/cc-test-reporter \
1411
&& pecl install xdebug \
1512
&& docker-php-ext-enable xdebug && \
1613
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Dockerfile.neo4j-okta

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM neo4j:5-enterprise
2+
3+
COPY ./neo4j-with-okta.conf /var/lib/neo4j/conf/neo4j.conf

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
- .env
5454
neo4j:
5555
<<: *common
56-
image: neo4j:5.23-community
56+
image: neo4j:5.23-enterprise
5757
hostname: neo4j
5858
networks:
5959
- neo4j
@@ -62,6 +62,7 @@ services:
6262
- "11474:7474"
6363
environment:
6464
<<: *common-env
65+
NEO4J_ACCEPT_LICENSE_AGREEMENT: 'yes' # Also add this
6566
NEO4J_server_bolt_advertised__address: neo4j:7687
6667
NEO4J_server_http_advertised__address: neo4j:7474
6768

neo4j-with-okta.conf

Lines changed: 829 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Neo4j PHP Client and Driver package.
7+
*
8+
* (c) Nagels <https://nagels.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Laudis\Neo4j\Exception;
15+
16+
use RuntimeException;
17+
18+
final class SSLConnectionException extends RuntimeException
19+
{
20+
}

src/Exception/TimeoutException.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Neo4j PHP Client and Driver package.
7+
*
8+
* (c) Nagels <https://nagels.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Laudis\Neo4j\Exception;
15+
16+
use RuntimeException;
17+
18+
class TimeoutException extends RuntimeException
19+
{
20+
}

src/Formatter/Specialised/BoltOGMTranslator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ private function makeFromBoltRelationship(BoltRelationship $rel): Relationship
178178
foreach ($rel->properties as $key => $property) {
179179
$map[$key] = $this->mapValueToType($property);
180180
}
181+
/** @var string|null $elementId */
182+
$startNodeElementId = null;
183+
$endNodeElementId = null;
181184

182185
/** @var string|null $elementId */
183186
$elementId = null;
@@ -191,7 +194,9 @@ private function makeFromBoltRelationship(BoltRelationship $rel): Relationship
191194
$rel->endNodeId,
192195
$rel->type,
193196
new CypherMap($map),
194-
$elementId
197+
$elementId,
198+
$startNodeElementId, // Add this parameter
199+
$endNodeElementId
195200
);
196201
}
197202

src/Types/Relationship.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
final class Relationship extends UnboundRelationship
2626
{
27+
private string $startNodeElementId;
28+
private string $endNodeElementId;
29+
2730
/**
2831
* @param CypherMap<OGMTypes> $properties
2932
*/
@@ -34,8 +37,17 @@ public function __construct(
3437
string $type,
3538
CypherMap $properties,
3639
?string $elementId,
40+
int|string|null $startNodeElementId = null,
41+
int|string|null $endNodeElementId = null,
3742
) {
3843
parent::__construct($id, $type, $properties, $elementId);
44+
$this->startNodeElementId = $startNodeElementId !== null
45+
? (string) $startNodeElementId
46+
: (string) $startNodeId;
47+
48+
$this->endNodeElementId = $endNodeElementId !== null
49+
? (string) $endNodeElementId
50+
: (string) $endNodeId;
3951
}
4052

4153
/**

src/Types/UnboundRelationship.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ class UnboundRelationship extends AbstractPropertyObject
3232
/**
3333
* @param CypherMap<OGMTypes> $properties
3434
*/
35+
private string $elementId;
36+
3537
public function __construct(
3638
private readonly int $id,
3739
private readonly string $type,
3840
private readonly CypherMap $properties,
39-
private readonly ?string $elementId,
41+
?string $elementId = null,
4042
) {
43+
$this->elementId = $elementId ?? (string) $id;
4144
}
4245

4346
public function getElementId(): ?string
@@ -55,6 +58,9 @@ public function getType(): string
5558
return $this->type;
5659
}
5760

61+
/**
62+
* @psalm-suppress MixedReturnTypeCoercion
63+
*/
5864
public function getProperties(): CypherMap
5965
{
6066
/** @psalm-suppress InvalidReturnStatement false positive with type alias. */
@@ -80,7 +86,11 @@ public function toArray(): array
8086
*
8187
* @return OGMTypes
8288
*/
83-
public function getProperty(string $key)
89+
90+
/**
91+
* @psalm-suppress MixedReturnStatement
92+
*/
93+
public function getProperty(string $key): string
8494
{
8595
/** @psalm-suppress ImpureMethodCall */
8696
if (!$this->properties->hasKey($key)) {

test-basic.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require_once 'vendor/autoload.php';
3+
4+
use Laudis\Neo4j\ClientBuilder;
5+
use Laudis\Neo4j\Authentication\Authenticate;
6+
7+
$client = ClientBuilder::create()
8+
->withDriver('bolt', 'bolt://localhost:7687',
9+
Authenticate::basic('neo4j', 'testtest')
10+
)
11+
->build();
12+
13+
try {
14+
$result = $client->run('RETURN "Hello World" as message');
15+
echo "Connection successful!\n";
16+
print_r($result->first()->get('message'));
17+
} catch (Exception $e) {
18+
echo "Connection failed: " . $e->getMessage() . "\n";
19+
}
20+
?>

0 commit comments

Comments
 (0)