From 7299866ddb8ca5e63bff7d728a027b39591d55bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 11 Nov 2022 12:32:47 +0100 Subject: [PATCH] Update PHPStan and stricter types for PHPUnit --- composer.json | 2 +- phpstan.neon.dist | 2 -- tests/FunctionalTest.php | 7 +------ tests/Io/FactoryStreamingClientTest.php | 4 ++++ tests/Io/StreamingClientTest.php | 12 ++++++++++++ tests/RedisClientTest.php | 3 +++ 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 3f933de..ab034dd 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "clue/block-react": "^1.5", - "phpstan/phpstan": "1.8.11 || 1.4.10", + "phpstan/phpstan": "1.9.2 || 1.4.10", "phpunit/phpunit": "^9.5 || ^7.5" }, "autoload": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index aa2f1e3..f9fd7fb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,5 +13,3 @@ parameters: # 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::.+\(\)\.$/' - # ignore incomplete type information for mocks in legacy PHPUnit 7.5 - - '/^Parameter #\d+ .+ of .+ expects .+, PHPUnit\\Framework\\MockObject\\MockObject given\.$/' diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 673ab73..b55309b 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -103,12 +103,7 @@ public function testInvalidCommand(): void $redis = new RedisClient($this->uri, null, $this->loop); $promise = $redis->doesnotexist(1, 2, 3); - if (method_exists($this, 'expectException')) { - $this->expectException('Exception'); - } else { - assert(method_exists($this, 'setExpectedException')); - $this->setExpectedException('Exception'); - } + $this->expectException(\Exception::class); await($promise, $this->loop); } diff --git a/tests/Io/FactoryStreamingClientTest.php b/tests/Io/FactoryStreamingClientTest.php index 3cb09c6..da83302 100644 --- a/tests/Io/FactoryStreamingClientTest.php +++ b/tests/Io/FactoryStreamingClientTest.php @@ -28,6 +28,9 @@ public function setUp(): void { $this->loop = $this->createMock(LoopInterface::class); $this->connector = $this->createMock(ConnectorInterface::class); + + assert($this->loop instanceof LoopInterface); + assert($this->connector instanceof ConnectorInterface); $this->factory = new Factory($this->loop, $this->connector); } @@ -47,6 +50,7 @@ public function testConstructWithoutLoopAssignsLoopAutomatically(): void */ public function testCtor(): void { + assert($this->loop instanceof LoopInterface); $this->factory = new Factory($this->loop); } diff --git a/tests/Io/StreamingClientTest.php b/tests/Io/StreamingClientTest.php index dc47ad7..241a76d 100644 --- a/tests/Io/StreamingClientTest.php +++ b/tests/Io/StreamingClientTest.php @@ -35,6 +35,9 @@ public function setUp(): void $this->parser = $this->createMock(ParserInterface::class); $this->serializer = $this->createMock(SerializerInterface::class); + assert($this->stream instanceof DuplexStreamInterface); + assert($this->parser instanceof ParserInterface); + assert($this->serializer instanceof SerializerInterface); $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); } @@ -56,6 +59,8 @@ public function testClosingClientEmitsEvent(): void public function testClosingStreamClosesClient(): void { $stream = new ThroughStream(); + assert($this->parser instanceof ParserInterface); + assert($this->serializer instanceof SerializerInterface); $this->redis = new StreamingClient($stream, $this->parser, $this->serializer); $this->redis->on('close', $this->expectCallableOnce()); @@ -66,6 +71,8 @@ public function testClosingStreamClosesClient(): void public function testReceiveParseErrorEmitsErrorEvent(): void { $stream = new ThroughStream(); + assert($this->parser instanceof ParserInterface); + assert($this->serializer instanceof SerializerInterface); $this->redis = new StreamingClient($stream, $this->parser, $this->serializer); $this->redis->on('error', $this->expectCallableOnceWith( @@ -88,6 +95,8 @@ public function testReceiveParseErrorEmitsErrorEvent(): void public function testReceiveUnexpectedReplyEmitsErrorEvent(): void { $stream = new ThroughStream(); + assert($this->parser instanceof ParserInterface); + assert($this->serializer instanceof SerializerInterface); $this->redis = new StreamingClient($stream, $this->parser, $this->serializer); $this->redis->on('error', $this->expectCallableOnce()); @@ -169,6 +178,9 @@ public function testClosingStreamRejectsAllRemainingRequests(): void { $stream = new ThroughStream(function () { return ''; }); $this->parser->expects($this->once())->method('pushIncoming')->willReturn([]); + + assert($this->parser instanceof ParserInterface); + assert($this->serializer instanceof SerializerInterface); $this->redis = new StreamingClient($stream, $this->parser, $this->serializer); $promise = $this->redis->ping(); diff --git a/tests/RedisClientTest.php b/tests/RedisClientTest.php index 813523a..323b3f8 100644 --- a/tests/RedisClientTest.php +++ b/tests/RedisClientTest.php @@ -27,6 +27,7 @@ public function setUp(): void $this->factory = $this->createMock(Factory::class); $this->loop = $this->createMock(LoopInterface::class); + assert($this->loop instanceof LoopInterface); $this->redis = new RedisClient('localhost', null, $this->loop); $ref = new \ReflectionProperty($this->redis, 'factory'); @@ -73,6 +74,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleTimerWithIdleTimeFromQueryParam(): void { + assert($this->loop instanceof LoopInterface); $this->redis = new RedisClient('localhost?idle=10', null, $this->loop); $ref = new \ReflectionProperty($this->redis, 'factory'); @@ -95,6 +97,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT public function testPingWillResolveWhenUnderlyingClientResolvesPingAndNotStartIdleTimerWhenIdleParamIsNegative(): void { + assert($this->loop instanceof LoopInterface); $this->redis = new RedisClient('localhost?idle=-1', null, $this->loop); $ref = new \ReflectionProperty($this->redis, 'factory');