diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 2a42230..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Bug Report -about: Create a report to help us improve -title: "[BUG] " -labels: bug -assignees: '' ---- - -### 问题描述 -清楚简洁地描述问题是什么。 - -### 环境信息 - -- PHP 版本: [例如 7.4.3] -- 操作系统: [例如 Windows, macOS] -- workerman 版本: [例如 4.0.39] -- webman-coroutine 版本: [例如 1.0.0] -- 协程环境下的驱动: [例如 swoole, swow等] - -### 错误信息 - -粘贴错误信息。 - -### 截图 [可选] - -如果适用,添加问题相关的截图。 - diff --git a/tests/HandlersCase/RevoltHandlerTest.php b/tests/HandlersCase/RevoltHandlerTest.php index 0fd700d..675decf 100644 --- a/tests/HandlersCase/RevoltHandlerTest.php +++ b/tests/HandlersCase/RevoltHandlerTest.php @@ -27,19 +27,33 @@ public function testInitEnv() $this->assertTrue(true); } + /** + * @runInSeparateProcess + * @return void + */ public function testWaitFor() { - $rippleHandlerMock = Mockery::mock(RevoltHandler::class . '[sleep]'); - $rippleHandlerMock->shouldReceive('sleep')->andReturnNull(); + $suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension'); + $suspensionMock->shouldReceive('resume')->andReturnNull(); + $suspensionMock->shouldReceive('suspend')->andReturnNull(); + + $eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop'); + $eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock); + $eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) { + $closure(); + }); + $eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) { + $closure(); + }); $return = false; - $rippleHandlerMock::waitFor(function () use (&$return) { + RevoltHandler::waitFor(function () use (&$return) { return $return = true; }); $this->assertTrue($return); $return = false; - $rippleHandlerMock::waitFor(function () use (&$return) { + RevoltHandler::waitFor(function () use (&$return) { sleep(1); return $return = true; @@ -47,7 +61,7 @@ public function testWaitFor() $this->assertTrue($return); $return = false; - $rippleHandlerMock::waitFor(function () use (&$return) { + RevoltHandler::waitFor(function () use (&$return) { return false; }, 1); $this->assertFalse($return); diff --git a/tests/UtilsCase/Channel/RevoltChannelTest.php b/tests/UtilsCase/Channel/RevoltChannelTest.php index 69c2e20..63c9fea 100644 --- a/tests/UtilsCase/Channel/RevoltChannelTest.php +++ b/tests/UtilsCase/Channel/RevoltChannelTest.php @@ -8,9 +8,6 @@ use PHPUnit\Framework\TestCase; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\RevoltChannel; -/** - * @runTestsInSeparateProcesses - */ class RevoltChannelTest extends TestCase { protected function tearDown(): void @@ -62,8 +59,18 @@ public function testClose() public function testPushWithTimeout() { - Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler') - ->shouldReceive('sleep')->andReturnNull(); + $suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension'); + $suspensionMock->shouldReceive('resume')->andReturnNull(); + $suspensionMock->shouldReceive('suspend')->andReturnNull(); + + $eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop'); + $eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock); + $eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) { + $closure(); + }); + $eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) { + $closure(); + }); $channel = new RevoltChannel(1); $channel->push('test'); @@ -72,8 +79,18 @@ public function testPushWithTimeout() public function testPopWithTimeout() { - Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler') - ->shouldReceive('sleep')->andReturnNull(); + $suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension'); + $suspensionMock->shouldReceive('resume')->andReturnNull(); + $suspensionMock->shouldReceive('suspend')->andReturnNull(); + + $eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop'); + $eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock); + $eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) { + $closure(); + }); + $eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) { + $closure(); + }); $channel = new RevoltChannel(1); $this->assertFalse($channel->pop(1)); diff --git a/tests/UtilsCase/Coroutine/RevoltCoroutineTest.php b/tests/UtilsCase/Coroutine/RevoltCoroutineTest.php index ea247e1..75b345f 100644 --- a/tests/UtilsCase/Coroutine/RevoltCoroutineTest.php +++ b/tests/UtilsCase/Coroutine/RevoltCoroutineTest.php @@ -8,9 +8,6 @@ use PHPUnit\Framework\TestCase; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\RevoltCoroutine; -/** - * @runTestsInSeparateProcesses - */ class RevoltCoroutineTest extends TestCase { protected function tearDown(): void diff --git a/tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php b/tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php index bc9683e..d483b8d 100644 --- a/tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php +++ b/tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php @@ -8,9 +8,6 @@ use PHPUnit\Framework\TestCase; use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\RevoltWaitGroup; -/** - * @runTestsInSeparateProcesses - */ class RevoltWaitGroupTest extends TestCase { protected function tearDown(): void @@ -43,8 +40,18 @@ public function testCount() public function testWait() { - Mockery::mock('Workbunny\WebmanCoroutine\Handlers\RevoltHandler') - ->shouldReceive('sleep')->andReturnNull(); + $suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension'); + $suspensionMock->shouldReceive('resume')->andReturnNull(); + $suspensionMock->shouldReceive('suspend')->andReturnNull(); + + $eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop'); + $eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock); + $eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) { + $closure(); + }); + $eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) { + $closure(); + }); $wg = new RevoltWaitGroup(); $wg->add(); $wg->done();