Skip to content

Commit

Permalink
Merge pull request #170 from clue-labs/internal-factory
Browse files Browse the repository at this point in the history
Fix passing internal protocol factory to `Factory` class
  • Loading branch information
clue authored Dec 30, 2024
2 parents e2a4cfb + 32665df commit 2fbc581
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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');
}

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

0 comments on commit 2fbc581

Please sign in to comment.