Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
transistive committed Jan 18, 2021
1 parent 15f57c0 commit fece01b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Network/Bolt/BoltDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Laudis\Neo4j\Exception\Neo4jException;
use Laudis\Neo4j\Formatter\BoltCypherFormatter;

/**
* @psalm-type ParsedUrl = array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string}
*/
final class BoltDriver implements DriverInterface
{
/** @var array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string} */
Expand All @@ -35,7 +38,7 @@ final class BoltDriver implements DriverInterface
/**
* BoltConnection constructor.
*
* @param array{fragment?: string, host: string, pass: string, path?: string, port?: int, query?: string, scheme?: string, user: string} $parsedUrl
* @param ParsedUrl $parsedUrl
*/
public function __construct(array $parsedUrl, BoltInjections $injections)
{
Expand Down
70 changes: 70 additions & 0 deletions tests/Integration/BoltDriverIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\Tests\Integration;

use Exception;
use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Exception\Neo4jException;
use Laudis\Neo4j\Network\Bolt\BoltDriver;
use Laudis\Neo4j\Network\Bolt\BoltInjections;
use PHPUnit\Framework\TestCase;

/**
* @psalm-import-type ParsedUrl from BoltDriver
*/
final class BoltDriverIntegration extends TestCase
{
/**
* @throws Exception
*/
public function testValidHostname(): void
{
/** @var ParsedUrl $parsedUrl */
$parsedUrl = parse_url('bolt://neo4j:test@neo4j-42');
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
$session = $driver->aquireSession();
$results = $session->run([new Statement(<<<'CYPHER'
RETURN 1 AS x
CYPHER, [])]);
self::assertEquals(1, $results->first()->first()->get('x'));
}

/**
* @throws Exception
*/
public function testValidUrl(): void
{
$ip = gethostbyname('neo4j-42');
/** @var ParsedUrl $parsedUrl */
$parsedUrl = parse_url('bolt://neo4j:test@'.$ip);
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
$session = $driver->aquireSession();
$results = $session->run([new Statement(<<<'CYPHER'
RETURN 1 AS x
CYPHER, [])]);
self::assertEquals(1, $results->first()->first()->get('x'));
}

/**
* @throws Exception
*/
public function testInvalid(): void
{
/** @var ParsedUrl $parsedUrl */
$parsedUrl = parse_url('bolt://neo4j:[email protected]');
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
$this->expectException(Neo4jException::class);
$driver->aquireSession();
}
}
34 changes: 34 additions & 0 deletions tests/Unit/BoltInjectionsTest.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\Tests\Unit;

use Laudis\Neo4j\Network\Bolt\BoltInjections;
use PHPUnit\Framework\TestCase;

final class BoltInjectionsTest extends TestCase
{
public function testConstruct(): void
{
$injections = BoltInjections::create('test');
self::assertEquals('test', $injections->database());
$injections = new BoltInjections('abc');
self::assertEquals('abc', $injections->database());
}

public function testWithDatabase(): void
{
$injections = new BoltInjections('abc');
self::assertEquals('test', $injections->withDatabase('test')->database());
}
}

0 comments on commit fece01b

Please sign in to comment.