Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a947ec4
main branch
Feb 24, 2025
aec41d0
implemented the unit tests for authentication and objects
Feb 24, 2025
5a89641
fixed the CI and Psalm
Feb 24, 2025
9c84675
fixed the CI and Psalm show-infor errors
Feb 24, 2025
fda7a1b
removed PersonUnitTest
Feb 24, 2025
ca125bf
implemented unit test
Feb 25, 2025
147b17a
DEBUG
Feb 27, 2025
a4d171f
DEBUG
Feb 27, 2025
ae085cf
enabled the mocking of final classes in PHPUnit
Feb 27, 2025
a7df996
enabled the mocking of final classes in PHPUnit
Feb 27, 2025
ec7693a
Debug
Feb 27, 2025
e5fc522
Debug
Feb 27, 2025
f256ec6
Removed the getters from resultCounters
Feb 27, 2025
30d31a7
updated the TransactionUnitTest
Feb 27, 2025
3b3eae0
fixed integration test for resultcounters
Feb 27, 2025
60f2f7d
fixed integration test
Feb 27, 2025
f093b16
fixed integration test
Feb 27, 2025
ae425ed
updated tests
Feb 27, 2025
e00b7d8
resolved conflicts
Feb 27, 2025
6db361a
seperated all integration tests
Feb 27, 2025
63a96ab
removed all the final keyword
pratikshazalte69 Feb 28, 2025
379ec73
DEBUG
pratikshazalte69 Feb 28, 2025
3ac6243
resolved changes according to comments
pratikshazalte69 Feb 28, 2025
78b3ad0
resolved changes
pratikshazalte69 Feb 28, 2025
3179ea9
invalidbooktest is created
123kiran17 Feb 28, 2025
f9d34da
Added unit test for ResultRow
pratikshazalte69 Feb 28, 2025
13fc352
chore: remove invalid import
123kiran17 Feb 28, 2025
c0d5bd7
Merge branch 'main' into invalidbookmarktest
123kiran17 Feb 28, 2025
8d96f84
psalm info issues are fixed
123kiran17 Feb 28, 2025
829e957
Added unit test for ResultRow
pratikshazalte69 Feb 28, 2025
1019823
Added unit test for ResultRow
pratikshazalte69 Feb 28, 2025
eac8354
Added final keyword
pratikshazalte69 Feb 28, 2025
12ba09a
fixed broken test and added schema for phpunit.xml
123kiran17 Feb 28, 2025
2c7ce6c
Merge remote-tracking branch 'origin/main' into invalidbookmarktest
123kiran17 Feb 28, 2025
dc88213
updated README.md
123kiran17 Feb 28, 2025
e8cd214
Added final keyword to all neccesary classes
pratikshazalte69 Feb 28, 2025
b48d977
minor errors
123kiran17 Feb 28, 2025
c3484e7
propertynotsetinconstructor is removed
123kiran17 Feb 28, 2025
166abee
Merge remote-tracking branch 'origin/main' into add-unit-tests-197459…
transistive Feb 28, 2025
762f5cb
Merge remote-tracking branch 'origin/invalidbookmarktest' into add-un…
transistive Feb 28, 2025
9a13ccc
fixed all warnings
transistive Feb 28, 2025
57307b0
add coverage options
transistive Feb 28, 2025
f0d214d
explicitly mark test folder in phpunit tests
transistive Feb 28, 2025
30916ba
remove coverage filter from phpunit xml
transistive Feb 28, 2025
26da2a2
winp
pratikshazalte69 Mar 3, 2025
c1ba3cf
Deprecations fixed
pratikshazalte69 Mar 3, 2025
6635290
Deprecations fixed
pratikshazalte69 Mar 3, 2025
2f744a0
added a new phunitCoverage.xml file for generating a code coverage re…
pratikshazalte69 Mar 3, 2025
a196b99
added a new phunitCoverage.xml file for generating a code coverage re…
pratikshazalte69 Mar 3, 2025
493aea5
removed phunit.cache file and xml-coverage folder
pratikshazalte69 Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Use an official PHP image as the base image
FROM php:8.1-cli

# Install necessary extensions (e.g., for Composer)
RUN apt-get update && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev git libzip-dev zip \
RUN apt-get update && \
apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
git \
libzip-dev \
zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd zip

RUN pecl install xdebug pcov && docker-php-ext-enable xdebug pcov

# Configure Xdebug for coverage
# RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Set working directory
WORKDIR /var/www

# Copy the composer.phar file to the container
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
6 changes: 6 additions & 0 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<!--
&lt;!&ndash; Logging &ndash;&gt;
<logging>
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Neo4j\QueryAPI\Objects\Bookmarks;
use Neo4j\QueryAPI\Enums\AccessMode;

final class Configuration
class Configuration
{
/**
* Constructor for Configuration class.
Expand Down
6 changes: 0 additions & 6 deletions src/Objects/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class Authentication
{
public static function basic(string $username, string $password): AuthenticateInterface
{
$username = $username ?: 'defaultUsername';
$password = $password ?: 'defaultPassword';

return new BasicAuthentication($username, $password);
}

Expand All @@ -32,9 +29,6 @@ public static function fromEnvironment(): AuthenticateInterface
);
}




public static function noAuth(): AuthenticateInterface
{
return new NoAuth();
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Node
private array $properties;

/**
* Node constructor.
* Node constructor
*
* @param string[] $labels Array of labels for the node.
* @param array<string, mixed> $properties Associative array of properties.
Expand Down
2 changes: 1 addition & 1 deletion src/ResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
use Neo4j\QueryAPI\Objects\Point;

final class ResponseParser
class ResponseParser
{
public function __construct(private readonly OGM $ogm)
{
Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/Authentication/BasicAuthenticationUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\Authentication;

use Neo4j\QueryAPI\Authentication\BasicAuthentication;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

final class BasicAuthenticationUnitTest extends TestCase
{
private BasicAuthentication $auth;
private MockObject $requestMock;

#[\Override]
protected function setUp(): void
{
$this->auth = new BasicAuthentication('testUser', 'testPass');
$this->requestMock = $this->createMock(RequestInterface::class);
}

public function testAuthenticateAddsAuthorizationHeader(): void
{
$authHeader = 'Basic ' . base64_encode('testUser:testPass');

$this->requestMock->expects($this->once())
->method('withHeader')
->with('Authorization', $authHeader)
->willReturn($this->requestMock);

$result = $this->auth->authenticate($this->requestMock);
$this->assertSame($this->requestMock, $result);
}

public function testGetHeaderReturnsCorrectValue(): void
{
$expectedHeader = 'Basic ' . base64_encode('testUser:testPass');
$this->assertEquals($expectedHeader, $this->auth->getHeader());
}

public function testGetTypeReturnsBasic(): void
{
$this->assertEquals('Basic', $this->auth->getType());
}
}
43 changes: 43 additions & 0 deletions tests/Unit/Authentication/BearerAuthenticationUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\Authentication;

use Neo4j\QueryAPI\Authentication\BearerAuthentication;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

final class BearerAuthenticationUnitTest extends TestCase
{
private BearerAuthentication $auth;
private RequestInterface $requestMock;
#[\Override]
protected function setUp(): void
{
$this->auth = new BearerAuthentication('testToken');
$this->requestMock = $this->createMock(RequestInterface::class);
}

public function testAuthenticateAddsAuthorizationHeader(): void
{
$authHeader = 'Bearer testToken';

$this->requestMock->expects($this->once())
->method('withHeader')
->with('Authorization', $authHeader)
->willReturnSelf();

$result = $this->auth->authenticate($this->requestMock);
$this->assertSame($this->requestMock, $result);
}

public function testGetHeaderReturnsCorrectValue(): void
{
$expectedHeader = 'Bearer testToken';
$this->assertEquals($expectedHeader, $this->auth->getHeader());
}

public function testGetTypeReturnsBearer(): void
{
$this->assertEquals('Bearer', $this->auth->getType());
}
}
35 changes: 35 additions & 0 deletions tests/Unit/Authentication/NoAuthUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\Authentication;

use Neo4j\QueryAPI\Authentication\NoAuth;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

final class NoAuthUnitTest extends TestCase
{
private NoAuth $auth;
private RequestInterface $requestMock;
#[\Override]
protected function setUp(): void
{
$this->auth = new NoAuth();
$this->requestMock = $this->createMock(RequestInterface::class);
}

public function testAuthenticateReturnsUnmodifiedRequest(): void
{

$this->assertSame($this->requestMock, $this->auth->authenticate($this->requestMock));
}

public function testGetHeaderReturnsEmptyString(): void
{
$this->assertEquals('', $this->auth->getHeader());
}

public function testGetTypeReturnsNoAuth(): void
{
$this->assertEquals('NoAuth', $this->auth->getType());
}
}
39 changes: 39 additions & 0 deletions tests/Unit/objects/AuthenticationUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\objects;

use Neo4j\QueryAPI\Objects\Authentication;
use Neo4j\QueryAPI\Authentication\BasicAuthentication;
use Neo4j\QueryAPI\Authentication\BearerAuthentication;
use Neo4j\QueryAPI\Authentication\NoAuth;
use PHPUnit\Framework\TestCase;

final class AuthenticationUnitTest extends TestCase
{
public function testBasicReturnsBasicAuthenticationInstance(): void
{
$auth = Authentication::basic('testUser', 'testPass');
$this->assertInstanceOf(BasicAuthentication::class, $auth);
}

public function testFromEnvironmentReturnsBasicAuthenticationInstance(): void
{
putenv('NEO4J_USERNAME=testUser');
putenv('NEO4J_PASSWORD=testPass');

$auth = Authentication::fromEnvironment();
$this->assertInstanceOf(BasicAuthentication::class, $auth);
}

public function testNoAuthReturnsNoAuthInstance(): void
{
$auth = Authentication::noAuth();
$this->assertInstanceOf(NoAuth::class, $auth);
}

public function testBearerReturnsBearerAuthenticationInstance(): void
{
$auth = Authentication::bearer('testToken');
$this->assertInstanceOf(BearerAuthentication::class, $auth);
}
}
45 changes: 45 additions & 0 deletions tests/Unit/objects/BookmarksUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\objects;

use Neo4j\QueryAPI\Objects\Bookmarks;
use PHPUnit\Framework\TestCase;

final class BookmarksUnitTest extends TestCase
{
private Bookmarks $bookmarks;
#[\Override]
protected function setUp(): void
{
$this->bookmarks = new Bookmarks(['bookmark1', 'bookmark2']);
}

public function testGetBookmarksReturnsCorrectArray(): void
{
$this->assertEquals(['bookmark1', 'bookmark2'], $this->bookmarks->getBookmarks());
}

public function testAddBookmarksMergesUniqueValues(): void
{
$newBookmarks = new Bookmarks(['bookmark1', 'bookmark2', 'bookmark3']);
$this->bookmarks->addBookmarks($newBookmarks);

$this->assertEquals(['bookmark1', 'bookmark2', 'bookmark3'], array_values($this->bookmarks->getBookmarks()));
}

public function testAddBookmarksDoesNothingWhenNullIsPassed(): void
{
$this->bookmarks->addBookmarks(null);
$this->assertEquals(['bookmark1', 'bookmark2'], $this->bookmarks->getBookmarks());
}

public function testCountReturnsCorrectNumber(): void
{
$this->assertEquals(2, $this->bookmarks->count());
}

public function testJsonSerializeReturnsCorrectArray(): void
{
$this->assertEquals(['bookmark1', 'bookmark2'], $this->bookmarks->jsonSerialize());
}
}
36 changes: 36 additions & 0 deletions tests/Unit/objects/NodeUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\objects;

use Neo4j\QueryAPI\Objects\Node;
use PHPUnit\Framework\TestCase;

final class NodeUnitTest extends TestCase
{
private Node $node;
#[\Override]
protected function setUp(): void
{
$this->node = new Node(['Label1', 'Label2'], ['key1' => 'value1', 'key2' => 42]);
}

public function testGetLabelsReturnsCorrectArray(): void
{
$this->assertEquals(['Label1', 'Label2'], $this->node->getLabels());
}

public function testGetPropertiesReturnsCorrectArray(): void
{
$this->assertEquals(['key1' => 'value1', 'key2' => 42], $this->node->getProperties());
}

public function testToArrayReturnsCorrectStructure(): void
{
$expected = [
'_labels' => ['Label1', 'Label2'],
'_properties' => ['key1' => 'value1', 'key2' => 42],
];

$this->assertEquals($expected, $this->node->toArray());
}
}
39 changes: 39 additions & 0 deletions tests/Unit/objects/PathUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Neo4j\QueryAPI\Tests\Unit\objects;

use Neo4j\QueryAPI\Objects\Path;
use Neo4j\QueryAPI\Objects\Node;
use Neo4j\QueryAPI\Objects\Relationship;
use PHPUnit\Framework\TestCase;

final class PathUnitTest extends TestCase
{
private Path $path;
private array $nodes;
private array $relationships;
#[\Override]
protected function setUp(): void
{
$this->nodes = [
new Node(['Person'], ['name' => 'Alice']),
new Node(['Person'], ['name' => 'Bob'])
];

$this->relationships = [
new Relationship('KNOWS', ['since' => 2020])
];

$this->path = new Path($this->nodes, $this->relationships);
}

public function testGetNodesReturnsCorrectArray(): void
{
$this->assertEquals($this->nodes, $this->path->getNodes());
}

public function testGetRelationshipsReturnsCorrectArray(): void
{
$this->assertEquals($this->relationships, $this->path->getRelationships());
}
}
Loading