Skip to content

Commit efd1dff

Browse files
committed
Greenbarred tests
1 parent e9de7bb commit efd1dff

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

src/Formatter/OGMFormatter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,18 @@ private function buildResult(array $result): CypherList
130130
$relationship = $data['graph']['relationships'];
131131
$metaIndex = 0;
132132
$relationshipIndex = 0;
133+
$nodeIndex = 0;
133134

134135
/** @var array<string, OGMTypes> $record */
135136
$record = [];
136137
foreach ($data['row'] as $i => $value) {
137138
if (is_array($value)) {
138-
$translation = $this->arrayTranslator->translate($meta, $relationship, $metaIndex, $relationshipIndex, $nodes, $value);
139+
$translation = $this->arrayTranslator->translate($meta, $relationship, $metaIndex, $relationshipIndex, $nodeIndex, $nodes, $value);
139140

140141
$relationshipIndex += $translation[1];
141142
$metaIndex += $translation[0];
142-
$record[$columns[$i]] = $translation[2];
143+
$nodeIndex += $translation[2];
144+
$record[$columns[$i]] = $translation[3];
143145
} elseif (is_string($value)) {
144146
[$metaIncrement, $translation] = $this->stringTranslator->translate($metaIndex, $meta, $value);
145147
$metaIndex += $metaIncrement;

src/Formatter/Specialised/HttpOGMArrayTranslator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ private function translateCypherList(array $value): CypherList
9999
* @param MetaArray $meta
100100
* @param list<NodeArray> $nodes
101101
*
102-
* @return array{0: int, 1: int, 2:Cartesian3DPoint|CartesianPoint|CypherList|CypherMap|Node|Relationship|WGS843DPoint|WGS84Point|Path}
102+
* @return array{0: int, 1: int, 2: int, 3:Cartesian3DPoint|CartesianPoint|CypherList|CypherMap|Node|Relationship|WGS843DPoint|WGS84Point|Path}
103103
*/
104-
public function translate(array $meta, array $relationships, int $metaIndex, int $relationshipIndex, array $nodes, array $value): array
104+
public function translate(array $meta, array $relationships, int $metaIndex, int $relationshipIndex, int $nodeIndex, array $nodes, array $value): array
105105
{
106106
$currentMeta = $meta[$metaIndex];
107107
$metaIncrease = 1;
@@ -127,18 +127,20 @@ public function translate(array $meta, array $relationships, int $metaIndex, int
127127
$tbr = $this->translatePoint($value);
128128
break;
129129
default:
130-
if ($type === 'node' && isset($currentMeta['id'])) {
130+
if ($type === 'node' && isset($currentMeta['id']) && $value === $nodes[$nodeIndex]['properties']) {
131131
/** @var int $id */
132132
$id = $currentMeta['id'];
133-
$tbr = $this->translateNode($nodes, $id);
133+
$node = $nodes[$nodeIndex];
134+
++$nodeIndex;
135+
$tbr = new Node($id, new CypherList($node['labels']), $this->translateCypherMap($node['properties']));
134136
} else {
135137
/** @var array<array-key, array|scalar|null> $value */
136138
$tbr = $this->translateContainer($value);
137139
}
138140
break;
139141
}
140142

141-
return [$metaIncrease, $relationshipIncrease, $tbr];
143+
return [$metaIncrease, $relationshipIncrease, $nodeIndex, $tbr];
142144
}
143145

144146
/**

tests/Fixtures/MoviesFixture.php

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

33
/*
4-
* This file is part of the Laudis Neo4j package.
5-
*
6-
* (c) Laudis technologies <http://laudis.tech>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
4+
* This file is part of the Laudis Neo4j package.
5+
*
6+
* (c) Laudis technologies <http://laudis.tech>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
1111

1212
namespace Laudis\Neo4j\Tests\Fixtures;
1313

tests/Integration/DriverParityTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313

1414
namespace Laudis\Neo4j\Tests\Integration;
1515

16+
use Laudis\Neo4j\Contracts\ClientInterface;
1617
use Laudis\Neo4j\Contracts\FormatterInterface;
1718
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
1819
use Laudis\Neo4j\Tests\Fixtures\MoviesFixture;
1920
use Laudis\Neo4j\Types\CypherMap;
2021

21-
class DriverParityTest extends SelectableDriverIntegrationTestCase
22+
/**
23+
* @psalm-suppress all
24+
*/
25+
final class DriverParityTest extends SelectableDriverIntegrationTestCase
2226
{
2327
private const TESTABLE_SCHEMES = ['bolt', 'http'];
2428

@@ -38,11 +42,10 @@ protected static function formatter(): FormatterInterface
3842

3943
public function testCanHandleMapLiterals(): void
4044
{
41-
$this->runParityTest(function($client) {
42-
45+
$this->runParityTest(function (ClientInterface $client) {
4346
$results = $client->run('MATCH (n:Person)-[r:ACTED_IN]->(m) RETURN n, {movie: m, roles: r.roles} AS actInfo LIMIT 5');
44-
45-
foreach($results as $result) {
47+
48+
foreach ($results as $result) {
4649
$actorInfo = $result->get('actInfo');
4750

4851
$this->assertInstanceOf(CypherMap::class, $actorInfo);
@@ -54,12 +57,11 @@ public function testCanHandleMapLiterals(): void
5457

5558
private function runParityTest(callable $test): void
5659
{
57-
foreach(self::TESTABLE_SCHEMES as $scheme) {
60+
foreach (self::TESTABLE_SCHEMES as $scheme) {
5861
$client = $this->getClientForScheme($scheme);
59-
echo "Testing ".$scheme.' for '.$this->getName().PHP_EOL;
62+
echo 'Testing '.$scheme.' for '.$this->getName().PHP_EOL;
6063
$test($client);
6164
echo $scheme.' passed'.PHP_EOL;
62-
6365
}
6466
}
6567
}

tests/Integration/SelectableDriverIntegrationTestCase.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
namespace Laudis\Neo4j\Tests\Integration;
1515

16+
use function array_values;
1617
use Exception;
1718
use Laudis\Neo4j\ClientBuilder;
1819
use Laudis\Neo4j\Common\Uri;
1920
use Laudis\Neo4j\Contracts\ClientInterface;
2021
use Laudis\Neo4j\Contracts\FormatterInterface;
22+
use function sprintf;
2123

2224
abstract class SelectableDriverIntegrationTestCase extends EnvironmentAwareIntegrationTest
2325
{
24-
/** @var array<string,ClientInterface> */
26+
/** @var array<string, ClientInterface> */
2527
protected static array $drivers = [];
2628

2729
abstract protected static function formatter(): FormatterInterface;
@@ -34,26 +36,26 @@ public static function setUpBeforeClass(): void
3436

3537
protected static function createClient(): ClientInterface
3638
{
37-
$connections = self::buildConnections();
38-
39-
foreach ($connections as $i => $connection) {
39+
foreach (self::buildConnections() as $i => $connection) {
4040
$builder = ClientBuilder::create();
4141
$uri = Uri::create($connection);
4242
$alias = $uri->getScheme().'_'.$i;
4343
$builder = $builder->withDriver($alias, $connection);
44-
$client = $builder->withFormatter(static::formatter())->build();
45-
self::$drivers[$alias] = $client;
44+
45+
self::$drivers[$alias] = $builder->withFormatter(static::formatter())->build();
4646
}
4747

48-
return \array_values(self::$drivers)[0];
48+
/** @psalm-suppress PossiblyUndefinedIntArrayOffset */
49+
return array_values(self::$drivers)[0];
4950
}
5051

5152
protected function getClientForScheme(string $scheme): ClientInterface
5253
{
53-
$firstAliasForScheme = current(array_filter(array_keys(self::$drivers), fn($alias) => str_starts_with($alias, $scheme)));
54+
$firstAliasForScheme = current(array_filter(array_keys(self::$drivers), fn ($alias) => str_starts_with($alias, $scheme)));
5455
if (false === $firstAliasForScheme) {
55-
throw new Exception(\sprintf("No client for scheme %s found", $scheme));
56+
throw new Exception(sprintf('No client for scheme %s found', $scheme));
5657
}
58+
5759
return self::$drivers[$firstAliasForScheme];
5860
}
5961
}

0 commit comments

Comments
 (0)