-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
$loop
constructor argument, always use default loop
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
|
||
class FunctionalTest extends TestCase | ||
{ | ||
|
||
/** @var string */ | ||
private $uri; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use Clue\React\Redis\Io\StreamingClient; | ||
use Clue\Tests\React\Redis\TestCase; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use React\EventLoop\Loop; | ||
use React\EventLoop\LoopInterface; | ||
use React\EventLoop\TimerInterface; | ||
use React\Promise\Deferred; | ||
|
@@ -16,43 +17,39 @@ | |
|
||
class FactoryStreamingClientTest extends TestCase | ||
{ | ||
/** @var MockObject */ | ||
private $loop; | ||
|
||
/** @var MockObject */ | ||
private $connector; | ||
|
||
/** @var Factory */ | ||
private $factory; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->loop = $this->createMock(LoopInterface::class); | ||
$this->connector = $this->createMock(ConnectorInterface::class); | ||
/** @var LoopInterface */ | ||
public static $loop; | ||
|
||
assert($this->loop instanceof LoopInterface); | ||
assert($this->connector instanceof ConnectorInterface); | ||
$this->factory = new Factory($this->loop, $this->connector); | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$loop = Loop::get(); | ||
} | ||
|
||
public function testConstructWithoutLoopAssignsLoopAutomatically(): void | ||
public static function tearDownAfterClass(): void | ||
{ | ||
$factory = new Factory(); | ||
Loop::set(self::$loop); | ||
} | ||
|
||
$ref = new \ReflectionProperty($factory, 'loop'); | ||
$ref->setAccessible(true); | ||
$loop = $ref->getValue($factory); | ||
public function setUp(): void | ||
{ | ||
$this->connector = $this->createMock(ConnectorInterface::class); | ||
|
||
$this->assertInstanceOf(LoopInterface::class, $loop); | ||
assert($this->connector instanceof ConnectorInterface); | ||
$this->factory = new Factory($this->connector); | ||
} | ||
|
||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testCtor(): void | ||
{ | ||
assert($this->loop instanceof LoopInterface); | ||
$this->factory = new Factory($this->loop); | ||
$this->factory = new Factory(); | ||
} | ||
|
||
public function testWillConnectWithDefaultPort(): void | ||
|
@@ -87,6 +84,10 @@ public function testWillWriteSelectCommandIfTargetContainsPath(): void | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 89 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://127.0.0.1/demo'); | ||
} | ||
|
@@ -96,6 +97,10 @@ public function testWillWriteSelectCommandIfTargetContainsDbQueryParameter(): vo | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$1\r\n4\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 102 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://127.0.0.1?db=4'); | ||
} | ||
|
@@ -105,6 +110,10 @@ public function testWillWriteAuthCommandIfRedisUriContainsUserInfo(): void | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 115 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('example.com:6379')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://hello:[email protected]'); | ||
} | ||
|
@@ -114,6 +123,10 @@ public function testWillWriteAuthCommandIfRedisUriContainsEncodedUserInfo(): voi | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nh@llo\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 128 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('example.com:6379')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://:h%[email protected]'); | ||
} | ||
|
@@ -123,6 +136,10 @@ public function testWillWriteAuthCommandIfTargetContainsPasswordQueryParameter() | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$6\r\nsecret\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 141 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('example.com:6379')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://example.com?password=secret'); | ||
} | ||
|
@@ -132,6 +149,10 @@ public function testWillWriteAuthCommandIfTargetContainsEncodedPasswordQueryPara | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nh@llo\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 154 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('example.com:6379')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis://example.com?password=h%40llo'); | ||
} | ||
|
@@ -141,6 +162,10 @@ public function testWillWriteAuthCommandIfRedissUriContainsUserInfo(): void | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 167 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('tls://example.com:6379')->willReturn(resolve($stream)); | ||
$this->factory->createClient('rediss://hello:[email protected]'); | ||
} | ||
|
@@ -150,6 +175,10 @@ public function testWillWriteAuthCommandIfRedisUnixUriContainsPasswordQueryParam | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 180 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis+unix:///tmp/redis.sock?password=world'); | ||
} | ||
|
@@ -168,6 +197,10 @@ public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo(): void | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 202 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis+unix://hello:world@/tmp/redis.sock'); | ||
} | ||
|
@@ -275,6 +308,10 @@ public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter | |
$stream = $this->createMock(ConnectionInterface::class); | ||
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n"); | ||
|
||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer'); | ||
Loop::set($loop); | ||
Check failure on line 313 in tests/Io/FactoryStreamingClientTest.php GitHub Actions / PHPStan (PHP 7.2)
|
||
|
||
$this->connector->expects($this->once())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream)); | ||
$this->factory->createClient('redis+unix:///tmp/redis.sock?db=demo'); | ||
} | ||
|
@@ -584,8 +621,11 @@ public function testCancelWillCloseConnectionWhenConnectionWaitsForSelect(): voi | |
|
||
public function testCreateClientWithTimeoutParameterWillStartTimerAndRejectOnExplicitTimeout(): void | ||
{ | ||
$loop = $this->createMock(LoopInterface::class); | ||
Loop::set($loop); | ||
|
||
$timeout = null; | ||
$this->loop->expects($this->once())->method('addTimer')->with(0, $this->callback(function ($cb) use (&$timeout) { | ||
$loop->expects($this->once())->method('addTimer')->with(0, $this->callback(function ($cb) use (&$timeout) { | ||
$timeout = $cb; | ||
return true; | ||
})); | ||
|
@@ -613,7 +653,10 @@ public function testCreateClientWithTimeoutParameterWillStartTimerAndRejectOnExp | |
|
||
public function testCreateClientWithNegativeTimeoutParameterWillNotStartTimer(): void | ||
{ | ||
$this->loop->expects($this->never())->method('addTimer'); | ||
$loop = $this->createMock(LoopInterface::class); | ||
Loop::set($loop); | ||
|
||
$loop->expects($this->never())->method('addTimer'); | ||
|
||
$deferred = new Deferred(); | ||
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:2')->willReturn($deferred->promise()); | ||
|
@@ -623,7 +666,9 @@ public function testCreateClientWithNegativeTimeoutParameterWillNotStartTimer(): | |
|
||
public function testCreateClientWithoutTimeoutParameterWillStartTimerWithDefaultTimeoutFromIni(): void | ||
{ | ||
$this->loop->expects($this->once())->method('addTimer')->with(42, $this->anything()); | ||
$loop = $this->createMock(LoopInterface::class); | ||
$loop->expects($this->once())->method('addTimer')->with(42, $this->anything()); | ||
Loop::set($loop); | ||
|
||
$deferred = new Deferred(); | ||
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:2')->willReturn($deferred->promise()); | ||
|
@@ -637,9 +682,11 @@ public function testCreateClientWithoutTimeoutParameterWillStartTimerWithDefault | |
|
||
public function testCreateClientWillCancelTimerWhenConnectionResolves(): void | ||
{ | ||
$loop = $this->createMock(LoopInterface::class); | ||
$timer = $this->createMock(TimerInterface::class); | ||
$this->loop->expects($this->once())->method('addTimer')->willReturn($timer); | ||
$this->loop->expects($this->once())->method('cancelTimer')->with($timer); | ||
$loop->expects($this->once())->method('addTimer')->willReturn($timer); | ||
$loop->expects($this->once())->method('cancelTimer')->with($timer); | ||
Loop::set($loop); | ||
|
||
$deferred = new Deferred(); | ||
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:6379')->willReturn($deferred->promise()); | ||
|
@@ -652,9 +699,11 @@ public function testCreateClientWillCancelTimerWhenConnectionResolves(): void | |
|
||
public function testCreateClientWillCancelTimerWhenConnectionRejects(): void | ||
{ | ||
$loop = $this->createMock(LoopInterface::class); | ||
$timer = $this->createMock(TimerInterface::class); | ||
$this->loop->expects($this->once())->method('addTimer')->willReturn($timer); | ||
$this->loop->expects($this->once())->method('cancelTimer')->with($timer); | ||
$loop->expects($this->once())->method('addTimer')->willReturn($timer); | ||
$loop->expects($this->once())->method('cancelTimer')->with($timer); | ||
Loop::set($loop); | ||
|
||
$deferred = new Deferred(); | ||
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:6379')->willReturn($deferred->promise()); | ||
|