Skip to content

Commit fece01b

Browse files
committed
added more tests
1 parent 15f57c0 commit fece01b

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

src/Network/Bolt/BoltDriver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use Laudis\Neo4j\Exception\Neo4jException;
2525
use Laudis\Neo4j\Formatter\BoltCypherFormatter;
2626

27+
/**
28+
* @psalm-type ParsedUrl = array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string}
29+
*/
2730
final class BoltDriver implements DriverInterface
2831
{
2932
/** @var array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string} */
@@ -35,7 +38,7 @@ final class BoltDriver implements DriverInterface
3538
/**
3639
* BoltConnection constructor.
3740
*
38-
* @param array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string} $parsedUrl
41+
* @param ParsedUrl $parsedUrl
3942
*/
4043
public function __construct(array $parsedUrl, BoltInjections $injections)
4144
{
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Laudis Neo4j package.
7+
*
8+
* (c) Laudis technologies <http://laudis.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\Tests\Integration;
15+
16+
use Exception;
17+
use Laudis\Neo4j\Databags\Statement;
18+
use Laudis\Neo4j\Exception\Neo4jException;
19+
use Laudis\Neo4j\Network\Bolt\BoltDriver;
20+
use Laudis\Neo4j\Network\Bolt\BoltInjections;
21+
use PHPUnit\Framework\TestCase;
22+
23+
/**
24+
* @psalm-import-type ParsedUrl from BoltDriver
25+
*/
26+
final class BoltDriverIntegration extends TestCase
27+
{
28+
/**
29+
* @throws Exception
30+
*/
31+
public function testValidHostname(): void
32+
{
33+
/** @var ParsedUrl $parsedUrl */
34+
$parsedUrl = parse_url('bolt://neo4j:test@neo4j-42');
35+
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
36+
$session = $driver->aquireSession();
37+
$results = $session->run([new Statement(<<<'CYPHER'
38+
RETURN 1 AS x
39+
CYPHER, [])]);
40+
self::assertEquals(1, $results->first()->first()->get('x'));
41+
}
42+
43+
/**
44+
* @throws Exception
45+
*/
46+
public function testValidUrl(): void
47+
{
48+
$ip = gethostbyname('neo4j-42');
49+
/** @var ParsedUrl $parsedUrl */
50+
$parsedUrl = parse_url('bolt://neo4j:test@'.$ip);
51+
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
52+
$session = $driver->aquireSession();
53+
$results = $session->run([new Statement(<<<'CYPHER'
54+
RETURN 1 AS x
55+
CYPHER, [])]);
56+
self::assertEquals(1, $results->first()->first()->get('x'));
57+
}
58+
59+
/**
60+
* @throws Exception
61+
*/
62+
public function testInvalid(): void
63+
{
64+
/** @var ParsedUrl $parsedUrl */
65+
$parsedUrl = parse_url('bolt://neo4j:[email protected]');
66+
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
67+
$this->expectException(Neo4jException::class);
68+
$driver->aquireSession();
69+
}
70+
}

tests/Unit/BoltInjectionsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Laudis Neo4j package.
7+
*
8+
* (c) Laudis technologies <http://laudis.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\Tests\Unit;
15+
16+
use Laudis\Neo4j\Network\Bolt\BoltInjections;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class BoltInjectionsTest extends TestCase
20+
{
21+
public function testConstruct(): void
22+
{
23+
$injections = BoltInjections::create('test');
24+
self::assertEquals('test', $injections->database());
25+
$injections = new BoltInjections('abc');
26+
self::assertEquals('abc', $injections->database());
27+
}
28+
29+
public function testWithDatabase(): void
30+
{
31+
$injections = new BoltInjections('abc');
32+
self::assertEquals('test', $injections->withDatabase('test')->database());
33+
}
34+
}

0 commit comments

Comments
 (0)