Skip to content

Commit

Permalink
Forward compatibility with upcoming Promise v3
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 23, 2022
1 parent 7b4428d commit a5619ea
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 33 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
# - 7.0
# - 5.6
# - 5.5
# - 5.4
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: composer install
- run: docker run -d --name mysql --net=host -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=test -e MYSQL_USER=test -e MYSQL_PASSWORD=test mysql:5
- run: bash tests/wait-for-mysql.sh
Expand All @@ -39,6 +41,7 @@ jobs:
name: PHPUnit (HHVM)
runs-on: ubuntu-18.04
continue-on-error: true
if: false # temporarily skipped until https://github.com/azjezz/setup-hhvm/issues/3 is addressed
steps:
- uses: actions/checkout@v2
- uses: azjezz/setup-hhvm@v1
Expand Down
22 changes: 16 additions & 6 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": "dev-queue-fibers as 3.0.0",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.9",
"react/socket": "dev-promise-3 as 1.12.0"
},
"require-dev": {
"clue/block-react": "^1.2",
"clue/block-react": "^1.5",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
Expand All @@ -25,5 +25,15 @@
"psr-4": {
"React\\Tests\\MySQL\\": "tests"
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/WyriHaximus-labs/socket"
},
{
"type": "vcs",
"url": "https://github.com/clue-labs/promise"
}
]
}
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 a5619ea

Please sign in to comment.