*/ public function numberOfTests() { return [[], [], []]; } public function testStaticAddReadStreamCallsAddReadStreamOnLoopInstance() { $stream = tmpfile(); $listener = function () { }; $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addReadStream')->with($stream, $listener); Loop::set($loop); Loop::addReadStream($stream, $listener); } public function testStaticAddReadStreamWithNoDefaultLoopCallsAddReadStreamOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $stream = stream_socket_server('127.0.0.1:0'); $listener = function () { }; Loop::addReadStream($stream, $listener); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticAddWriteStreamCallsAddWriteStreamOnLoopInstance() { $stream = tmpfile(); $listener = function () { }; $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addWriteStream')->with($stream, $listener); Loop::set($loop); Loop::addWriteStream($stream, $listener); } public function testStaticAddWriteStreamWithNoDefaultLoopCallsAddWriteStreamOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $stream = stream_socket_server('127.0.0.1:0'); $listener = function () { }; Loop::addWriteStream($stream, $listener); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticRemoveReadStreamCallsRemoveReadStreamOnLoopInstance() { $stream = tmpfile(); $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('removeReadStream')->with($stream); Loop::set($loop); Loop::removeReadStream($stream); } public function testStaticRemoveReadStreamWithNoDefaultLoopIsNoOp() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $stream = tmpfile(); Loop::removeReadStream($stream); $this->assertNull($ref->getValue()); } public function testStaticRemoveWriteStreamCallsRemoveWriteStreamOnLoopInstance() { $stream = tmpfile(); $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('removeWriteStream')->with($stream); Loop::set($loop); Loop::removeWriteStream($stream); } public function testStaticRemoveWriteStreamWithNoDefaultLoopIsNoOp() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $stream = tmpfile(); Loop::removeWriteStream($stream); $this->assertNull($ref->getValue()); } public function testStaticAddTimerCallsAddTimerOnLoopInstanceAndReturnsTimerInstance() { $interval = 1.0; $callback = function () { }; $timer = $this->createMock(TimerInterface::class); $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with($interval, $callback)->willReturn($timer); Loop::set($loop); $ret = Loop::addTimer($interval, $callback); $this->assertSame($timer, $ret); } public function testStaticAddTimerWithNoDefaultLoopCallsAddTimerOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $interval = 1.0; $callback = function () { }; $ret = Loop::addTimer($interval, $callback); $this->assertInstanceOf(TimerInterface::class, $ret); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticAddPeriodicTimerCallsAddPeriodicTimerOnLoopInstanceAndReturnsTimerInstance() { $interval = 1.0; $callback = function () { }; $timer = $this->createMock(TimerInterface::class); $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addPeriodicTimer')->with($interval, $callback)->willReturn($timer); Loop::set($loop); $ret = Loop::addPeriodicTimer($interval, $callback); $this->assertSame($timer, $ret); } public function testStaticAddPeriodicTimerWithNoDefaultLoopCallsAddPeriodicTimerOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $interval = 1.0; $callback = function () { }; $ret = Loop::addPeriodicTimer($interval, $callback); $this->assertInstanceOf(TimerInterface::class, $ret); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticCancelTimerCallsCancelTimerOnLoopInstance() { $timer = $this->createMock(TimerInterface::class); $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('cancelTimer')->with($timer); Loop::set($loop); Loop::cancelTimer($timer); } public function testStaticCancelTimerWithNoDefaultLoopIsNoOp() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $timer = $this->createMock(TimerInterface::class); Loop::cancelTimer($timer); $this->assertNull($ref->getValue()); } public function testStaticFutureTickCallsFutureTickOnLoopInstance() { $listener = function () { }; $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('futureTick')->with($listener); Loop::set($loop); Loop::futureTick($listener); } public function testStaticFutureTickWithNoDefaultLoopCallsFutureTickOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $listener = function () { }; Loop::futureTick($listener); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticAddSignalCallsAddSignalOnLoopInstance() { $signal = 1; $listener = function () { }; $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addSignal')->with($signal, $listener); Loop::set($loop); Loop::addSignal($signal, $listener); } public function testStaticAddSignalWithNoDefaultLoopCallsAddSignalOnNewLoopInstance() { if (DIRECTORY_SEPARATOR === '\\') { $this->markTestSkipped('Not supported on Windows'); } $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $signal = 1; $listener = function () { }; try { Loop::addSignal($signal, $listener); } catch (\BadMethodCallException $e) { $this->markTestSkipped('Skipped: ' . $e->getMessage()); } $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance() { $signal = 1; $listener = function () { }; $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('removeSignal')->with($signal, $listener); Loop::set($loop); Loop::removeSignal($signal, $listener); } public function testStaticRemoveSignalWithNoDefaultLoopIsNoOp() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); $signal = 1; $listener = function () { }; Loop::removeSignal($signal, $listener); $this->assertNull($ref->getValue()); } public function testStaticRunCallsRunOnLoopInstance() { $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('run')->with(); Loop::set($loop); Loop::run(); } public function testStaticRunWithNoDefaultLoopCallsRunsOnNewLoopInstance() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); Loop::run(); $this->assertInstanceOf(LoopInterface::class, $ref->getValue()); } public function testStaticStopCallsStopOnLoopInstance() { $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('stop')->with(); Loop::set($loop); Loop::stop(); } public function testStaticStopCallWithNoDefaultLoopIsNoOp() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); Loop::stop(); $this->assertNull($ref->getValue()); } /** * @after * @before */ public function unsetLoopFromLoopAccessor() { $ref = new \ReflectionProperty(Loop::class, 'instance'); if (PHP_VERSION_ID < 80100) { $ref->setAccessible(true); } $ref->setValue(null, null); } }