Skip to content

Commit 21cbdba

Browse files
committed
Fix passing internal protocol factory to Factory class
1 parent 2b3fef6 commit 21cbdba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Factory
2525
/**
2626
* @param ?LoopInterface $loop
2727
* @param ?ConnectorInterface $connector
28-
* @param ?ProtocolFactory $protocol
28+
* @param ?ProtocolFactory $protocol (internal, should not usually be passed)
2929
*/
3030
public function __construct($loop = null, $connector = null, $protocol = null)
3131
{
@@ -35,7 +35,7 @@ public function __construct($loop = null, $connector = null, $protocol = null)
3535
if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
3636
throw new \InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
3737
}
38-
if ($protocol !== null && !$protocol instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
38+
if ($protocol !== null && !$protocol instanceof ProtocolFactory) { // manual type check to support legacy PHP < 7.1
3939
throw new \InvalidArgumentException('Argument #3 ($protocol) expected null|Clue\Redis\Protocol\Factory');
4040
}
4141

tests/FactoryLazyClientTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
3232
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
3333
}
3434

35+
public function testConstructWithProtocolFactoryAssignsGivenProtocolFactory()
36+
{
37+
$protocol = $this->getMockBuilder('Clue\Redis\Protocol\Factor')->getMock();
38+
39+
$factory = new Factory(null, null, $protocol);
40+
41+
$ref = new \ReflectionProperty($factory, 'protocol');
42+
$ref->setAccessible(true);
43+
44+
$this->assertSame($protocol, $ref->getValue($factory));
45+
}
46+
3547
public function testContructorThrowsExceptionForInvalidLoop()
3648
{
3749
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');

0 commit comments

Comments
 (0)