Skip to content

Commit

Permalink
Merge pull request #157 from clue-labs/promise-v3
Browse files Browse the repository at this point in the history
Forward compatibility with upcoming Promise v3
  • Loading branch information
WyriHaximus authored Aug 30, 2022
2 parents d3d5b08 + 98690d9 commit 81d8362
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"php": ">=5.4.0",
"evenement/evenement": "^3.0 || ^2.1 || ^1.1",
"react/event-loop": "^1.2",
"react/promise": "^2.7",
"react/promise-stream": "^1.1",
"react/promise-timer": "^1.8",
"react/socket": "^1.9"
"react/promise": "^3 || ^2.7",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.9",
"react/socket": "^1.12"
},
"require-dev": {
"clue/block-react": "^1.2",
"clue/block-react": "^1.5",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions src/Io/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function ping()
$reject($reason);
})
->on('success', function () use ($resolve) {
$resolve();
$resolve(null);
});
});
}
Expand All @@ -144,7 +144,7 @@ public function quit()
$this->state = self::STATE_CLOSED;
$this->emit('end', [$this]);
$this->emit('close', [$this]);
$resolve();
$resolve(null);
});
$this->state = self::STATE_CLOSEING;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Io/LazyConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function quit()
// not already connecting => no need to connect, simply close virtual connection
if ($this->connecting === null) {
$this->close();
return \React\Promise\resolve();
return \React\Promise\resolve(null);
}

return $this->connecting()->then(function (ConnectionInterface $connection) {
Expand Down
38 changes: 19 additions & 19 deletions tests/Io/LazyConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testPingWillNotCloseConnectionWhenPendingConnectionFails()
public function testPingWillNotCloseConnectionWhenUnderlyingConnectionCloses()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand All @@ -48,7 +48,7 @@ public function testPingWillNotCloseConnectionWhenUnderlyingConnectionCloses()
public function testPingWillCancelTimerWithoutClosingConnectionWhenUnderlyingConnectionCloses()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand All @@ -69,7 +69,7 @@ public function testPingWillCancelTimerWithoutClosingConnectionWhenUnderlyingCon
public function testPingWillNotForwardErrorFromUnderlyingConnection()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand All @@ -87,8 +87,8 @@ public function testPingWillNotForwardErrorFromUnderlyingConnection()
public function testPingFollowedByIdleTimerWillQuitUnderlyingConnection()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));
$base->expects($this->never())->method('close');

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand All @@ -115,8 +115,8 @@ public function testPingFollowedByIdleTimerWillQuitUnderlyingConnection()
public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuitFails()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject(new \RuntimeException()));
$base->expects($this->once())->method('close');

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand All @@ -143,7 +143,7 @@ public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWhenQuit
public function testPingAfterIdleTimerWillCloseUnderlyingConnectionBeforeCreatingSecondConnection()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'quit', 'close'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$base->expects($this->once())->method('close');

Expand Down Expand Up @@ -289,7 +289,7 @@ public function testQueryBeforePingWillResolveWithoutStartingTimerWhenQueryFromU
public function testQueryAfterPingWillCancelTimerAgainWhenPingFromUnderlyingConnectionResolved()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('query')->with('SELECT 1')->willReturn(new Promise(function () { }));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -480,7 +480,7 @@ public function testPingWillTryToCreateNewUnderlyingConnectionAfterPreviousPingF
public function testPingWillResolveAndStartTimerWhenPingFromUnderlyingConnectionResolves()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand Down Expand Up @@ -570,7 +570,7 @@ public function testQuitAfterPingReturnsPendingPromiseWhenConnectionIsPending()
public function testQuitAfterPingWillQuitUnderlyingConnectionWhenResolved()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand All @@ -585,8 +585,8 @@ public function testQuitAfterPingWillQuitUnderlyingConnectionWhenResolved()
public function testQuitAfterPingResolvesAndEmitsCloseWhenUnderlyingConnectionQuits()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand All @@ -606,7 +606,7 @@ public function testQuitAfterPingRejectsAndEmitsCloseWhenUnderlyingConnectionFai
{
$error = new \RuntimeException();
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(\React\Promise\reject($error));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -651,7 +651,7 @@ public function testCloseAfterPingCancelsPendingConnection()
public function testCloseTwiceAfterPingWillCloseUnderlyingConnectionWhenResolved()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('close');

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -685,7 +685,7 @@ public function testCloseAfterPingDoesNotEmitConnectionErrorFromAbortedConnectio
public function testCloseAfterPingWillCancelTimerWhenPingFromUnderlyingConnectionResolves()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));

$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
$factory->expects($this->once())->method('createConnection')->willReturn(\React\Promise\resolve($base));
Expand All @@ -704,7 +704,7 @@ public function testCloseAfterPingWillCancelTimerWhenPingFromUnderlyingConnectio
public function testCloseAfterPingHasResolvedWillCloseUnderlyingConnectionWithoutTryingToCancelConnection()
{
$base = $this->getMockBuilder('React\MySQL\Io\LazyConnection')->setMethods(['ping', 'close'])->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('close')->willReturnCallback(function () use ($base) {
$base->emit('close');
});
Expand All @@ -723,7 +723,7 @@ public function testCloseAfterPingHasResolvedWillCloseUnderlyingConnectionWithou
public function testCloseAfterQuitAfterPingWillCloseUnderlyingConnectionWhenQuitIsStillPending()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$base->expects($this->once())->method('close');

Expand All @@ -740,7 +740,7 @@ public function testCloseAfterQuitAfterPingWillCloseUnderlyingConnectionWhenQuit
public function testCloseAfterPingAfterIdleTimeoutWillCloseUnderlyingConnectionWhenQuitIsStillPending()
{
$base = $this->getMockBuilder('React\MySQL\ConnectionInterface')->getMock();
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve());
$base->expects($this->once())->method('ping')->willReturn(\React\Promise\resolve(null));
$base->expects($this->once())->method('quit')->willReturn(new Promise(function () { }));
$base->expects($this->once())->method('close');

Expand Down
2 changes: 1 addition & 1 deletion tests/ResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function testSimpleSelectFromLazyConnectionWithoutDatabaseNameReturnsSame

$connection->query('select * from test.book')->then(function (QueryResult $command) {
$this->assertCount(2, $command->resultRows);
})->done();
});

$connection->quit();
Loop::run();
Expand Down

0 comments on commit 81d8362

Please sign in to comment.