Skip to content
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

[2.x] Fix passing internal protocol factory to Factory class #170

Merged
merged 1 commit into from
Dec 30, 2024
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
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