Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatibility with upcoming Promise v3 #63

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"clue/ndjson-react": "^1.0",
"react/child-process": "^0.6",
"react/event-loop": "^1.2",
"react/promise": "^2.7 || ^1.2.1"
"react/promise": "^3 || ^2.7 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
Expand Down
2 changes: 1 addition & 1 deletion src/Io/BlockingDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function quit()

$this->close();

return \React\Promise\resolve();
return \React\Promise\resolve(null);
}

public function close()
Expand Down
2 changes: 1 addition & 1 deletion src/Io/LazyDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function quit()
{
if ($this->promise === null && !$this->closed) {
$this->close();
return \React\Promise\resolve();
return \React\Promise\resolve(null);
}

return $this->db()->then(function (DatabaseInterface $db) {
Expand Down
38 changes: 19 additions & 19 deletions tests/Io/LazyDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function testExecAfterExecWillNotStartIdleTimerWhenFirstExecResolves()

$this->db->exec('CREATE');
$this->db->exec('CREATE');
$deferred->resolve();
$deferred->resolve(null);
}

public function testExecAfterExecWillStartAndCancelIdleTimerWhenSecondExecStartsAfterFirstResolves()
Expand All @@ -233,15 +233,15 @@ public function testExecAfterExecWillStartAndCancelIdleTimerWhenSecondExecStarts
$this->loop->expects($this->once())->method('cancelTimer')->with($timer);

$this->db->exec('CREATE');
$deferred->resolve();
$deferred->resolve(null);
$this->db->exec('CREATE');
}

public function testExecFollowedByIdleTimerWillQuitUnderlyingConnectionWithoutCloseEvent()
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->disableOriginalConstructor()->setMethods(array('exec', 'quit', 'close'))->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));
$client->expects($this->never())->method('close');

$this->factory->expects($this->once())->method('open')->willReturn(\React\Promise\resolve($client));
Expand All @@ -264,8 +264,8 @@ public function testExecFollowedByIdleTimerWillQuitUnderlyingConnectionWithoutCl
public function testExecFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuitFails()
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->setMethods(array('exec', 'quit', 'close'))->disableOriginalConstructor()->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\reject());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\reject(new \RuntimeException()));
$client->expects($this->once())->method('close');

$this->factory->expects($this->once())->method('open')->willReturn(\React\Promise\resolve($client));
Expand All @@ -288,7 +288,7 @@ public function testExecFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuit
public function testExecAfterIdleTimerWillCloseUnderlyingConnectionBeforeCreatingSecondConnection()
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->setMethods(array('exec', 'quit', 'close'))->disableOriginalConstructor()->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$client->expects($this->once())->method('close');

Expand Down Expand Up @@ -441,7 +441,7 @@ public function testQueryAfterQueryWillNotStartIdleTimerWhenFirstQueryResolves()

$this->db->query('CREATE');
$this->db->query('CREATE');
$deferred->resolve();
$deferred->resolve(null);
}

public function testQueryAfterQueryWillStartAndCancelIdleTimerWhenSecondQueryStartsAfterFirstResolves()
Expand All @@ -460,15 +460,15 @@ public function testQueryAfterQueryWillStartAndCancelIdleTimerWhenSecondQuerySta
$this->loop->expects($this->once())->method('cancelTimer')->with($timer);

$this->db->query('CREATE');
$deferred->resolve();
$deferred->resolve(null);
$this->db->query('CREATE');
}

public function testQueryFollowedByIdleTimerWillQuitUnderlyingConnectionWithoutCloseEvent()
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->disableOriginalConstructor()->setMethods(array('query', 'quit', 'close'))->getMock();
$client->expects($this->once())->method('query')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('query')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));
$client->expects($this->never())->method('close');

$this->factory->expects($this->once())->method('open')->willReturn(\React\Promise\resolve($client));
Expand Down Expand Up @@ -531,7 +531,7 @@ public function testCloseAfterExecWillEmitCloseWithoutErrorWhenUnderlyingDatabas
public function testCloseAfterExecWillCloseUnderlyingDatabaseConnectionWhenAlreadyResolved()
{
$client = $this->getMockBuilder('Clue\React\SQLite\DatabaseInterface')->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('close');

$deferred = new Deferred();
Expand All @@ -556,7 +556,7 @@ public function testCloseAfterExecWillCancelIdleTimerWhenExecIsAlreadyResolved()
$this->loop->expects($this->once())->method('cancelTimer')->with($timer);

$this->db->exec('CREATE');
$deferred->resolve();
$deferred->resolve(null);
$this->db->close();
}

Expand Down Expand Up @@ -586,7 +586,7 @@ public function testCloseAfterExecRejectsWillEmitClose()
public function testCloseAfterQuitAfterExecWillCloseUnderlyingConnectionWhenQuitIsStillPending()
{
$client = $this->getMockBuilder('Clue\React\SQLite\DatabaseInterface')->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$client->expects($this->once())->method('close');

Expand All @@ -600,7 +600,7 @@ public function testCloseAfterQuitAfterExecWillCloseUnderlyingConnectionWhenQuit
public function testCloseAfterExecAfterIdleTimeoutWillCloseUnderlyingConnectionWhenQuitIsStillPending()
{
$client = $this->getMockBuilder('Clue\React\SQLite\DatabaseInterface')->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
$client->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$client->expects($this->once())->method('close');

Expand Down Expand Up @@ -657,7 +657,7 @@ public function testQuitAfterExecWillCloseDatabaseWhenUnderlyingDatabaseEmitsClo
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->disableOriginalConstructor()->setMethods(array('exec', 'quit'))->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve('PONG'));
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));

$deferred = new Deferred();
$this->factory->expects($this->once())->method('open')->willReturn($deferred->promise());
Expand All @@ -677,7 +677,7 @@ public function testEmitsNoErrorEventWhenUnderlyingDatabaseEmitsError()
$error = new \RuntimeException();

$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->disableOriginalConstructor()->setMethods(array('exec'))->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));

$deferred = new Deferred();
$this->factory->expects($this->once())->method('open')->willReturn($deferred->promise());
Expand All @@ -692,7 +692,7 @@ public function testEmitsNoErrorEventWhenUnderlyingDatabaseEmitsError()
public function testEmitsNoCloseEventWhenUnderlyingDatabaseEmitsClose()
{
$client = $this->getMockBuilder('Clue\React\SQLite\Io\ProcessIoDatabase')->disableOriginalConstructor()->setMethods(array('exec'))->getMock();
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));

$deferred = new Deferred();
$this->factory->expects($this->once())->method('open')->willReturn($deferred->promise());
Expand All @@ -719,7 +719,7 @@ public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnect
$this->db->on('close', $this->expectCallableNever());

$this->db->exec('CREATE');
$deferred->resolve();
$deferred->resolve(null);

$client->emit('close');
}
Expand Down