diff --git a/src/Factory.php b/src/Factory.php index e874609..845fd54 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -25,7 +25,7 @@ class Factory /** * @param ?LoopInterface $loop * @param ?ConnectorInterface $connector - * @param ?ProtocolFactory $protocol + * @param ?ProtocolFactory $protocol (internal, should not usually be passed) */ public function __construct($loop = null, $connector = null, $protocol = null) { @@ -35,7 +35,7 @@ public function __construct($loop = null, $connector = null, $protocol = null) if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1 throw new \InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface'); } - if ($protocol !== null && !$protocol instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1 + if ($protocol !== null && !$protocol instanceof ProtocolFactory) { // manual type check to support legacy PHP < 7.1 throw new \InvalidArgumentException('Argument #3 ($protocol) expected null|Clue\Redis\Protocol\Factory'); } diff --git a/tests/FactoryLazyClientTest.php b/tests/FactoryLazyClientTest.php index 85bd24e..e9a6735 100644 --- a/tests/FactoryLazyClientTest.php +++ b/tests/FactoryLazyClientTest.php @@ -32,6 +32,18 @@ public function testConstructWithoutLoopAssignsLoopAutomatically() $this->assertInstanceOf('React\EventLoop\LoopInterface', $loop); } + public function testConstructWithProtocolFactoryAssignsGivenProtocolFactory() + { + $protocol = $this->getMockBuilder('Clue\Redis\Protocol\Factory')->getMock(); + + $factory = new Factory(null, null, $protocol); + + $ref = new \ReflectionProperty($factory, 'protocol'); + $ref->setAccessible(true); + + $this->assertSame($protocol, $ref->getValue($factory)); + } + public function testContructorThrowsExceptionForInvalidLoop() { $this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');