Skip to content

Commit a83fd47

Browse files
exaby73transistive
authored andcommitted
test: Add tests for default configs
1 parent 7d9eee9 commit a83fd47

File tree

2 files changed

+100
-10
lines changed

2 files changed

+100
-10
lines changed

tests/App/config/default.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ neo4j:
2626

2727
drivers:
2828
- alias: neo4j_undefined_configs
29-
dsn: '%neo4j.dsn.badname%'
29+
dsn: "%neo4j.dsn.badname%"
3030

3131
- alias: neo4j-enforced-defaults
32-
dsn: '%neo4j.dsn.badname%'
32+
dsn: "%neo4j.dsn.badname%"
3333
priority: null
3434

3535
- alias: neo4j-partly-enforced-defaults
36-
dsn: '%neo4j.dsn.secret%'
36+
dsn: "%neo4j.dsn.secret%"
3737

3838
- alias: neo4j-simple
39-
dsn: '%neo4j.dsn.simple%'
39+
dsn: "%neo4j.dsn.simple%"
4040

4141
- alias: neo4j-fallback-mechanism
4242
priority: 100
43-
dsn: '%neo4j.dsn.badname%'
43+
dsn: "%neo4j.dsn.badname%"
4444

4545
- alias: neo4j-fallback-mechanism
4646
priority: 1000
47-
dsn: '%neo4j.dsn.badname%'
47+
dsn: "%neo4j.dsn.badname%"
4848

4949
- alias: neo4j-test
50-
dsn: '%neo4j.dsn.test%'
50+
dsn: "%neo4j.dsn.test%"

tests/Functional/IntegrationTest.php

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
<?php
22

3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
35
declare(strict_types=1);
46

57
namespace Neo4j\Neo4jBundle\Tests\Functional;
68

9+
use Laudis\Neo4j\Client;
10+
use Laudis\Neo4j\Common\SingleThreadedSemaphore;
711
use Laudis\Neo4j\Contracts\ClientInterface;
812
use Laudis\Neo4j\Contracts\DriverInterface;
13+
use Laudis\Neo4j\Databags\ConnectionRequestData;
14+
use Laudis\Neo4j\Databags\SslConfiguration;
15+
use Laudis\Neo4j\Enum\SslMode;
16+
use Laudis\Neo4j\Neo4j\Neo4jConnectionPool;
917
use Laudis\Neo4j\Neo4j\Neo4jDriver;
1018
use Neo4j\Neo4jBundle\Tests\App\TestKernel;
1119
use Psr\Http\Message\UriInterface;
@@ -67,12 +75,10 @@ public function testDefaultDsn(): void
6775
* @var Neo4jDriver $driver
6876
*/
6977
$driver = $client->getDriver('default');
70-
$reflection = new \ReflectionClass($driver);
71-
$property = $reflection->getProperty('parsedUrl');
7278
/**
7379
* @var UriInterface $uri
7480
*/
75-
$uri = $property->getValue($driver);
81+
$uri = $this->getPrivateProperty($driver, 'parsedUrl');
7682

7783
$this->assertSame($uri->getScheme(), 'neo4j');
7884
}
@@ -93,4 +99,88 @@ public function testDsn(): void
9399
$client = $container->get('neo4j.client');
94100
$client->getDriver('neo4j_undefined_configs');
95101
}
102+
103+
public function testDefaultDriverConfig(): void
104+
{
105+
static::bootKernel();
106+
$container = static::getContainer();
107+
108+
/**
109+
* @var ClientInterface $client
110+
*/
111+
$client = $container->get('neo4j.client');
112+
/** @var Neo4jDriver $driver */
113+
$driver = $client->getDriver('default');
114+
/** @var Neo4jConnectionPool $pool */
115+
$pool = $this->getPrivateProperty($driver, 'pool');
116+
/** @var SingleThreadedSemaphore $semaphore */
117+
$semaphore = $this->getPrivateProperty($pool, 'semaphore');
118+
/** @var int $max */
119+
$max = $this->getPrivateProperty($semaphore, 'max');
120+
121+
// default_driver_config.pool_size
122+
$this->assertSame($max, 256);
123+
124+
/** @var ConnectionRequestData $data */
125+
$data = $this->getPrivateProperty($pool, 'data');
126+
127+
$this->assertSame($data->getUserAgent(), 'Neo4j Symfony Bundle/testing');
128+
129+
/** @var SslConfiguration $sslConfig */
130+
$sslConfig = $this->getPrivateProperty($data, 'config');
131+
/** @var SslMode $sslMode */
132+
$sslMode = $this->getPrivateProperty($sslConfig, 'mode');
133+
/** @var bool $verifyPeer */
134+
$verifyPeer = $this->getPrivateProperty($sslConfig, 'verifyPeer');
135+
136+
$this->assertSame($sslMode, SslMode::DISABLE());
137+
$this->assertFalse($verifyPeer);
138+
}
139+
140+
public function testDefaultSessionConfig(): void
141+
{
142+
static::bootKernel();
143+
$container = static::getContainer();
144+
145+
/**
146+
* @var ClientInterface $client
147+
*/
148+
$client = $container->get('neo4j.client');
149+
/** @var Client $innerClient */
150+
$innerClient = $this->getPrivateProperty($client, 'client');
151+
$sessionConfig = $innerClient->getDefaultSessionConfiguration();
152+
153+
$this->assertSame($sessionConfig->getFetchSize(), 999);
154+
}
155+
156+
public function testDefaultTrasactionConfig(): void
157+
{
158+
static::bootKernel();
159+
$container = static::getContainer();
160+
161+
/**
162+
* @var ClientInterface $client
163+
*/
164+
$client = $container->get('neo4j.client');
165+
/** @var Client $innerClient */
166+
$innerClient = $this->getPrivateProperty($client, 'client');
167+
$transactionConfig = $innerClient->getDefaultTransactionConfiguration();
168+
169+
$this->assertSame($transactionConfig->getTimeout(), 40.0);
170+
}
171+
172+
/**
173+
* @template T
174+
*
175+
* @return T
176+
*
177+
* @noinspection PhpDocMissingThrowsInspection
178+
*/
179+
private function getPrivateProperty(object $object, string $property): mixed
180+
{
181+
$reflection = new \ReflectionClass($object);
182+
$property = $reflection->getProperty($property);
183+
184+
return $property->getValue($object);
185+
}
96186
}

0 commit comments

Comments
 (0)