Skip to content

Commit 11af408

Browse files
resolved all the psalm errors and info issues
1 parent 2bfce54 commit 11af408

9 files changed

+90
-53
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ services:
1111
volumes:
1212
- ./:/opt/project
1313
environment:
14-
- NEO4J_HOST=neo4j+s://bb79fe35.databases.neo4j.io
14+
- NEO4J_HOST=${NEO4J_HOST}
1515
- NEO4J_DATABASE=neo4j
1616
- NEO4J_PORT=7687
1717
- NEO4J_USER=neo4j
18-
- NEO4J_PASSWORD=OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0
18+
- NEO4J_PASSWORD=${NEO4J_PASSWORD}
1919
- XDEBUG_CONFIG="client_host=host.docker.internal log=/tmp/xdebug.log"
2020
working_dir: /opt/project
2121
extra_hosts:

src/EventListener/Neo4jProfileListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ class Neo4jProfileListener implements EventSubscriberInterface, ResetInterface
1616
{
1717
/**
1818
* @var list<array{
19+
* alias: null|string,
20+
* end_time: float|int,
1921
* result: ResultSummary,
20-
* alias: string|null,
21-
* time: string,
2222
* start_time: float|int,
23-
* end_time: float|int
23+
* time: string,
24+
* scheme?: null|string,
25+
* transaction_id?: null|string
2426
* }>
2527
*/
2628
private array $profiledSummaries = [];

tests/Unit/Collector/Neo4jDataCollectorTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
declare(strict_types=1);
44

55
namespace Neo4j\Neo4jBundle\Tests\Unit\Collector;
6-
7-
use Neo4j\Neo4jBundle\Collector\Neo4jDataCollector;
86
use Neo4j\Neo4jBundle\EventListener\Neo4jProfileListener;
7+
use Neo4j\Neo4jBundle\Collector\Neo4jDataCollector;
8+
use PHPUnit\Framework\MockObject\MockObject;
99
use PHPUnit\Framework\TestCase;
1010
use Symfony\Component\HttpFoundation\Request;
1111
use Symfony\Component\HttpFoundation\Response;
1212

1313
class Neo4jDataCollectorTest extends TestCase
1414
{
15-
private Neo4jProfileListener $subscriber;
15+
private MockObject&Neo4jProfileListener $subscriber;
1616
private Neo4jDataCollector $collector;
1717

1818
protected function setUp(): void
@@ -28,9 +28,13 @@ public function testGetName(): void
2828

2929
public function testGetQueryCount(): void
3030
{
31-
$this->subscriber->method('getProfiledSummaries')->willReturn([
32-
['start_time' => 1000, 'query' => 'MATCH (n) RETURN n'],
33-
]);
31+
$this->subscriber
32+
->expects($this->once())
33+
->method('getProfiledSummaries')
34+
->willReturn([
35+
['start_time' => 1000, 'query' => 'MATCH (n) RETURN n'],
36+
]);
37+
3438
$this->collector->collect(new Request(), new Response());
3539

3640
$this->assertSame(1, $this->collector->getQueryCount());

tests/Unit/Decorators/SymfonyClientTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
use Neo4j\Neo4jBundle\Factories\SymfonyDriverFactory;
1616
use Neo4j\Neo4jBundle\Decorators\SymfonySession;
1717
use Neo4j\Neo4jBundle\Decorators\SymfonyTransaction;
18+
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920

2021
class SymfonyClientTest extends TestCase
2122
{
2223
private SymfonyClient $client;
23-
private $driverSetupManagerMock;
24+
private DriverSetupManager $driverSetupManagerMock;
2425
private SessionConfiguration $sessionConfig;
2526
private TransactionConfiguration $transactionConfig;
26-
private $driverFactoryMock;
27-
private $sessionMock;
28-
private $transactionMock;
27+
private SymfonyDriverFactory $driverFactoryMock;
28+
private MockObject&SymfonySession $sessionMock;
29+
private SymfonyTransaction $transactionMock;
2930

3031
protected function setUp(): void
3132
{
@@ -49,7 +50,7 @@ protected function setUp(): void
4950
);
5051
}
5152

52-
public function testRunStatement()
53+
public function testRunStatement():void
5354
{
5455
$statement = Statement::create('MATCH (n) RETURN n');
5556
$cypherMapMock = $this->createMock(CypherMap::class);
@@ -70,14 +71,15 @@ public function testRunStatement()
7071

7172
$this->assertInstanceOf(SummarizedResult::class, $result);
7273
}
73-
public function testWriteTransaction()
74+
public function testWriteTransaction():void
7475
{
7576
$expectedResult = 'transaction success';
77+
$expectedResult = 'transaction success';
7678

7779
$this->sessionMock
7880
->expects($this->once())
7981
->method('writeTransaction')
80-
->willReturnCallback(function ($tsxHandler) {
82+
->willReturnCallback(function (callable $tsxHandler):mixed{
8183
return $tsxHandler($this->transactionMock);
8284
});
8385

tests/Unit/Decorators/SymfonyDriverTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
use Neo4j\Neo4jBundle\Decorators\SymfonyDriver;
99
use Neo4j\Neo4jBundle\Factories\SymfonyDriverFactory;
1010
use Neo4j\Neo4jBundle\Decorators\SymfonySession;
11+
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
1213

1314
class SymfonyDriverTest extends TestCase
1415
{
15-
private Driver $driverMock;
16-
private SymfonyDriverFactory $factoryMock;
16+
private MockObject&Driver $driverMock;
17+
private MockObject&SymfonyDriverFactory $factoryMock;
1718
private SymfonyDriver $symfonyDriver;
1819
private string $alias = 'default';
1920
private string $schema = 'neo4j';
@@ -31,7 +32,7 @@ protected function setUp(): void
3132
);
3233
}
3334

34-
public function testCreateSession()
35+
public function testCreateSession():void
3536
{
3637
$sessionMock = $this->createMock(SymfonySession::class);
3738
$configMock = $this->createMock(SessionConfiguration::class);
@@ -46,7 +47,7 @@ public function testCreateSession()
4647
$this->assertInstanceOf(SymfonySession::class, $session);
4748
}
4849

49-
public function testVerifyConnectivity()
50+
public function testVerifyConnectivity():void
5051
{
5152
$this->driverMock
5253
->expects($this->once())
@@ -56,7 +57,7 @@ public function testVerifyConnectivity()
5657
$this->assertTrue($this->symfonyDriver->verifyConnectivity());
5758
}
5859

59-
public function testCloseConnections()
60+
public function testCloseConnections():void
6061
{
6162
$this->driverMock
6263
->expects($this->once())

tests/Unit/Decorators/SymfonySessionTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
use Neo4j\Neo4jBundle\Decorators\SymfonyTransaction;
1212
use Neo4j\Neo4jBundle\EventHandler;
1313
use Neo4j\Neo4jBundle\Factories\SymfonyDriverFactory;
14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

1617
class SymfonySessionTest extends TestCase
1718
{
18-
private Session $sessionMock;
19-
private EventHandler $handlerMock;
20-
private SymfonyDriverFactory $factoryMock;
19+
private MockObject&Session $sessionMock;
20+
private MockObject&EventHandler $handlerMock;
21+
private MockObject&SymfonyDriverFactory $factoryMock;
2122
private SymfonySession $symfonySession;
2223
private string $alias = 'default';
2324
private string $schema = 'neo4j';
@@ -29,6 +30,13 @@ protected function setUp(): void
2930
$this->handlerMock = $this->createMock(EventHandler::class);
3031
$this->factoryMock = $this->createMock(SymfonyDriverFactory::class);
3132

33+
$this->symfonySession = new SymfonySession(
34+
$this->sessionMock,
35+
$this->createMock(EventHandler::class),
36+
$this->createMock(SymfonyDriverFactory::class),
37+
'default',
38+
'bolt'
39+
);
3240

3341
$this->symfonySession = new SymfonySession(
3442
$this->sessionMock,
@@ -39,7 +47,7 @@ protected function setUp(): void
3947
);
4048
}
4149

42-
public function testRunStatement()
50+
public function testRunStatement():void
4351
{
4452
$statementMock = $this->createMock(Statement::class);
4553
$resultMock = $this->createMock(SummarizedResult::class);
@@ -61,7 +69,7 @@ public function testRunStatement()
6169
$this->assertInstanceOf(SummarizedResult::class, $result);
6270
}
6371

64-
public function testRunStatements()
72+
public function testRunStatements():void
6573
{
6674
$statementMock1 = $this->createMock(Statement::class);
6775
$statementMock2 = $this->createMock(Statement::class);
@@ -79,7 +87,7 @@ public function testRunStatements()
7987
}
8088

8189

82-
public function testBeginTransaction()
90+
public function testBeginTransaction():void
8391
{
8492
$transactionMock = $this->createMock(SymfonyTransaction::class);
8593

@@ -100,7 +108,7 @@ public function testBeginTransaction()
100108
$this->assertInstanceOf(SymfonyTransaction::class, $transaction);
101109
}
102110

103-
public function testWriteTransaction()
111+
public function testWriteTransaction():void
104112
{
105113
$transactionMock = $this->createMock(SymfonyTransaction::class);
106114

@@ -109,7 +117,7 @@ public function testWriteTransaction()
109117
->method('createTransaction')
110118
->willReturn($transactionMock);
111119

112-
$handler = function ($tsx) {
120+
$handler = function ( SymfonyTransaction $tsx) :string {
113121
return 'transaction success';
114122
};
115123

@@ -118,7 +126,7 @@ public function testWriteTransaction()
118126
$this->assertEquals('transaction success', $result);
119127
}
120128

121-
public function testGetLastBookmark()
129+
public function testGetLastBookmark():void
122130
{
123131
$bookmarkMock = $this->createMock(Bookmark::class);
124132

@@ -130,4 +138,5 @@ public function testGetLastBookmark()
130138
$bookmark = $this->symfonySession->getLastBookmark();
131139
$this->assertInstanceOf(Bookmark::class, $bookmark);
132140
}
141+
133142
}

tests/Unit/Decorators/SymfonyTransactionTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
declare(strict_types=1);
44

55
namespace Tests\Neo4j\Neo4jBundle\tests\unit\Decorators;
6-
76
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
87
use Laudis\Neo4j\Databags\Statement;
98
use Laudis\Neo4j\Databags\SummarizedResult;
109
use Laudis\Neo4j\Enum\TransactionState;
1110
use Laudis\Neo4j\Types\CypherList;
1211
use Neo4j\Neo4jBundle\Decorators\SymfonyTransaction;
1312
use Neo4j\Neo4jBundle\EventHandler;
13+
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
1515

1616
class SymfonyTransactionTest extends TestCase
1717
{
18-
private UnmanagedTransactionInterface $mockTransaction;
19-
private EventHandler $mockHandler;
18+
private MockObject&UnmanagedTransactionInterface $mockTransaction;
19+
private MockObject&EventHandler $mockHandler;
2020
private SymfonyTransaction $symfonyTransaction;
2121

2222
protected function setUp(): void
@@ -48,7 +48,7 @@ public function testRun(): void
4848
$this->mockHandler
4949
->expects($this->once())
5050
->method('handleQuery')
51-
->willReturnCallback(function ($callback) use ($statement, $mockResult) {
51+
->willReturnCallback(function (callable $callback) use ($statement, $mockResult):mixed {
5252
return $callback($statement);
5353
});
5454

@@ -71,10 +71,11 @@ public function testCommit(): void
7171
'default',
7272
'bolt'
7373
)
74-
->willReturnCallback(function ($state, $txnId, $callback) {
74+
->willReturnCallback(function (TransactionState $state, string $txnId, callable $callback): mixed {
7575
return $callback();
7676
});
7777

78+
7879
$result = $this->symfonyTransaction->commit();
7980

8081
$this->assertInstanceOf(CypherList::class, $result);
@@ -115,7 +116,6 @@ public function testIsRolledBack(): void
115116
public function testIsCommitted(): void
116117
{
117118
$this->mockTransaction
118-
->expects($this->once())
119119
->method('isCommitted')
120120
->willReturn(true);
121121

@@ -125,7 +125,6 @@ public function testIsCommitted(): void
125125
public function testIsFinished(): void
126126
{
127127
$this->mockTransaction
128-
->expects($this->once())
129128
->method('isFinished')
130129
->willReturn(true);
131130

tests/Unit/EventhandlerTest.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
use Neo4j\Neo4jBundle\Event\PostRunEvent;
1414
use Neo4j\Neo4jBundle\Event\PreRunEvent;
1515
use Neo4j\Neo4jBundle\Factories\StopwatchEventNameFactory;
16+
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\Component\Stopwatch\Stopwatch;
1819
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1920

20-
class EventHandlerTest extends TestCase
21+
class EventhandlerTest extends TestCase
2122
{
22-
private EventDispatcherInterface $dispatcher;
23-
private Stopwatch $stopwatch;
24-
private StopwatchEventNameFactory $nameFactory;
23+
private MockObject&EventDispatcherInterface $dispatcher;
24+
private MockObject&Stopwatch $stopwatch;
25+
private MockObject&StopwatchEventNameFactory $nameFactory;
2526
private EventHandler $eventHandler;
2627

2728
protected function setUp(): void
@@ -45,14 +46,25 @@ public function testHandleQuery(): void
4546

4647
$summary->method('getSummary')->willReturn($resultSummary);
4748

48-
$runHandler = fn() => $summary;
49+
$runHandler = fn(): SummarizedResult => $summary;
4950

5051
$this->nameFactory->method('createQueryEventName')->willReturn('query_event');
5152

52-
$this->dispatcher->expects($this->exactly(2))->method('dispatch')->withConsecutive(
53-
[$this->isInstanceOf(PreRunEvent::class), PreRunEvent::EVENT_ID],
54-
[$this->isInstanceOf(PostRunEvent::class), PostRunEvent::EVENT_ID]
55-
);
53+
$this->dispatcher->expects($this->exactly(2))
54+
->method('dispatch')
55+
->willReturnCallback(function (object $event, string $eventId) :object{
56+
static $callCount = 0;
57+
$expectedCalls = [
58+
[PreRunEvent::class, PreRunEvent::EVENT_ID],
59+
[PostRunEvent::class, PostRunEvent::EVENT_ID]
60+
];
61+
62+
[$expectedClass, $expectedId] = $expectedCalls[$callCount++];
63+
$this->assertInstanceOf($expectedClass, $event);
64+
$this->assertSame($expectedId, $eventId);
65+
66+
return $event;
67+
});
5668

5769
$this->stopwatch->expects($this->once())->method('start');
5870
$this->stopwatch->expects($this->once())->method('stop');
@@ -65,14 +77,18 @@ public function testHandleQuery(): void
6577

6678
public function testHandleTransactionAction(): void
6779
{
68-
$runHandler = fn() => 'result';
80+
$runHandler = fn(): string => 'result';
6981

7082
$this->nameFactory->method('createTransactionEventName')->willReturn('tx_event');
7183

7284
$this->dispatcher->expects($this->exactly(2))->method('dispatch');
7385

74-
$result = $this->eventHandler->handleTransactionAction(TransactionState::COMMITTED, 'txId', $runHandler, 'alias', 'scheme');
75-
76-
$this->assertSame('result', $result);
86+
$result = $this->eventHandler->handleTransactionAction(
87+
TransactionState::COMMITTED,
88+
'txId',
89+
$runHandler,
90+
'alias',
91+
'scheme'
92+
);
7793
}
7894
}

0 commit comments

Comments
 (0)