Skip to content

Commit 1927662

Browse files
committed
extended test coverage
1 parent 2f3c148 commit 1927662

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

phpunit.coverage.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<report>
1515
<clover outputFile="out/phpunit/clover.xml" />
1616
<html outputDirectory="out/phpunit/html" />
17+
<xml outputDirectory="out/phpunit/xml"/>
18+
<text outputFile="out/phpunit/out.txt"/>
19+
<php outputFile="out/phpunit/out.php"/>
20+
<crap4j outputFile="out/phpunit/crap4j.xml"/>
1721
</report>
1822
<include>
1923
<directory suffix=".php">src</directory>

src/ClientBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function addBoltConnection(string $alias, string $url, BoltInjections $pr
5555
}
5656

5757
/**
58-
* Adds a new http connection with the given alias and over the provided url. The configuration will be merged with the one in the client, if provided.
58+
* Adds a new http connection with the given alias and over t he provided url. The configuration will be merged with the one in the client, if provided.
5959
*/
6060
public function addHttpConnection(string $alias, string $url, HttpInjections $injections = null): ClientBuilder
6161
{

tests/Integration/BoltDriverIntegration.php renamed to tests/Integration/BoltDriverIntegrationTest.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* @psalm-import-type ParsedUrl from BoltDriver
2525
*/
26-
final class BoltDriverIntegration extends TestCase
26+
final class BoltDriverIntegrationTest extends TestCase
2727
{
2828
/**
2929
* @throws Exception
@@ -32,8 +32,7 @@ public function testValidHostname(): void
3232
{
3333
/** @var ParsedUrl $parsedUrl */
3434
$parsedUrl = parse_url('bolt://neo4j:test@neo4j-42');
35-
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
36-
$session = $driver->aquireSession();
35+
$session = (new BoltDriver($parsedUrl, BoltInjections::create()))->aquireSession();
3736
$results = $session->run([new Statement(<<<'CYPHER'
3837
RETURN 1 AS x
3938
CYPHER, [])]);
@@ -48,8 +47,7 @@ public function testValidUrl(): void
4847
$ip = gethostbyname('neo4j-42');
4948
/** @var ParsedUrl $parsedUrl */
5049
$parsedUrl = parse_url('bolt://neo4j:test@'.$ip);
51-
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
52-
$session = $driver->aquireSession();
50+
$session = (new BoltDriver($parsedUrl, BoltInjections::create()))->aquireSession();
5351
$results = $session->run([new Statement(<<<'CYPHER'
5452
RETURN 1 AS x
5553
CYPHER, [])]);
@@ -59,7 +57,19 @@ public function testValidUrl(): void
5957
/**
6058
* @throws Exception
6159
*/
62-
public function testInvalid(): void
60+
public function testInvalidIp(): void
61+
{
62+
/** @var ParsedUrl $parsedUrl */
63+
$parsedUrl = parse_url('bolt://neo4j:[email protected]');
64+
$driver = new BoltDriver($parsedUrl, BoltInjections::create());
65+
$this->expectException(Neo4jException::class);
66+
$driver->aquireSession();
67+
}
68+
69+
/**
70+
* @throws Exception
71+
*/
72+
public function testInvalidSocket(): void
6373
{
6474
/** @var ParsedUrl $parsedUrl */
6575
$parsedUrl = parse_url('bolt://neo4j:[email protected]');

tests/Unit/HttpInjectionsTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
5+
namespace Laudis\Neo4j\Tests\Unit;
6+
7+
8+
use Laudis\Neo4j\Network\Http\HttpInjections;
9+
use PHPUnit\Framework\TestCase;
10+
use Psr\Http\Client\ClientInterface;
11+
use Psr\Http\Message\RequestFactoryInterface;
12+
use Psr\Http\Message\StreamFactoryInterface;
13+
14+
final class HttpInjectionsTest extends TestCase
15+
{
16+
public function testConstruct(): void
17+
{
18+
$injections = HttpInjections::create();
19+
self::assertEquals('neo4j', $injections->database());
20+
$injections = new HttpInjections('abc');
21+
self::assertEquals('abc', $injections->database());
22+
}
23+
24+
public function testWithDatabase(): void
25+
{
26+
self::assertEquals('test', HttpInjections::create()->withDatabase('test')->database());
27+
self::assertEquals('test', HttpInjections::create()->withDatabase(static fn () => 'test')->database());
28+
}
29+
30+
public function testWithClient(): void
31+
{
32+
$client = $this->getMockBuilder(ClientInterface::class)->getMock();
33+
self::assertSame($client, HttpInjections::create()->withClient($client)->client());
34+
self::assertSame($client, HttpInjections::create()->withClient(static fn () => $client)->client());
35+
}
36+
37+
public function testWithRequestFactory(): void
38+
{
39+
$factory = $this->getMockBuilder(RequestFactoryInterface::class)->getMock();
40+
self::assertSame($factory, HttpInjections::create()->withRequestFactory($factory)->requestFactory());
41+
self::assertSame($factory, HttpInjections::create()
42+
->withRequestFactory(static fn () => $factory)->requestFactory()
43+
);
44+
}
45+
46+
public function testWithStreamFactory(): void
47+
{
48+
$factory = $this->getMockBuilder(StreamFactoryInterface::class)->getMock();
49+
self::assertSame($factory, HttpInjections::create()->withStreamFactory($factory)->streamFactory());
50+
self::assertSame($factory, HttpInjections::create()->withStreamFactory(static fn () => $factory)->streamFactory());
51+
}
52+
}

0 commit comments

Comments
 (0)