|
| 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 | +} |
0 commit comments