From 56b4835cce729bbccc1a1634c1238b377d47dd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 10 Dec 2023 17:58:50 +0100 Subject: [PATCH] Update to use reactphp/async instead of clue/reactphp-block --- composer.json | 4 ++-- tests/FunctionalTest.php | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 5601a46..bf0f9e5 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,9 @@ "react/socket": "dev-cancel-happy as 1.15.0" }, "require-dev": { - "clue/block-react": "^1.5", "phpstan/phpstan": "1.10.15 || 1.4.10", - "phpunit/phpunit": "^9.6 || ^7.5" + "phpunit/phpunit": "^9.6 || ^7.5", + "react/async": "^4 || ^3" }, "autoload": { "psr-4": { "Clue\\React\\Redis\\": "src/" } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index d66e80b..767c530 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -6,7 +6,7 @@ use React\EventLoop\Loop; use React\Promise\Deferred; use React\Promise\PromiseInterface; -use function Clue\React\Block\await; +use function React\Async\await; use function React\Promise\Timer\timeout; class FunctionalTest extends TestCase @@ -27,8 +27,8 @@ public function testPing(): void { $redis = new RedisClient($this->uri); + /** @var PromiseInterface */ $promise = $redis->ping(); - $this->assertInstanceOf(PromiseInterface::class, $promise); $ret = await($promise); @@ -39,8 +39,8 @@ public function testPingLazy(): void { $redis = new RedisClient($this->uri); + /** @var PromiseInterface */ $promise = $redis->ping(); - $this->assertInstanceOf(PromiseInterface::class, $promise); $ret = await($promise); @@ -77,6 +77,7 @@ public function testMgetIsNotInterpretedAsSubMessage(): void $redis->mset('message', 'message', 'channel', 'channel', 'payload', 'payload'); + /** @var PromiseInterface */ $promise = $redis->mget('message', 'channel', 'payload')->then($this->expectCallableOnce()); $redis->on('message', $this->expectCallableNever()); @@ -90,6 +91,8 @@ public function testPipeline(): void $redis->set('a', 1)->then($this->expectCallableOnceWith('OK')); $redis->incr('a')->then($this->expectCallableOnceWith(2)); $redis->incr('a')->then($this->expectCallableOnceWith(3)); + + /** @var PromiseInterface */ $promise = $redis->get('a')->then($this->expectCallableOnceWith('3')); await($promise); @@ -98,6 +101,8 @@ public function testPipeline(): void public function testInvalidCommand(): void { $redis = new RedisClient($this->uri); + + /** @var PromiseInterface */ $promise = $redis->doesnotexist(1, 2, 3); $this->expectException(\Exception::class); @@ -108,6 +113,8 @@ public function testMultiExecEmpty(): void { $redis = new RedisClient($this->uri); $redis->multi()->then($this->expectCallableOnceWith('OK')); + + /** @var PromiseInterface */ $promise = $redis->exec()->then($this->expectCallableOnceWith([])); await($promise); @@ -122,6 +129,8 @@ public function testMultiExecQueuedExecHasValues(): void $redis->expire('b', 20)->then($this->expectCallableOnceWith('QUEUED')); $redis->incrBy('b', 2)->then($this->expectCallableOnceWith('QUEUED')); $redis->ttl('b')->then($this->expectCallableOnceWith('QUEUED')); + + /** @var PromiseInterface */ $promise = $redis->exec()->then($this->expectCallableOnceWith(['OK', 1, 12, 20])); await($promise); @@ -135,6 +144,7 @@ public function testPubSub(): void $channel = 'channel:test:' . mt_rand(); // consumer receives a single message + /** @var Deferred */ $deferred = new Deferred(); $consumer->on('message', $this->expectCallableOnce()); $consumer->on('message', [$deferred, 'resolve']); @@ -148,7 +158,9 @@ public function testPubSub(): void await(timeout($deferred->promise(), 0.1)); - await($consumer->unsubscribe($channel)); + /** @var PromiseInterface */ + $promise = $consumer->unsubscribe($channel); + await($promise); } public function testClose(): void