|
8 | 8 | use Neo4j\QueryAPI\Objects\Point;
|
9 | 9 | use Neo4j\QueryAPI\Objects\Relationship;
|
10 | 10 | use Neo4j\QueryAPI\OGM;
|
| 11 | +use PHPUnit\Framework\Attributes\DataProvider; |
11 | 12 | use PHPUnit\Framework\TestCase;
|
12 | 13 |
|
13 | 14 | class Neo4jOGMTest extends TestCase
|
14 | 15 | {
|
15 | 16 | private OGM $ogm;
|
16 | 17 |
|
| 18 | + public static function integerDataProvider(): array |
| 19 | + { |
| 20 | + return [ |
| 21 | + 'Test with age 30' => [ |
| 22 | + 'CREATE (n:Person {age: $age}) RETURN n.age', |
| 23 | + ['age' => 30], |
| 24 | + 30, // Expected result should be just the integer, not an array |
| 25 | + ], |
| 26 | + 'Test with age 40' => [ |
| 27 | + 'CREATE (n:Person {age: $age}) RETURN n.age', |
| 28 | + ['age' => 40], |
| 29 | + 40, // Expected result should be just the integer |
| 30 | + ], |
| 31 | + |
| 32 | + ]; |
| 33 | + } |
| 34 | + |
| 35 | + public static function floatDataProvider(): array |
| 36 | + { |
| 37 | + return [ |
| 38 | + 'Test with height 1.75' => [ |
| 39 | + 'CREATE (n:Person {height: $height}) RETURN n.height', |
| 40 | + ['height' => 1.75], |
| 41 | + 1.75, // Expecting a float value directly, not wrapped in an array |
| 42 | + ], |
| 43 | + |
| 44 | + ]; |
| 45 | + } |
| 46 | + |
| 47 | + public static function nullDataProvider() |
| 48 | + { |
| 49 | + return |
| 50 | + [ |
| 51 | + |
| 52 | + 'testWithNull' => [ |
| 53 | + 'CREATE (n:Person {middleName: $middleName}) RETURN n.middleName', |
| 54 | + ['middleName' => null], |
| 55 | + null, |
| 56 | + ], |
| 57 | + ]; |
| 58 | + } |
| 59 | + |
| 60 | + public static function booleanDataProvider():array |
| 61 | + { |
| 62 | + return [ |
| 63 | + ['query1', ['_value' => true], true], |
| 64 | + ['query2', ['_value' => false], false], |
| 65 | + ['query3', ['_value' => null], null], // Optional if you want to test null as well. |
| 66 | + ]; |
| 67 | + } |
| 68 | + |
| 69 | + |
17 | 70 | public function setUp(): void
|
18 | 71 | {
|
19 | 72 | $this->ogm = new OGM();
|
@@ -136,20 +189,43 @@ public function testWithCartesian3DPoint(): void
|
136 | 189 |
|
137 | 190 | public function testArray(): void
|
138 | 191 | {
|
139 |
| - $arrayData = ['bob1', 'alicy']; |
140 |
| - |
141 |
| - $this->assertEquals($arrayData, $this->ogm->map([ |
| 192 | + $input = [ |
142 | 193 | '$type' => 'Array',
|
143 |
| - '_value' => $arrayData, |
144 |
| - ])); |
| 194 | + '_value' => [ |
| 195 | + [ |
| 196 | + [ |
| 197 | + '$type' => 'String', |
| 198 | + '_value' => 'bob1', |
| 199 | + ], |
| 200 | + [ |
| 201 | + '$type' => 'String', |
| 202 | + '_value' => 'alicy', |
| 203 | + ], |
| 204 | + ], |
| 205 | + ], |
| 206 | + ]; |
| 207 | + |
| 208 | + $expectedOutput = [ |
| 209 | + 0 => [ |
| 210 | + [ |
| 211 | + '$type' => 'String', |
| 212 | + '_value' => 'bob1', |
| 213 | + ], |
| 214 | + [ |
| 215 | + '$type' => 'String', |
| 216 | + '_value' => 'alicy', |
| 217 | + ], |
| 218 | + ], |
| 219 | + ]; |
| 220 | + |
| 221 | + $this->assertEquals($expectedOutput, $this->ogm->map($input)); |
145 | 222 | }
|
146 | 223 |
|
| 224 | + |
| 225 | + |
147 | 226 | public function testMap(): void
|
148 | 227 | {
|
149 |
| - $mapData = ['hello' => |
150 |
| - [ '$type' => 'String', |
151 |
| - '_value' => 'hello',] |
152 |
| - ]; |
| 228 | + $mapData = ['hello' => 'hello']; |
153 | 229 | $this->assertEquals(
|
154 | 230 | $mapData,
|
155 | 231 | $this->ogm->map([
|
@@ -302,5 +378,48 @@ public function testWithPath()
|
302 | 378 | $this->assertEquals('B', $path->getNodes()[1]->getProperties()['name']['_value']);
|
303 | 379 | }
|
304 | 380 |
|
| 381 | + #[DataProvider('integerDataProvider')] public function testWithInteger(string $query, array $parameters, int $expectedResult): void |
| 382 | + { |
| 383 | + $actual = $this->ogm->map([ |
| 384 | + '$type' => 'Integer', |
| 385 | + '_value' => $parameters['age'], |
| 386 | + ]); |
| 387 | + |
| 388 | + $this->assertEquals($expectedResult, $actual); |
| 389 | + } |
| 390 | + |
| 391 | + #[DataProvider('floatDataProvider')] |
| 392 | + public function testWithFloat(string $query, array $parameters, float $expectedResult): void |
| 393 | + { |
| 394 | + $actual = $this->ogm->map([ |
| 395 | + '$type' => 'float', |
| 396 | + '_value' => $parameters['height'], |
| 397 | + ]); |
| 398 | + |
| 399 | + $this->assertEquals($expectedResult, $actual); |
| 400 | + } |
| 401 | + |
| 402 | + |
| 403 | + #[DataProvider('nullDataProvider')] |
| 404 | + public function testWithNull(string $query, array $parameters, ?string $expectedResult): void |
| 405 | + { |
| 406 | + $actual = $this->ogm->map([ |
| 407 | + '$type' => 'Null', |
| 408 | + '_value' => null, |
| 409 | + ]); |
| 410 | + $this->assertEquals($expectedResult, $actual); |
| 411 | + } |
| 412 | + |
| 413 | + #[DataProvider('booleanDataProvider')] |
| 414 | + public function testWithBoolean(string $query, array $parameters, ?bool $expectedResult): void |
| 415 | + { |
| 416 | + $actual = $this->ogm->map([ |
| 417 | + '$type' => 'Boolean', |
| 418 | + '_value' => $parameters['_value'], |
| 419 | + ]); |
| 420 | + $this->assertEquals($expectedResult, $actual); |
| 421 | + } |
| 422 | + |
| 423 | + |
305 | 424 |
|
306 | 425 | }
|
0 commit comments