Skip to content

Commit 939d106

Browse files
committed
Changed the code for point test cases
1 parent 6d0fbd3 commit 939d106

File tree

8 files changed

+39
-157
lines changed

8 files changed

+39
-157
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

phpunit.dist.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
<log type="testdox" target="php://stdout" />
1414
</logging>
1515
-->
16-
<php>
17-
<env name="NEO4J_ADDRESS" value="$_ENV['NEO4J_ADDRESS']" />
18-
<env name="NEO4J_USERNAME" value="$_ENV['NEO4J_USERNAME']" />
19-
<env name="NEO4J_PASSWORD" value="$_ENV['NEO4J_PASSWORD']" />
20-
</php>
16+
2117
<!-- No need to set sensitive information here -->
2218
</phpunit>

src/OGM.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function map(array $object): mixed
2929
};
3030
}
3131

32-
private function parseWKT(string $wkt): Point
32+
public static function parseWKT(string $wkt): Point
3333
{
3434
$sridPart = substr($wkt, 0, strpos($wkt, ';'));
3535
$srid = (int)str_replace('SRID=', '', $sridPart);
@@ -41,28 +41,16 @@ private function parseWKT(string $wkt): Point
4141
$pointPart = trim($pointPart, ' ()');
4242
$coordinates = explode(' ', $pointPart);
4343

44-
if (count($coordinates) == 2) {
45-
list($longitude, $latitude) = $coordinates;
46-
$x = (float)$longitude;
47-
$y = (float)$latitude;
48-
$z = 0.0;
49-
} elseif (count($coordinates) == 3) {
50-
list($longitude, $latitude, $height) = $coordinates;
51-
$x = (float)$longitude;
52-
$y = (float)$latitude;
53-
$z = (float)$height;
44+
if (count($coordinates) === 2) {
45+
[$x, $y] = $coordinates;
46+
$z = null;
47+
} elseif (count($coordinates) === 3) {
48+
[$x, $y, $z] = $coordinates;
5449
} else {
55-
throw new InvalidArgumentException("Invalid WKT format: unable to parse coordinates.");
50+
throw new \InvalidArgumentException("Invalid WKT format: unable to parse coordinates.");
5651
}
57-
return new Point(
58-
$longitude,
59-
$latitude,
60-
$z,
61-
$x,
62-
$y,
63-
$z,
64-
$srid
65-
);
52+
53+
return new Point((float)$x, (float)$y, $z !== null ? (float)$z : null, $srid);
6654
}
6755

6856

src/Objects/Point.php

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,54 @@
33
namespace Neo4j\QueryAPI\Objects;
44

55
/**
6-
* Represents a geographical point with longitude, latitude, and SRID (Spatial Reference System Identifier).
6+
* Represents a point with x, y, z coordinates, and SRID (Spatial Reference System Identifier).
77
*/
88
class Point
99
{
1010
/**
11-
* @param float $longitude The longitude of the point.
12-
* @param float $latitude The latitude of the point.
11+
* @param float $x The x coordinate of the point.
12+
* @param float $y The y coordinate of the point.
13+
* @param float|null $z The z coordinate of the point, or null if not applicable.
1314
* @param int $srid The Spatial Reference System Identifier (SRID).
1415
*/
1516
public function __construct(
16-
public float $longitude,
17-
public float $latitude,
18-
public float $height,
1917
public float $x,
2018
public float $y,
21-
public float $z,
22-
public int $srid,
19+
public float|null $z,
20+
public int $srid,
2321
) {
2422
}
2523

2624
/**
27-
* Get the longitude of the point.
25+
* Get the x coordinate of the point.
2826
*
29-
* @return float Longitude value.
30-
*/
31-
public function getLongitude(): float
32-
{
33-
return $this->longitude;
34-
}
35-
36-
/**
37-
* Get the latitude of the point.
38-
*
39-
* @return float Latitude value.
40-
*/
41-
public function getLatitude(): float
42-
{
43-
return $this->latitude;
44-
}
45-
public function getHeight(): float
46-
{
47-
return $this->height;
48-
}
49-
/**
50-
* Get the x of the point.
51-
*
52-
* @return float x value.
27+
* @return float x coordinate value.
5328
*/
5429
public function getX(): float
5530
{
5631
return $this->x;
5732
}
33+
5834
/**
59-
* Get the y of the point.
35+
* Get the y coordinate of the point.
6036
*
61-
* @return float y value.
37+
* @return float y coordinate value.
6238
*/
6339
public function getY(): float
6440
{
6541
return $this->y;
6642
}
6743

6844
/**
69-
* Get the z of the point.
45+
* Get the z coordinate of the point.
7046
*
71-
* @return float z value.
47+
* @return float|null z coordinate value, or null if not applicable.
7248
*/
73-
public function getZ(): float
49+
public function getZ(): float|null
7450
{
7551
return $this->z;
7652
}
7753

78-
7954
/**
8055
* Get the SRID (Spatial Reference System Identifier) of the point.
8156
*
@@ -89,10 +64,11 @@ public function getSrid(): int
8964
/**
9065
* Convert the Point object to a string representation.
9166
*
92-
* @return string String representation in the format: "SRID=<srid>;POINT (<longitude> <latitude>)".
67+
* @return string String representation in the format: "SRID=<srid>;POINT (<x> <y> <z>)".
9368
*/
9469
public function __toString(): string
9570
{
96-
return "SRID={$this->srid};POINT ({$this->longitude} {$this->latitude} {$this->x} {$this->y})";
71+
$zValue = $this->z !== null ? " {$this->z}" : "";
72+
return "SRID={$this->srid};POINT ({$this->x} {$this->y}{$zValue})";
9773
}
9874
}

src/Objects/Point_3D.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/Integration/Neo4jOGMTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ public function testWithWGS84_2DPoint(): void
8484
]);
8585

8686
$this->assertInstanceOf(Point::class, $point);
87-
$this->assertEquals(1.2, $point->getLongitude());
88-
$this->assertEquals(3.4, $point->getLatitude());
87+
$this->assertEquals(1.2, $point->getX()); // x is longitude
88+
$this->assertEquals(3.4, $point->getY()); // y is latitude
89+
$this->assertNull($point->getZ()); // Ensure z is null for 2D point
8990
$this->assertEquals(4326, $point->getSrid());
9091
}
9192

93+
9294
public function testWithWGS84_3DPoint(): void
9395
{
9496
// Simulate mapping the raw WKT data into the Point object
@@ -98,9 +100,9 @@ public function testWithWGS84_3DPoint(): void
98100
]);
99101

100102
$this->assertInstanceOf(Point::class, $point);
101-
$this->assertEquals(12.34, $point->getLongitude());
102-
$this->assertEquals(56.78, $point->getLatitude());
103-
$this->assertEquals(100.5, $point->getHeight());
103+
$this->assertEquals(12.34, $point->getX());
104+
$this->assertEquals(56.78, $point->getY());
105+
$this->assertEquals(100.5, $point->getZ());
104106
$this->assertEquals(4979, $point->getSrid());
105107
}
106108

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function createSubset(array $expected, array $actual): array
8282

8383
public static function queryProvider(): array
8484
{
85-
$decodedBinary = base64_decode('U29tZSByYW5kb20gYmluYXJ5IGRhdGE=');
85+
8686
return [
8787
'testWithExactNames' => [
8888
'MATCH (n:Person) WHERE n.name IN $names RETURN n.name',

tests/Unit/Neo4jQueryAPIUnitTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ protected function setUp(): void
2020
{
2121
parent::setUp();
2222

23-
// Use environment variables from phpunit.xml
2423
$this->address = getenv('NEO4J_ADDRESS');
2524
$this->username = getenv('NEO4J_USERNAME');
2625
$this->password = getenv('NEO4J_PASSWORD');
@@ -32,26 +31,24 @@ public function testCorrectClientSetup(): void
3231

3332
$this->assertInstanceOf(Neo4jQueryAPI::class, $neo4jQueryAPI);
3433

35-
// Use Reflection to get the client property
3634
$clientReflection = new \ReflectionClass(Neo4jQueryAPI::class);
3735
$clientProperty = $clientReflection->getProperty('client');
38-
// Make private property accessible
3936
$client = $clientProperty->getValue($neo4jQueryAPI);
4037

4138
$this->assertInstanceOf(Client::class, $client);
4239

4340
$config = $client->getConfig();
4441
$this->assertEquals(rtrim($this->address, '/'), $config['base_uri']);
4542
$this->assertEquals('Basic ' . base64_encode("{$this->username}:{$this->password}"), $config['headers']['Authorization']);
46-
$this->assertEquals('application/json', $config['headers']['Content-Type']);
43+
$this->assertEquals('application/vnd.neo4j.query', $config['headers']['Content-Type']);
4744
}
4845

4946
/**
5047
* @throws GuzzleException
5148
*/
5249
public function testRunSuccess(): void
5350
{
54-
// Mock a successful response from Neo4j server
51+
5552
$mock = new MockHandler([
5653
new Response(200, ['X-Foo' => 'Bar'], '{"hello":"world"}'),
5754
]);
@@ -61,16 +58,12 @@ public function testRunSuccess(): void
6158

6259
$neo4jQueryAPI = new Neo4jQueryAPI($client);
6360

64-
// Use a sample Cypher query to run on the Neo4j server
6561
$cypherQuery = 'MATCH (n:Person) RETURN n LIMIT 5';
6662

67-
// Execute the query and capture the result
63+
6864
$result = $neo4jQueryAPI->run($cypherQuery, []);
6965

70-
// Output for debugging
71-
print_r($result);
7266

73-
// Verify the response matches the expected output
7467
$this->assertEquals(['hello' => 'world'], $result);
7568
}
7669
}

0 commit comments

Comments
 (0)