Skip to content

Update PHPStan and stricter types for PHPUnit #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\.$/'
7 changes: 1 addition & 6 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Io/FactoryStreamingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -47,6 +50,7 @@ public function testConstructWithoutLoopAssignsLoopAutomatically(): void
*/
public function testCtor(): void
{
assert($this->loop instanceof LoopInterface);
$this->factory = new Factory($this->loop);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Io/StreamingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
Expand All @@ -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(
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/RedisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down