|
13 | 13 |
|
14 | 14 | namespace Laudis\Neo4j\Tests\Integration;
|
15 | 15 |
|
| 16 | +use Laudis\Neo4j\Bolt\BoltConnectionPool; |
| 17 | +use Laudis\Neo4j\Bolt\BoltDriver; |
16 | 18 | use Laudis\Neo4j\Contracts\FormatterInterface;
|
17 | 19 | use Laudis\Neo4j\Databags\Statement;
|
18 | 20 | use Laudis\Neo4j\Exception\InvalidTransactionStateException;
|
19 | 21 | use Laudis\Neo4j\Exception\Neo4jException;
|
20 | 22 | use Laudis\Neo4j\Formatter\BasicFormatter;
|
| 23 | +use ReflectionClass; |
| 24 | +use function str_starts_with; |
21 | 25 |
|
22 | 26 | /**
|
23 | 27 | * @psalm-import-type BasicResults from \Laudis\Neo4j\Formatter\BasicFormatter
|
@@ -298,4 +302,38 @@ public function testRollbackInvalid(string $alias): void
|
298 | 302 | }
|
299 | 303 | self::assertTrue($exception);
|
300 | 304 | }
|
| 305 | + |
| 306 | + /** |
| 307 | + * @dataProvider connectionAliases |
| 308 | + * @noinspection PhpUnusedLocalVariableInspection |
| 309 | + * @psalm-suppress UnusedVariable |
| 310 | + */ |
| 311 | + public function testCorrectConnectionReuse(string $alias): void |
| 312 | + { |
| 313 | + $driver = $this->getClient()->getDriver($alias); |
| 314 | + if (!$driver instanceof BoltDriver) { |
| 315 | + self::markTestSkipped('Can only white box test bolt driver'); |
| 316 | + } |
| 317 | + |
| 318 | + $poolReflection = new ReflectionClass(BoltConnectionPool::class); |
| 319 | + $poolReflection->setStaticPropertyValue('connectionCache', []); |
| 320 | + |
| 321 | + $this->getClient()->run('MATCH (x) RETURN x', [], $alias); |
| 322 | + $this->getClient()->run('MATCH (x) RETURN x', [], $alias); |
| 323 | + $this->getClient()->run('MATCH (x) RETURN x', [], $alias); |
| 324 | + $this->getClient()->run('MATCH (x) RETURN x', [], $alias); |
| 325 | + $a = $this->getClient()->beginTransaction([], $alias); |
| 326 | + $b = $this->getClient()->beginTransaction([], $alias); |
| 327 | + $this->getClient()->run('MATCH (x) RETURN x', [], $alias); |
| 328 | + |
| 329 | + $poolReflection = new ReflectionClass(BoltConnectionPool::class); |
| 330 | + /** @var array $cache */ |
| 331 | + $cache = $poolReflection->getStaticPropertyValue('connectionCache'); |
| 332 | + |
| 333 | + $key = array_key_first($cache); |
| 334 | + self::assertIsString($key); |
| 335 | + self::assertArrayHasKey($key, $cache); |
| 336 | + /** @psalm-suppress MixedArgument */ |
| 337 | + self::assertCount(3, $cache[$key]); |
| 338 | + } |
301 | 339 | }
|
0 commit comments