From c5251eb9348b444efa40a6d3a3fa12b60c6ea744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 3 Sep 2022 18:35:56 +0200 Subject: [PATCH] Forward compatibility with upcoming Promise v3 --- composer.json | 2 +- src/Io/BlockingDatabase.php | 2 +- src/Io/LazyDatabase.php | 2 +- tests/Io/LazyDatabaseTest.php | 38 +++++++++++++++++------------------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 9b272c1..f1fd012 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/Io/BlockingDatabase.php b/src/Io/BlockingDatabase.php index b6fdd9c..811cf91 100644 --- a/src/Io/BlockingDatabase.php +++ b/src/Io/BlockingDatabase.php @@ -142,7 +142,7 @@ public function quit() $this->close(); - return \React\Promise\resolve(); + return \React\Promise\resolve(null); } public function close() diff --git a/src/Io/LazyDatabase.php b/src/Io/LazyDatabase.php index 7beb1fe..23c377b 100644 --- a/src/Io/LazyDatabase.php +++ b/src/Io/LazyDatabase.php @@ -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) { diff --git a/tests/Io/LazyDatabaseTest.php b/tests/Io/LazyDatabaseTest.php index 143952e..4e69a88 100644 --- a/tests/Io/LazyDatabaseTest.php +++ b/tests/Io/LazyDatabaseTest.php @@ -214,7 +214,7 @@ public function testExecAfterExecWillNotStartIdleTimerWhenFirstExecResolves() $this->db->exec('CREATE'); $this->db->exec('CREATE'); - $deferred->resolve(); + $deferred->resolve(null); } public function testExecAfterExecWillStartAndCancelIdleTimerWhenSecondExecStartsAfterFirstResolves() @@ -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)); @@ -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)); @@ -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'); @@ -441,7 +441,7 @@ public function testQueryAfterQueryWillNotStartIdleTimerWhenFirstQueryResolves() $this->db->query('CREATE'); $this->db->query('CREATE'); - $deferred->resolve(); + $deferred->resolve(null); } public function testQueryAfterQueryWillStartAndCancelIdleTimerWhenSecondQueryStartsAfterFirstResolves() @@ -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)); @@ -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(); @@ -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(); } @@ -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'); @@ -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'); @@ -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()); @@ -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()); @@ -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()); @@ -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'); }