From e39dd3a3cf51aa29ead6a3e6b4693bf5f29a15bc 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 1/2] Forward compatibility with upcoming Promise v3 --- .github/workflows/ci.yml | 3 +++ composer.json | 18 ++++++++++------ src/Io/Connection.php | 4 ++-- src/Io/LazyConnection.php | 2 +- tests/Io/LazyConnectionTest.php | 38 ++++++++++++++++----------------- tests/ResultQueryTest.php | 2 +- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38ce90f..09cd260 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,8 @@ jobs: 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..9491f1b 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": "^3@dev || ^2.7", + "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,11 @@ "psr-4": { "React\\Tests\\MySQL\\": "tests" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/WyriHaximus-labs/socket" + } + ] } 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(); From 98690d955cc53b83d651f306edd442fec4c4f943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 22 Jun 2022 11:57:44 +0200 Subject: [PATCH 2/2] Update to stable reactphp/socket v1.12.0 --- .github/workflows/ci.yml | 3 --- composer.json | 12 +++--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09cd260..38ce90f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,6 @@ jobs: 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 @@ -41,7 +39,6 @@ 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 9491f1b..f3a9485 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,10 @@ "php": ">=5.4.0", "evenement/evenement": "^3.0 || ^2.1 || ^1.1", "react/event-loop": "^1.2", - "react/promise": "^3@dev || ^2.7", + "react/promise": "^3 || ^2.7", "react/promise-stream": "^1.4", "react/promise-timer": "^1.9", - "react/socket": "dev-promise-3 as 1.12.0" + "react/socket": "^1.12" }, "require-dev": { "clue/block-react": "^1.5", @@ -25,11 +25,5 @@ "psr-4": { "React\\Tests\\MySQL\\": "tests" } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/WyriHaximus-labs/socket" - } - ] + } }