Skip to content

Commit 147b17a

Browse files
PratikshaPratiksha
authored andcommitted
DEBUG
1 parent ca125bf commit 147b17a

10 files changed

+45
-415
lines changed

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Neo4j\QueryAPI\Objects\Bookmarks;
77
use Neo4j\QueryAPI\Enums\AccessMode;
88

9-
class Configuration
9+
final class Configuration
1010
{
1111
/**
1212
* Constructor for Configuration class.

src/OGM.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function map(array $data): mixed
3939

4040
private function parsePoint(string $value): Point
4141
{
42-
// Match SRID and coordinate values
4342
if (preg_match('/SRID=(\d+);POINT(?: Z)? \(([-\d.]+) ([-\d.]+)(?: ([-\d.]+))?\)/', $value, $matches)) {
4443
$srid = (int) $matches[1];
4544
$x = (float) $matches[2];
@@ -57,14 +56,14 @@ private function mapNode(array $nodeData): Node
5756
{
5857
return new Node(
5958
labels: $nodeData['_labels'] ?? [],
60-
properties: $this->mapProperties($nodeData['_properties'] ?? []) // ✅ Fix: Ensure properties exist
59+
properties: $this->mapProperties($nodeData['_properties'] ?? [])
6160
);
6261
}
6362

6463
private function mapRelationship(array $relationshipData): Relationship
6564
{
6665
return new Relationship(
67-
type: $relationshipData['_type'] ?? 'UNKNOWN', // ✅ Fix: Default to 'UNKNOWN'
66+
type: $relationshipData['_type'] ?? 'UNKNOWN',
6867
properties: $this->mapProperties($relationshipData['_properties'] ?? [])
6968
);
7069
}

src/ResponseParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
1515
use Neo4j\QueryAPI\Objects\Point;
1616

17-
class ResponseParser
17+
final class ResponseParser
1818
{
1919
public function __construct(private readonly OGM $ogm)
2020
{

src/Transaction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function run(string $query, array $parameters): ResultSet
3535
{
3636
$request = $this->requestFactory->buildTransactionRunRequest($query, $parameters, $this->transactionId, $this->clusterAffinity);
3737

38-
$response = null; // ✅ Ensures response is always defined
38+
$response = null;
3939

4040
try {
4141
$response = $this->client->sendRequest($request);
@@ -75,7 +75,6 @@ public function rollback(): void
7575
*/
7676
private function handleRequestException(RequestExceptionInterface $e): void
7777
{
78-
// ✅ Corrected: Check if exception has a response
7978
$response = method_exists($e, 'getResponse') ? $e->getResponse() : null;
8079

8180
if ($response instanceof ResponseInterface) {

tests/Integration/Neo4jOGMTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ protected function setUp(): void
2323

2424
public function testWithNode(): void
2525
{
26-
// Ensure the property $ogm is referenced
2726
$nodeData = [
2827
'$type' => 'Node',
2928
'_value' => [
@@ -36,10 +35,9 @@ public function testWithNode(): void
3635
$this->assertEquals('Ayush', $node->getProperties()['name']['_value']);
3736
}
3837

39-
// Example of using $ogm in another test
4038
public function testWithSimpleRelationship(): void
4139
{
42-
// Mapping the Relationship
40+
4341
$relationshipData = [
4442
'$type' => 'Relationship',
4543
'_value' => [
@@ -52,7 +50,6 @@ public function testWithSimpleRelationship(): void
5250
$this->assertEquals('FRIENDS', $relationship->getType());
5351
}
5452

55-
// More tests...
5653
public function testWithPath(): void
5754
{
5855
$pathData = [
@@ -63,7 +60,7 @@ public function testWithPath(): void
6360
'_value' => [
6461
'_labels' => ['Person'],
6562
'_properties' => [
66-
'name' => ['_value' => 'A'], // ✅ Now correctly wrapped
63+
'name' => ['_value' => 'A'],
6764
],
6865
],
6966
],
@@ -79,7 +76,7 @@ public function testWithPath(): void
7976
'_value' => [
8077
'_labels' => ['Person'],
8178
'_properties' => [
82-
'name' => ['_value' => 'B'], // ✅ Now correctly wrapped
79+
'name' => ['_value' => 'B'],
8380
],
8481
],
8582
],
@@ -88,7 +85,6 @@ public function testWithPath(): void
8885

8986
$path = $this->ogm->map($pathData);
9087

91-
// Assertions
9288
$this->assertCount(2, $path->getNodes());
9389
$this->assertCount(1, $path->getRelationships());
9490
$this->assertEquals('A', $path->getNodes()[0]->getProperties()['name']['_value']);

tests/Unit/srcfiles/Neo4jQueryAPI_UnitTest.php renamed to tests/Unit/Neo4jQueryAPINewUnitTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
22

3-
namespace Neo4j\QueryAPI\Tests\Unit\srcfiles;
3+
namespace Neo4j\QueryAPI\Tests\Unit;
44

5+
use Neo4j\QueryAPI\Configuration;
56
use Neo4j\QueryAPI\Exception\Neo4jException;
67
use Neo4j\QueryAPI\Neo4jQueryAPI;
7-
use Neo4j\QueryAPI\Configuration;
8-
use Neo4j\QueryAPI\ResponseParser;
98
use Neo4j\QueryAPI\Neo4jRequestFactory;
9+
use Neo4j\QueryAPI\ResponseParser;
1010
use Neo4j\QueryAPI\Results\ResultSet;
11-
use Neo4j\QueryAPI\Authentication\AuthenticateInterface;
1211
use PHPUnit\Framework\TestCase;
1312
use Psr\Http\Client\ClientInterface;
13+
use Psr\Http\Client\RequestExceptionInterface;
1414
use Psr\Http\Message\RequestInterface;
1515
use Psr\Http\Message\ResponseInterface;
16-
use Psr\Http\Client\RequestExceptionInterface;
1716

18-
final class Neo4jQueryAPI_UnitTest extends TestCase
17+
final class Neo4jQueryAPINewUnitTest extends TestCase
1918
{
2019
private Neo4jQueryAPI $api;
2120
private ClientInterface $clientMock;
@@ -72,7 +71,6 @@ public function testRunExecutesQueryAndReturnsResultSet(): void
7271

7372
$result = $this->api->run($cypher, $parameters);
7473

75-
// Ensure the returned result is the expected ResultSet
7674
$this->assertSame($mockResultSet, $result);
7775
}
7876

@@ -84,7 +82,7 @@ public function testHandleRequestExceptionThrowsNeo4jException(): void
8482
$this->invokeMethod($this->api, 'handleRequestException', [$mockException]);
8583
}
8684

87-
private function invokeMethod($object, string $methodName, array $parameters = [])
85+
private function invokeMethod($object, string $methodName, array $parameters = []):array
8886
{
8987
$reflection = new \ReflectionClass(get_class($object));
9088
$method = $reflection->getMethod($methodName);

tests/Unit/srcfiles/OGMUnitTest.php renamed to tests/Unit/OGMUnitTest.php

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

3-
namespace Neo4j\QueryAPI\Tests\Unit\srcfiles;
3+
namespace Neo4j\QueryAPI\Tests\Unit;
44

5-
use Neo4j\QueryAPI\OGM;
5+
use InvalidArgumentException;
66
use Neo4j\QueryAPI\Objects\Node;
7-
use Neo4j\QueryAPI\Objects\Relationship;
87
use Neo4j\QueryAPI\Objects\Point;
8+
use Neo4j\QueryAPI\Objects\Relationship;
9+
use Neo4j\QueryAPI\OGM;
910
use PHPUnit\Framework\TestCase;
10-
use InvalidArgumentException;
1111

1212
/**
1313
* @api
@@ -28,37 +28,37 @@ public function testMapInteger(): void
2828
$this->assertSame(42, $this->ogm->map($data));
2929
}
3030

31-
public function testMapFloat()
31+
public function testMapFloat():void
3232
{
3333
$data = ['$type' => 'Float', '_value' => 3.14];
3434
$this->assertSame(3.14, $this->ogm->map($data));
3535
}
3636

37-
public function testMapString()
37+
public function testMapString():void
3838
{
3939
$data = ['$type' => 'String', '_value' => 'hello'];
4040
$this->assertSame('hello', $this->ogm->map($data));
4141
}
4242

43-
public function testMapBoolean()
43+
public function testMapBoolean():void
4444
{
4545
$data = ['$type' => 'Boolean', '_value' => true];
4646
$this->assertTrue($this->ogm->map($data));
4747
}
4848

49-
public function testMapNull()
49+
public function testMapNull():void
5050
{
5151
$data = ['$type' => 'Null', '_value' => null];
5252
$this->assertNull($this->ogm->map($data));
5353
}
5454

55-
public function testMapArray()
55+
public function testMapArray():void
5656
{
5757
$data = ['$type' => 'List', '_value' => [['$type' => 'Integer', '_value' => 1], ['$type' => 'Integer', '_value' => 2]]];
5858
$this->assertSame([1, 2], $this->ogm->map($data));
5959
}
6060

61-
public function testMapNode()
61+
public function testMapNode():void
6262
{
6363
$data = [
6464
'$type' => 'Node',
@@ -71,7 +71,7 @@ public function testMapNode()
7171
$this->assertSame(['name' => 'Alice'], $result->getProperties());
7272
}
7373

74-
public function testMapRelationship()
74+
public function testMapRelationship():void
7575
{
7676
$data = [
7777
'$type' => 'Relationship',
@@ -95,7 +95,7 @@ public function testMapPoint(): void
9595
$this->assertSame(4326, $result->getSrid());
9696
}
9797

98-
public function testParseWKT()
98+
public function testParseWKT():void
9999
{
100100
$wkt = 'SRID=4326;POINT (10 20 30)';
101101
$result = OGM::parseWKT($wkt);
@@ -107,13 +107,13 @@ public function testParseWKT()
107107
$this->assertSame(4326, $result->getSrid());
108108
}
109109

110-
public function testInvalidWKTThrowsException()
110+
public function testInvalidWKTThrowsException():void
111111
{
112112
$this->expectException(InvalidArgumentException::class);
113113
OGM::parseWKT('Invalid WKT String');
114114
}
115115

116-
public function testInvalidPointFormatThrowsException()
116+
public function testInvalidPointFormatThrowsException():void
117117
{
118118
$this->expectException(InvalidArgumentException::class);
119119
$this->ogm->map(['$type' => 'Point', '_value' => 'Invalid Point Format']);

tests/Unit/srcfiles/ResponseParserUnitTest.php renamed to tests/Unit/ResponseParserUnitTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
<?php
22

3-
namespace Neo4j\QueryAPI\Tests\Unit\srcfiles;
3+
namespace Neo4j\QueryAPI\Tests\Unit;
44

5+
use Neo4j\QueryAPI\Exception\Neo4jException;
6+
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
57
use Neo4j\QueryAPI\OGM;
68
use Neo4j\QueryAPI\ResponseParser;
79
use Neo4j\QueryAPI\Results\ResultSet;
8-
use Neo4j\QueryAPI\Objects\ResultCounters;
9-
use Neo4j\QueryAPI\Objects\Bookmarks;
10-
use Neo4j\QueryAPI\Enums\AccessMode;
11-
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
12-
use Neo4j\QueryAPI\Exception\Neo4jException;
1310
use PHPUnit\Framework\TestCase;
1411
use Psr\Http\Message\ResponseInterface;
1512
use Psr\Http\Message\StreamInterface;
1613
use RuntimeException;
1714

18-
class ResponseParserUnitTest extends TestCase
15+
final class ResponseParserUnitTest extends TestCase
1916
{
2017
private ResponseParser $parser;
2118
private OGM $ogmMock;
@@ -48,13 +45,23 @@ public function testParseRunQueryResponseThrowsExceptionOnErrorResponse(): void
4845
$this->parser->parseRunQueryResponse($this->responseMock);
4946
}
5047

48+
5149
public function testParseRunQueryResponseThrowsExceptionOnInvalidData(): void
5250
{
53-
$this->responseMock->method('getStatusCode')->willReturn(200);
54-
$this->responseMock->method('getBody')->willReturn($this->streamMock);
55-
$this->streamMock->method('getContents')->willReturn(json_encode([]));
51+
$this->responseMock->expects($this->once())
52+
->method('getStatusCode')
53+
->willReturn(200);
54+
55+
$this->responseMock->expects($this->once())
56+
->method('getBody')
57+
->willReturn($this->streamMock);
58+
59+
$this->streamMock->expects($this->once())
60+
->method('getContents')
61+
->willReturn(json_encode([]));
5662

5763
$this->expectException(RuntimeException::class);
64+
5865
$this->parser->parseRunQueryResponse($this->responseMock);
5966
}
6067

0 commit comments

Comments
 (0)