From 434a4bf8a837f86bc1d96a73fa4c606b1d082b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 30 Jul 2023 12:55:37 +0200 Subject: [PATCH] Update to require Promise v3 --- composer.json | 2 +- phpstan.neon.dist | 3 --- src/Io/Factory.php | 2 -- src/RedisClient.php | 1 - tests/Io/FactoryStreamingClientTest.php | 3 --- tests/TestCase.php | 9 ++++----- 6 files changed, 5 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 242b91f..335b526 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "clue/redis-protocol": "0.3.*", "evenement/evenement": "^3.0 || ^2.0 || ^1.0", "react/event-loop": "^1.2", - "react/promise": "^3 || ^2.0 || ^1.1", + "react/promise": "^3", "react/promise-timer": "^1.10", "react/socket": "^1.15" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fb725aa..be4a66a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,10 +6,7 @@ parameters: - src/ - tests/ - reportUnmatchedIgnoredErrors: false ignoreErrors: - # ignore generic usage like `PromiseInterface` for Promise v2/v1 - - '/^PHPDoc tag @return contains generic type React\\Promise\\PromiseInterface<.+> but interface React\\Promise\\PromiseInterface is not generic\.$/' # ignore undefined methods due to magic `__call()` method - '/^Call to an undefined method Clue\\React\\Redis\\RedisClient::.+\(\)\.$/' - '/^Call to an undefined method Clue\\React\\Redis\\Io\\StreamingClient::.+\(\)\.$/' diff --git a/src/Io/Factory.php b/src/Io/Factory.php index d70a08c..b6778b9 100644 --- a/src/Io/Factory.php +++ b/src/Io/Factory.php @@ -80,7 +80,6 @@ public function createClient(string $uri): PromiseInterface unset($parts['path']); } - /** @var PromiseInterface $connecting */ $connecting = $this->connector->connect($authority); $deferred = new Deferred(function ($_, $reject) use ($connecting, $uri) { @@ -96,7 +95,6 @@ public function createClient(string $uri): PromiseInterface }, function () { // ignore to avoid reporting unhandled rejection }); - assert(\method_exists($connecting, 'cancel')); $connecting->cancel(); }); diff --git a/src/RedisClient.php b/src/RedisClient.php index bfe9ac8..f923d0f 100644 --- a/src/RedisClient.php +++ b/src/RedisClient.php @@ -229,7 +229,6 @@ public function close(): void // ignore to avoid reporting unhandled rejection }); if ($this->promise !== null) { - assert(\method_exists($this->promise, 'cancel')); $this->promise->cancel(); $this->promise = null; } diff --git a/tests/Io/FactoryStreamingClientTest.php b/tests/Io/FactoryStreamingClientTest.php index 4df8589..fba36e8 100644 --- a/tests/Io/FactoryStreamingClientTest.php +++ b/tests/Io/FactoryStreamingClientTest.php @@ -459,7 +459,6 @@ public function testCancelWillRejectPromise(): void $promise = $this->factory->createClient('redis://127.0.0.1:2'); - assert(method_exists($promise, 'cancel')); $promise->cancel(); $promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf(\RuntimeException::class))); @@ -542,7 +541,6 @@ public function testCancelWillRejectWithUriInMessageAndCancelConnectorWhenConnec $promise = $this->factory->createClient($uri); - assert(method_exists($promise, 'cancel')); $promise->cancel(); $promise->then(null, $this->expectCallableOnceWith( @@ -568,7 +566,6 @@ public function testCancelWillCloseConnectionWhenConnectionWaitsForSelect(): voi $promise = $this->factory->createClient('redis://127.0.0.1:2/123'); - assert(method_exists($promise, 'cancel')); $promise->cancel(); $promise->then(null, $this->expectCallableOnceWith( diff --git a/tests/TestCase.php b/tests/TestCase.php index 483864d..722c8b6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,6 @@ namespace Clue\Tests\React\Redis; -use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase as BaseTestCase; use React\Promise\PromiseInterface; @@ -39,12 +38,12 @@ protected function expectCallableNever(): callable protected function createCallableMock(): MockObject { - if (method_exists(MockBuilder::class, 'addMethods')) { - // @phpstan-ignore-next-line requires PHPUnit 9+ - return $this->getMockBuilder(\stdClass::class)->addMethods(['__invoke'])->getMock(); + $builder = $this->getMockBuilder(\stdClass::class); + if (method_exists($builder, 'addMethods')) { + return $builder->addMethods(['__invoke'])->getMock(); } else { // legacy PHPUnit < 9 - return $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + return $builder->setMethods(['__invoke'])->getMock(); } }