Skip to content

Commit

Permalink
Update to use reactphp/async instead of clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Dec 17, 2023
1 parent 579169d commit 56b4835
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/" }
Expand Down
20 changes: 16 additions & 4 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +27,8 @@ public function testPing(): void
{
$redis = new RedisClient($this->uri);

/** @var PromiseInterface<string> */
$promise = $redis->ping();
$this->assertInstanceOf(PromiseInterface::class, $promise);

$ret = await($promise);

Expand All @@ -39,8 +39,8 @@ public function testPingLazy(): void
{
$redis = new RedisClient($this->uri);

/** @var PromiseInterface<string> */
$promise = $redis->ping();
$this->assertInstanceOf(PromiseInterface::class, $promise);

$ret = await($promise);

Expand Down Expand Up @@ -77,6 +77,7 @@ public function testMgetIsNotInterpretedAsSubMessage(): void

$redis->mset('message', 'message', 'channel', 'channel', 'payload', 'payload');

/** @var PromiseInterface<never> */
$promise = $redis->mget('message', 'channel', 'payload')->then($this->expectCallableOnce());
$redis->on('message', $this->expectCallableNever());

Expand All @@ -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<void> */
$promise = $redis->get('a')->then($this->expectCallableOnceWith('3'));

await($promise);
Expand All @@ -98,6 +101,8 @@ public function testPipeline(): void
public function testInvalidCommand(): void
{
$redis = new RedisClient($this->uri);

/** @var PromiseInterface<never> */
$promise = $redis->doesnotexist(1, 2, 3);

$this->expectException(\Exception::class);
Expand All @@ -108,6 +113,8 @@ public function testMultiExecEmpty(): void
{
$redis = new RedisClient($this->uri);
$redis->multi()->then($this->expectCallableOnceWith('OK'));

/** @var PromiseInterface<void> */
$promise = $redis->exec()->then($this->expectCallableOnceWith([]));

await($promise);
Expand All @@ -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<void> */
$promise = $redis->exec()->then($this->expectCallableOnceWith(['OK', 1, 12, 20]));

await($promise);
Expand All @@ -135,6 +144,7 @@ public function testPubSub(): void
$channel = 'channel:test:' . mt_rand();

// consumer receives a single message
/** @var Deferred<void> */
$deferred = new Deferred();
$consumer->on('message', $this->expectCallableOnce());
$consumer->on('message', [$deferred, 'resolve']);
Expand All @@ -148,7 +158,9 @@ public function testPubSub(): void

await(timeout($deferred->promise(), 0.1));

await($consumer->unsubscribe($channel));
/** @var PromiseInterface<array{0:"unsubscribe",1:string,2:0}> */
$promise = $consumer->unsubscribe($channel);
await($promise);
}

public function testClose(): void
Expand Down

0 comments on commit 56b4835

Please sign in to comment.