Skip to content

Commit 581b27c

Browse files
authored
Merge pull request #141 from clue-labs/phpstan
Update PHPStan and stricter types for PHPUnit
2 parents 830c2b2 + 7299866 commit 581b27c

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"clue/block-react": "^1.5",
24-
"phpstan/phpstan": "1.8.11 || 1.4.10",
24+
"phpstan/phpstan": "1.9.2 || 1.4.10",
2525
"phpunit/phpunit": "^9.5 || ^7.5"
2626
},
2727
"autoload": {

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@ parameters:
1313
# ignore undefined methods due to magic `__call()` method
1414
- '/^Call to an undefined method Clue\\React\\Redis\\RedisClient::.+\(\)\.$/'
1515
- '/^Call to an undefined method Clue\\React\\Redis\\Io\\StreamingClient::.+\(\)\.$/'
16-
# ignore incomplete type information for mocks in legacy PHPUnit 7.5
17-
- '/^Parameter #\d+ .+ of .+ expects .+, PHPUnit\\Framework\\MockObject\\MockObject given\.$/'

tests/FunctionalTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ public function testInvalidCommand(): void
103103
$redis = new RedisClient($this->uri, null, $this->loop);
104104
$promise = $redis->doesnotexist(1, 2, 3);
105105

106-
if (method_exists($this, 'expectException')) {
107-
$this->expectException('Exception');
108-
} else {
109-
assert(method_exists($this, 'setExpectedException'));
110-
$this->setExpectedException('Exception');
111-
}
106+
$this->expectException(\Exception::class);
112107
await($promise, $this->loop);
113108
}
114109

tests/Io/FactoryStreamingClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function setUp(): void
2828
{
2929
$this->loop = $this->createMock(LoopInterface::class);
3030
$this->connector = $this->createMock(ConnectorInterface::class);
31+
32+
assert($this->loop instanceof LoopInterface);
33+
assert($this->connector instanceof ConnectorInterface);
3134
$this->factory = new Factory($this->loop, $this->connector);
3235
}
3336

@@ -47,6 +50,7 @@ public function testConstructWithoutLoopAssignsLoopAutomatically(): void
4750
*/
4851
public function testCtor(): void
4952
{
53+
assert($this->loop instanceof LoopInterface);
5054
$this->factory = new Factory($this->loop);
5155
}
5256

tests/Io/StreamingClientTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function setUp(): void
3535
$this->parser = $this->createMock(ParserInterface::class);
3636
$this->serializer = $this->createMock(SerializerInterface::class);
3737

38+
assert($this->stream instanceof DuplexStreamInterface);
39+
assert($this->parser instanceof ParserInterface);
40+
assert($this->serializer instanceof SerializerInterface);
3841
$this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer);
3942
}
4043

@@ -56,6 +59,8 @@ public function testClosingClientEmitsEvent(): void
5659
public function testClosingStreamClosesClient(): void
5760
{
5861
$stream = new ThroughStream();
62+
assert($this->parser instanceof ParserInterface);
63+
assert($this->serializer instanceof SerializerInterface);
5964
$this->redis = new StreamingClient($stream, $this->parser, $this->serializer);
6065

6166
$this->redis->on('close', $this->expectCallableOnce());
@@ -66,6 +71,8 @@ public function testClosingStreamClosesClient(): void
6671
public function testReceiveParseErrorEmitsErrorEvent(): void
6772
{
6873
$stream = new ThroughStream();
74+
assert($this->parser instanceof ParserInterface);
75+
assert($this->serializer instanceof SerializerInterface);
6976
$this->redis = new StreamingClient($stream, $this->parser, $this->serializer);
7077

7178
$this->redis->on('error', $this->expectCallableOnceWith(
@@ -88,6 +95,8 @@ public function testReceiveParseErrorEmitsErrorEvent(): void
8895
public function testReceiveUnexpectedReplyEmitsErrorEvent(): void
8996
{
9097
$stream = new ThroughStream();
98+
assert($this->parser instanceof ParserInterface);
99+
assert($this->serializer instanceof SerializerInterface);
91100
$this->redis = new StreamingClient($stream, $this->parser, $this->serializer);
92101

93102
$this->redis->on('error', $this->expectCallableOnce());
@@ -169,6 +178,9 @@ public function testClosingStreamRejectsAllRemainingRequests(): void
169178
{
170179
$stream = new ThroughStream(function () { return ''; });
171180
$this->parser->expects($this->once())->method('pushIncoming')->willReturn([]);
181+
182+
assert($this->parser instanceof ParserInterface);
183+
assert($this->serializer instanceof SerializerInterface);
172184
$this->redis = new StreamingClient($stream, $this->parser, $this->serializer);
173185

174186
$promise = $this->redis->ping();

tests/RedisClientTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function setUp(): void
2727
$this->factory = $this->createMock(Factory::class);
2828
$this->loop = $this->createMock(LoopInterface::class);
2929

30+
assert($this->loop instanceof LoopInterface);
3031
$this->redis = new RedisClient('localhost', null, $this->loop);
3132

3233
$ref = new \ReflectionProperty($this->redis, 'factory');
@@ -73,6 +74,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT
7374

7475
public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleTimerWithIdleTimeFromQueryParam(): void
7576
{
77+
assert($this->loop instanceof LoopInterface);
7678
$this->redis = new RedisClient('localhost?idle=10', null, $this->loop);
7779

7880
$ref = new \ReflectionProperty($this->redis, 'factory');
@@ -95,6 +97,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT
9597

9698
public function testPingWillResolveWhenUnderlyingClientResolvesPingAndNotStartIdleTimerWhenIdleParamIsNegative(): void
9799
{
100+
assert($this->loop instanceof LoopInterface);
98101
$this->redis = new RedisClient('localhost?idle=-1', null, $this->loop);
99102

100103
$ref = new \ReflectionProperty($this->redis, 'factory');

0 commit comments

Comments
 (0)