Skip to content

Commit 83692d9

Browse files
authored
Merge pull request #63 from clue-labs/promise-v3
Forward compatibility with upcoming Promise v3
2 parents 18cfe26 + c5251eb commit 83692d9

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clue/ndjson-react": "^1.0",
1717
"react/child-process": "^0.6",
1818
"react/event-loop": "^1.2",
19-
"react/promise": "^2.7 || ^1.2.1"
19+
"react/promise": "^3 || ^2.7 || ^1.2.1"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"

src/Io/BlockingDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function quit()
142142

143143
$this->close();
144144

145-
return \React\Promise\resolve();
145+
return \React\Promise\resolve(null);
146146
}
147147

148148
public function close()

src/Io/LazyDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function quit()
116116
{
117117
if ($this->promise === null && !$this->closed) {
118118
$this->close();
119-
return \React\Promise\resolve();
119+
return \React\Promise\resolve(null);
120120
}
121121

122122
return $this->db()->then(function (DatabaseInterface $db) {

tests/Io/LazyDatabaseTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function testExecAfterExecWillNotStartIdleTimerWhenFirstExecResolves()
214214

215215
$this->db->exec('CREATE');
216216
$this->db->exec('CREATE');
217-
$deferred->resolve();
217+
$deferred->resolve(null);
218218
}
219219

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

235235
$this->db->exec('CREATE');
236-
$deferred->resolve();
236+
$deferred->resolve(null);
237237
$this->db->exec('CREATE');
238238
}
239239

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

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

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

@@ -441,7 +441,7 @@ public function testQueryAfterQueryWillNotStartIdleTimerWhenFirstQueryResolves()
441441

442442
$this->db->query('CREATE');
443443
$this->db->query('CREATE');
444-
$deferred->resolve();
444+
$deferred->resolve(null);
445445
}
446446

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

462462
$this->db->query('CREATE');
463-
$deferred->resolve();
463+
$deferred->resolve(null);
464464
$this->db->query('CREATE');
465465
}
466466

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

474474
$this->factory->expects($this->once())->method('open')->willReturn(\React\Promise\resolve($client));
@@ -531,7 +531,7 @@ public function testCloseAfterExecWillEmitCloseWithoutErrorWhenUnderlyingDatabas
531531
public function testCloseAfterExecWillCloseUnderlyingDatabaseConnectionWhenAlreadyResolved()
532532
{
533533
$client = $this->getMockBuilder('Clue\React\SQLite\DatabaseInterface')->getMock();
534-
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
534+
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
535535
$client->expects($this->once())->method('close');
536536

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

558558
$this->db->exec('CREATE');
559-
$deferred->resolve();
559+
$deferred->resolve(null);
560560
$this->db->close();
561561
}
562562

@@ -586,7 +586,7 @@ public function testCloseAfterExecRejectsWillEmitClose()
586586
public function testCloseAfterQuitAfterExecWillCloseUnderlyingConnectionWhenQuitIsStillPending()
587587
{
588588
$client = $this->getMockBuilder('Clue\React\SQLite\DatabaseInterface')->getMock();
589-
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve());
589+
$client->expects($this->once())->method('exec')->willReturn(\React\Promise\resolve(null));
590590
$client->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
591591
$client->expects($this->once())->method('close');
592592

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

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

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

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

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

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

721721
$this->db->exec('CREATE');
722-
$deferred->resolve();
722+
$deferred->resolve(null);
723723

724724
$client->emit('close');
725725
}

0 commit comments

Comments
 (0)