From a5619ea982dd8a6a3d21f9a14abec79c8c88b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 22 Jun 2022 09:17:25 +0200 Subject: [PATCH] Forward compatibility with upcoming Promise v3 --- .github/workflows/ci.yml | 11 ++++++---- composer.json | 22 +++++++++++++------ src/Io/Connection.php | 4 ++-- src/Io/LazyConnection.php | 2 +- tests/Io/LazyConnectionTest.php | 38 ++++++++++++++++----------------- tests/ResultQueryTest.php | 2 +- 6 files changed, 46 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38ce90f..1016bfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/composer.json b/composer.json index f814098..6ae8323 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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" + } + ] } diff --git a/src/Io/Connection.php b/src/Io/Connection.php index 20810d2..4b0f927 100644 --- a/src/Io/Connection.php +++ b/src/Io/Connection.php @@ -128,7 +128,7 @@ public function ping() $reject($reason); }) ->on('success', function () use ($resolve) { - $resolve(); + $resolve(null); }); }); } @@ -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; }); diff --git a/src/Io/LazyConnection.php b/src/Io/LazyConnection.php index 3fc58cd..b7dcd84 100644 --- a/src/Io/LazyConnection.php +++ b/src/Io/LazyConnection.php @@ -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) { diff --git a/tests/Io/LazyConnectionTest.php b/tests/Io/LazyConnectionTest.php index ff31592..fbc1ac7 100644 --- a/tests/Io/LazyConnectionTest.php +++ b/tests/Io/LazyConnectionTest.php @@ -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)); @@ -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)); @@ -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)); @@ -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(); @@ -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(); @@ -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'); @@ -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(); @@ -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)); @@ -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(); @@ -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)); @@ -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(); @@ -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(); @@ -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)); @@ -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'); }); @@ -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'); @@ -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'); diff --git a/tests/ResultQueryTest.php b/tests/ResultQueryTest.php index 2569082..80e6892 100644 --- a/tests/ResultQueryTest.php +++ b/tests/ResultQueryTest.php @@ -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();