Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
6e77dcd
initial scaffold testkit
transistive May 28, 2021
5296950
merged main into testkit
transistive Jun 18, 2021
cf68409
merged main into testkit
transistive Jul 28, 2021
9f05b99
Removed duplicate key in composer.json
transistive Jul 30, 2021
9f3636d
Added psr container to dev requirement
transistive Jul 30, 2021
7eb96e9
fixed psalm issues
transistive Jul 30, 2021
3713585
added testkit auto setup files
transistive Jul 30, 2021
3881784
first successfull test
transistive Jul 31, 2021
f40317a
reworked test acceptance bookkeeping
transistive Jul 31, 2021
ed4116f
completed authentication neo4j tests
transistive Jul 31, 2021
2ee4286
Added all responses to testkit
transistive Jul 31, 2021
ebc3804
added cypher types
transistive Jul 31, 2021
ba9303a
added input types
transistive Jul 31, 2021
629a06a
added feature list
transistive Jul 31, 2021
0a61840
renamed input to request
transistive Jul 31, 2021
9a3216f
refactored handlers to work with requests and responses
transistive Jul 31, 2021
873c861
end of refactor
transistive Jul 31, 2021
1092adb
added verify connectivity handler
transistive Jul 31, 2021
ff2fe5b
renamed ActionInterface to RequestHandlerInterface
transistive Jul 31, 2021
b4bb818
added main repository for objects being tested
transistive Jul 31, 2021
6e640c5
leveraged autowiring functionality of di
transistive Jul 31, 2021
5ce3c52
setup all available handlers
transistive Jul 31, 2021
82ccd99
Fixed bug when first key in list is null using bolt
transistive Jul 31, 2021
ff035c8
greenlit all datatype tests
transistive Jul 31, 2021
cff9295
changed acceptedTests to a blacklist principle
transistive Aug 4, 2021
df0fc35
added configuration to new driver
transistive Aug 4, 2021
4f980b7
reworked error handling backend
transistive Aug 4, 2021
01b3451
added result consume
transistive Aug 6, 2021
883f47e
Merge branch 'main' into testkit
transistive Aug 6, 2021
9f50d88
Merge branch 'main' into testkit
transistive Aug 17, 2021
107b1cd
Merge branch 'full-result' into testkit
transistive Aug 17, 2021
d9cab9e
added summarized result formatter to driver
transistive Aug 17, 2021
31f01a0
bugfixes
transistive Aug 17, 2021
5373f43
added better exception handling when acquiring a connection
transistive Aug 17, 2021
694c720
better exception handling in backend
transistive Aug 17, 2021
b3efee2
Merge branch 'main' into testkit
transistive Aug 18, 2021
3ca0825
added cached iterator to record results
transistive Aug 18, 2021
414b0b3
added seamless integration with iterators
transistive Aug 18, 2021
74f98df
added jsonserializable to enums
transistive Aug 18, 2021
cb16dfb
renamed protocol to better reflect official drivers
transistive Aug 18, 2021
48eed28
seamless integration with iterators
transistive Aug 18, 2021
fd12332
bugfixes
transistive Aug 18, 2021
ba6fca4
initial version of basic bookmarks
transistive Aug 18, 2021
69b313e
ran php cs fixer
transistive Aug 18, 2021
216bd52
fixed unbound relationship bug
transistive Aug 18, 2021
c5bde56
switched to proper getters
transistive Aug 18, 2021
0dcab55
fixed session test
transistive Aug 18, 2021
21ae777
switched to streams instead of sockets
transistive Aug 18, 2021
6f59114
greenlit neo4j tests
transistive Aug 18, 2021
f0fed2c
corrected psalm type annotation
transistive Aug 19, 2021
7318682
corrected tests
transistive Aug 19, 2021
e2b7dd4
phpstorm inspections
transistive Aug 20, 2021
bd6b708
automatically detect default user agent
transistive Aug 20, 2021
dc1df54
merged main into testkit
transistive Nov 9, 2021
582a111
fixed typo in exception message
transistive Nov 9, 2021
236bf06
fixed psalm typing issues
transistive Nov 9, 2021
16bc45b
set default command for testkit-backend
transistive Nov 9, 2021
eb862cd
removed Ds from testkit backend
transistive Nov 9, 2021
ae6119e
bound tsx to session
transistive Nov 9, 2021
6368fde
fixed bug in resutl formatter when first array item is null
transistive Nov 9, 2021
9391690
created flexible stdClass/cyphermap integration
transistive Nov 9, 2021
00d1065
better exception handling when authenticating over bolt
transistive Nov 9, 2021
52b74bd
temp commit
transistive Nov 15, 2021
cc546e2
reworked tests to be more stable
transistive Dec 4, 2021
3b49180
merged testing-transaction into testkit
transistive Dec 4, 2021
2e08cc7
fixed static analysis
transistive Dec 4, 2021
e938902
fixed authentication bug when working with cached connections
transistive Dec 4, 2021
545fdcf
fixed testkit-backend id in response
transistive Dec 4, 2021
2a7c6b3
initial setup teskit ci
transistive Dec 4, 2021
77c126f
further setup python environment
transistive Dec 4, 2021
6ef8ecf
installed requirements in installation step
transistive Dec 4, 2021
991fe0b
setup backend
transistive Dec 4, 2021
c40c19f
set checkout to 4.3
transistive Dec 4, 2021
1aad497
setup composer
transistive Dec 4, 2021
7c20b62
moved backend setup to same step
transistive Dec 5, 2021
9448655
made realm and ticket optional
transistive Dec 5, 2021
55321f6
fixed correct checout behaviour
transistive Dec 5, 2021
95f6090
Merge branch 'main' into testkit
transistive Dec 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/testkit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Testkit Tests

on:
push:
branches: [ '**' ]
pull_request:
branches: ['**']

jobs:
tests:
runs-on: ubuntu-latest
name: "Running Testkit tests for PHP ${{matrix.php-version}} on Neo4j and testkit ${{ matrix.neo4j-version }} with simple config"
strategy:
fail-fast: false
matrix:
neo4j-version: ["3.5", "4.0", "4.1", "4.2", "4.3"]
php-version: ["7.4", "8.0", "8.1"]

services:
neo4j:
image: neo4j:${{ matrix.neo4j-version }}
env:
NEO4J_AUTH: neo4j/test
NEO4JLABS_PLUGINS: '["apoc"]'
ports:
- 7687:7687
- 7474:7474
options: >-
--health-cmd "wget http://localhost:7474 || exit 1"

steps:
- name: Checkout driver
uses: actions/checkout@v2

- uses: php-actions/composer@v6
with:
progress: yes
php_version: ${{ matrix.php-version }}
version: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Checkout TestKit (testing tool)
uses: actions/checkout@v2
with:
repository: neo4j-drivers/testkit
path: testkit
ref: '4.3'

- name: Install dependencies
run: |
sudo apt-get update
# install docker
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
# Python (needed for dummy driver and TestKit)
sudo apt-get install python3 python3-pip
git clone https://github.com/pyenv/pyenv.git .pyenv
python -m pip install --upgrade pip
cd testkit
python -m pip install -r requirements.txt

- name: Run TestKit
env:
TEST_NEO4J_HOST: localhost
TEST_NEO4J_USER: neo4j
TEST_NEO4J_PASS: test
TEST_DRIVER_NAME: php
run: |
php testkit-backend/index.php &
cd testkit
sleep 2
python3 -m unittest -v "tests.neo4j.test_authentication.TestAuthenticationBasic"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Auto committed queries are the most straightforward and most intuitive but have
```php
$client->run(
'MERGE (user {email: $email})', //The query is a required parameter
['email' => '[email protected]'], //Parameters can be optionally added
['email' => '[email protected]'], //Requests can be optionally added
'backup' //The default connection can be overridden
);
```
Expand Down
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"psr/http-client": "^1.0",
"php-http/message": "^1.0",
"php-http/message-factory": "^1.0",
"stefanak-michal/bolt": "^2.5.2",
"stefanak-michal/bolt": "^2.5.3",
"symfony/polyfill-php80": "^1.2",
"ext-json": "*"
},
Expand All @@ -47,7 +47,13 @@
"vimeo/psalm": "^4.13.0",
"friendsofphp/php-cs-fixer": "3.0.2",
"psalm/plugin-phpunit": "^0.15.1",
"vlucas/phpdotenv": "^5.0"
"monolog/monolog": "^2.2",
"psr/log": "^1.1",
"php-di/php-di": "^6.3",
"vlucas/phpdotenv": "^5.0",
"psr/container": "^1.1",
"lctrs/psalm-psr-container-plugin": "^1.3",
"symfony/uid": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -56,7 +62,8 @@
},
"autoload-dev": {
"psr-4": {
"Laudis\\Neo4j\\Tests\\": "tests/"
"Laudis\\Neo4j\\Tests\\": "tests/",
"Laudis\\Neo4j\\TestkitBackend\\": "testkit-backend/src"
}
},
"minimum-stability": "stable"
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ services:
- 9000
env_file:
- .env
testkit-backend:
build:
context: .
dockerfile: Dockerfile
args:
- WITH_XDEBUG=true
working_dir: /opt/project
volumes:
- .:/opt/project
command: php /opt/project/testkit-backend/index.php
networks:
- neo4j
depends_on:
- neo4j
ports:
- "9876:9876"
neo4j:
networks:
- neo4j
Expand Down
9 changes: 8 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
>
<projectFiles>
<directory name="src"/>
<directory ignoreTypeStats="true" name="tests"/>
<directory name="tests"/>
<directory name="testkit-backend"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
Expand Down Expand Up @@ -52,11 +53,17 @@
<directory name="tests"/>
</errorLevel>
</MissingConstructor>
<UncaughtThrowInGlobalScope>
<errorLevel type="suppress">
<file name="testkit-backend/index.php"/>
</errorLevel>
</UncaughtThrowInGlobalScope>
</issueHandlers>
<stubs>
<file name="./vendor/vimeo/psalm/stubs/ext-ds.phpstub"/>
</stubs>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Lctrs\PsalmPsrContainerPlugin\Plugin"/>
</plugins>
</psalm>
11 changes: 10 additions & 1 deletion src/Authentication/BasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

use function base64_encode;
use Bolt\Bolt;
use Bolt\error\MessageException;
use Exception;
use Laudis\Neo4j\Common\TransactionHelper;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Laudis\Neo4j\Databags\Neo4jError;
use Laudis\Neo4j\Exception\Neo4jException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;

Expand Down Expand Up @@ -58,7 +62,12 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
*/
public function authenticateBolt(Bolt $bolt, UriInterface $uri, string $userAgent): void
{
$bolt->init($userAgent, $this->username, $this->password);
try {
$bolt->init($userAgent, $this->username, $this->password);
} catch (MessageException $e) {
$code = TransactionHelper::extractCode($e) ?? '';
throw new Neo4jException([new Neo4jError($code, $e->getMessage())]);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Bolt/BoltConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use function call_user_func;
use function is_callable;
use function is_string;
use Laudis\Neo4j\Client;
use Laudis\Neo4j\Contracts\ConfigInterface;

Expand Down
2 changes: 2 additions & 0 deletions src/Bolt/BoltConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function acquire(
if (!$connection->isOpen()) {
$connection->open();

$authenticate->authenticateBolt($connection->getImplementation(), $connectingTo, $userAgent);

return $connection;
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,7 @@ public function verifyConnectivity(?string $driver = null): bool
*/
private function decideAlias(?string $alias): string
{
if ($alias !== null) {
return $alias;
}

if ($this->default !== null) {
return $this->default;
}

return array_key_first($this->drivers);
return $alias ?? $this->default ?? array_key_first($this->drivers);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Laudis\Neo4j\Contracts;

use Laudis\Neo4j\Databags\Bookmark;
use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Databags\TransactionConfiguration;
use Laudis\Neo4j\Exception\Neo4jException;
Expand Down Expand Up @@ -95,4 +96,6 @@ public function readTransaction(callable $tsxHandler, ?TransactionConfiguration
* @return HandlerResult
*/
public function transaction(callable $tsxHandler, ?TransactionConfiguration $config = null);

// public function getLastBookmark(): Bookmark;
}
77 changes: 77 additions & 0 deletions src/Databags/Bookmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laudis Neo4j package.
*
* (c) Laudis technologies <http://laudis.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Laudis\Neo4j\Databags;

use function bin2hex;
use Exception;
use function random_bytes;
use function substr;

final class Bookmark
{
/** @var list<string> */
private array $bookmarks;

/**
* @param list<string> $bookmarks
*/
public function __construct(?array $bookmarks = null)
{
$this->bookmarks = $bookmarks ?? [];
}

public function isEmpty(): bool
{
return count($this->bookmarks) === 0;
}

/**
* @return list<string>
*/
public function values(): array
{
return $this->bookmarks;
}

/**
* @throws Exception
*/
public function withIncrement(?string $bookmark = null): self
{
$copy = $this->bookmarks;
if ($bookmark === null) {
$bookmark = $this->generateUuidV4();
}
$copy[] = $bookmark;

return new self($copy);
}

/**
* @throws Exception
*/
private function generateUuidV4(): string
{
$uuid = random_bytes(16);
$uuid[6] = ((int) $uuid[6]) & 0x0F | 0x40;
$uuid[8] = ((int) $uuid[8]) & 0x3F | 0x80;
$uuid = bin2hex($uuid);

return substr($uuid, 0, 8).'-'
.substr($uuid, 8, 4).'-'
.substr($uuid, 12, 4).'-'
.substr($uuid, 16, 4).'-'
.substr($uuid, 20, 12);
}
}
34 changes: 34 additions & 0 deletions src/Databags/BookmarkHolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Laudis Neo4j package.
*
* (c) Laudis technologies <http://laudis.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Laudis\Neo4j\Databags;

final class BookmarkHolder
{
private Bookmark $bookmark;

public function __construct(?Bookmark $bookmark = null)
{
$this->bookmark = $bookmark ?? new Bookmark();
}

public function getBookmark(): Bookmark
{
return $this->bookmark;
}

public function setBookmark(Bookmark $bookmark): void
{
$this->bookmark = $bookmark;
}
}
1 change: 1 addition & 0 deletions src/Databags/SessionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function getAccessMode(): AccessMode
{
$accessMode = is_callable($this->accessMode) ? call_user_func($this->accessMode) : $this->accessMode;

/** @psalm-suppress ImpureMethodCall */
return $accessMode ?? AccessMode::WRITE();
}

Expand Down
Loading
Loading