Skip to content

Commit 85c55c3

Browse files
authored
Testing (#4)
* moved prepary body method to HttpCypherFormatter * ran php-cs-fixer * added complex query tests * fixed version 3.5 api * updated jenkinsfile to recreate the database during testing * added typehint for discovery result * further refinement of the docker files
1 parent 1d9a5ea commit 85c55c3

13 files changed

+88
-26
lines changed

Jenkinsfile

+21-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,32 @@ pipeline {
2222
}
2323
stage('Test') {
2424
steps {
25+
sh 'docker-compose -f docker/docker-compose-4.2.yml down --volumes'
26+
sh 'docker-compose -f docker/docker-compose-4.2.yml up -d --force-recreate'
2527
sh 'docker-compose -f docker/docker-compose-4.2.yml run client php vendor/bin/phpunit'
28+
sh 'docker-compose -f docker/docker-compose-4.2.yml down'
29+
30+
31+
sh 'docker-compose -f docker/docker-compose-4.1.yml down --volumes'
32+
sh 'docker-compose -f docker/docker-compose-4.1.yml up -d --force-recreate'
2633
sh 'docker-compose -f docker/docker-compose-4.1.yml run client php vendor/bin/phpunit'
34+
sh 'docker-compose -f docker/docker-compose-4.1.yml down'
35+
36+
37+
sh 'docker-compose -f docker/docker-compose-4.0.yml down --volumes'
38+
sh 'docker-compose -f docker/docker-compose-4.0.yml up -d --force-recreate'
2739
sh 'docker-compose -f docker/docker-compose-4.0.yml run client php vendor/bin/phpunit'
40+
sh 'docker-compose -f docker/docker-compose-4.0.yml down'
41+
42+
43+
sh 'docker-compose -f docker/docker-compose-3.5.yml down --volumes'
44+
sh 'docker-compose -f docker/docker-compose-3.5.yml up -d --force-recreate'
2845
sh 'docker-compose -f docker/docker-compose-3.5.yml run client php vendor/bin/phpunit'
29-
sh 'docker-compose -f docker/docker-compose-2.3.yml run client php vendor/bin/phpunit'
46+
sh 'docker-compose -f docker/docker-compose-3.5.yml down'
47+
48+
// sh 'docker-compose -f docker/docker-compose-2.3.yml run client php vendor/bin/phpunit'
3049
sh 'docker-compose -f docker/docker-compose-php-7.4.yml run client php vendor/bin/phpunit'
50+
sh 'docker-compose -f docker/docker-compose-php-7.4.yml down'
3151
}
3252
}
3353
}

docker/Dockerfile-php-8.0

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y \
1414
ARG WITH_XDEBUG=false
1515

1616
RUN if [ $WITH_XDEBUG = "true" ] ; then \
17-
pecl install xdebug-3; \
17+
pecl install xdebug; \
1818
docker-php-ext-enable xdebug; \
1919
fi;
2020

docker/docker-compose-2.3.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-8.0
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
1517
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

docker/docker-compose-3.5.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-8.0
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
15-
- neo4j
17+
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

docker/docker-compose-4.0.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-8.0
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
15-
- neo4j
17+
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

docker/docker-compose-4.1.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-8.0
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
15-
- neo4j
17+
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

docker/docker-compose-4.2.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-8.0
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
15-
- neo4j
17+
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

docker/docker-compose-php-7.4.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ services:
99
build:
1010
context: ../
1111
dockerfile: docker/Dockerfile-php-7.4
12+
args:
13+
- WITH_XDEBUG=true
1214
networks:
1315
- neo4j
1416
depends_on:
15-
- neo4j
17+
- neo4j
18+
volumes:
19+
- ../:/opt/project
1620
neo4j:
1721
networks:
1822
- neo4j

phpunit-bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Laudis\Neo4j\ClientBuilder;
15-
use Laudis\Neo4j\Exception\Neo4jException;
1615

1716
include __DIR__.'/vendor/autoload.php';
1817

@@ -27,6 +26,7 @@
2726

2827
return;
2928
} catch (Throwable $e) {
29+
error_log($e->getMessage()."\n");
3030
--$retriesLeft;
3131
sleep(5);
3232
}

src/ClientBuilder.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use InvalidArgumentException;
1919
use Laudis\Neo4j\Contracts\ClientInterface;
2020
use Laudis\Neo4j\Contracts\DriverInterface;
21+
use Laudis\Neo4j\Formatter\HttpCypherFormatter;
22+
use Laudis\Neo4j\HttpDriver\RequestFactory;
2123
use Laudis\Neo4j\Network\Bolt\BoltDriver;
2224
use Laudis\Neo4j\Network\Bolt\BoltInjections;
2325
use Laudis\Neo4j\Network\Http\HttpDriver;
@@ -64,7 +66,10 @@ public function addHttpConnection(string $alias, string $url, HttpInjections $in
6466
if (!isset($parse['host'], $parse['user'], $parse['pass'])) {
6567
throw new InvalidArgumentException('The provided url must have a parsed host, user and pass value');
6668
}
67-
$conneciton = new HttpDriver($parse, new VersionDiscovery(), $injections ?? new HttpInjections());
69+
$injections = $injections ?? new HttpInjections();
70+
$factory = $injections->requestFactory();
71+
$requestFactory = new RequestFactory($factory, $injections->streamFactory(), new HttpCypherFormatter());
72+
$conneciton = new HttpDriver($parse, new VersionDiscovery($requestFactory, $injections->client()), $injections);
6873
$this->connectionPool->put($alias, $conneciton);
6974

7075
return $this;

src/HttpDriver/RequestFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function openTransaction(RequestData $data): RequestInterface
4040
return $this->createRequest($data, 'POST');
4141
}
4242

43-
private function createRequest(RequestData $data, string $method, string $body = ''): RequestInterface
43+
public function createRequest(RequestData $data, string $method, string $body = ''): RequestInterface
4444
{
4545
$combo = base64_encode($data->getUser().':'.$data->getPassword());
4646

src/Network/Http/HttpDriver.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ public function aquireSession(): SessionInterface
5959
$this->parsedUrl['port'] ?? self::DEFAULT_PORT,
6060
$this->parsedUrl['path'] ?? ''
6161
);
62-
$tsx = $this->decorator->discoverTransactionUrl($url, $this->injections);
62+
63+
$requestData = new RequestData(
64+
$url,
65+
$this->parsedUrl['user'],
66+
$this->parsedUrl['pass'],
67+
false
68+
);
69+
$tsx = $this->decorator->discoverTransactionUrl($requestData, $this->injections->database());
70+
$requestData = $requestData->withEndpoint($tsx);
6371

6472
$formatter = new HttpCypherFormatter();
6573
$this->session = new HttpSession(
6674
new RequestFactory($this->injections->requestFactory(), $this->injections->streamFactory(), $formatter),
6775
$this->injections->client(),
6876
$formatter,
69-
new RequestData(
70-
$tsx,
71-
$this->parsedUrl['user'],
72-
$this->parsedUrl['pass'],
73-
false
74-
)
77+
$requestData
7578
);
7679

7780
return $this->session;

src/Network/VersionDiscovery.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
namespace Laudis\Neo4j\Network;
1515

1616
use JsonException;
17-
use Laudis\Neo4j\Network\Http\HttpInjections;
17+
use Laudis\Neo4j\Databags\RequestData;
18+
use Laudis\Neo4j\HttpDriver\RequestFactory;
1819
use Psr\Http\Client\ClientExceptionInterface;
1920
use Psr\Http\Client\ClientInterface;
20-
use Psr\Http\Message\RequestFactoryInterface;
2121

2222
/**
2323
* @psalm-type DiscoveryResult = array{
2424
* bolt_routing:string,
2525
* transaction: string,
2626
* bolt_direct: string,
2727
* neo4j_version: string,
28-
* neo4j_edition: string
28+
* neo4j_edition: string,
29+
* data?: string
2930
* }
3031
* @psalm-type DiscoveryResultLegacy = array{
3132
* extensions: array,
@@ -46,21 +47,30 @@
4647
*/
4748
final class VersionDiscovery
4849
{
50+
private RequestFactory $requestFactory;
51+
private ClientInterface $client;
52+
53+
public function __construct(RequestFactory $requestFactory, ClientInterface $client)
54+
{
55+
$this->requestFactory = $requestFactory;
56+
$this->client = $client;
57+
}
58+
4959
/**
5060
* @throws ClientExceptionInterface
5161
* @throws JsonException
5262
*/
53-
public function discoverTransactionUrl(string $url, HttpInjections $injections): string
63+
public function discoverTransactionUrl(RequestData $data, string $database): string
5464
{
55-
$discovery = $this->discovery($injections->client(), $injections->requestFactory(), $url);
65+
$discovery = $this->discovery($data);
5666
$version = $discovery['neo4j_version'] ?? null;
5767

5868
if ($version === null) {
59-
$discovery = $this->discovery($injections->client(), $injections->requestFactory(), $url.'/db/data');
69+
$discovery = $this->discovery($data->withEndpoint($discovery['data'] ?? $data->getEndpoint().'/db/data'));
6070
}
6171
$tsx = $discovery['transaction'];
6272

63-
return str_replace('{databaseName}', $injections->database(), $tsx);
73+
return str_replace('{databaseName}', $database, $tsx);
6474
}
6575

6676
/**
@@ -69,9 +79,9 @@ public function discoverTransactionUrl(string $url, HttpInjections $injections):
6979
*
7080
* @return DiscoveryResult|DiscoveryResultLegacy $discovery
7181
*/
72-
private function discovery(ClientInterface $client, RequestFactoryInterface $factory, string $uri): array
82+
private function discovery(RequestData $data): array
7383
{
74-
$response = $client->sendRequest($factory->createRequest('GET', $uri));
84+
$response = $this->client->sendRequest($this->requestFactory->createRequest($data, 'GET'));
7585

7686
/** @var DiscoveryResultLegacy|DiscoveryResult $result */
7787
$result = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);

0 commit comments

Comments
 (0)