Skip to content

Commit

Permalink
feat:优化CoroutineWebServer环境未加载提示语
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 14, 2024
1 parent b83f861 commit 9e9104a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/CoroutineWebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Webman\App;
use Webman\Http\Request;
use Workbunny\WebmanCoroutine\Exceptions\WorkerException;
use Workbunny\WebmanCoroutine\Handlers\HandlerInterface;
use Workbunny\WebmanCoroutine\Utils\Coroutine\Coroutine;
use Workbunny\WebmanCoroutine\Utils\WaitGroup\WaitGroup;
Expand Down Expand Up @@ -63,6 +64,10 @@ public function onWorkerStart($worker)
parent::onWorkerStart($worker);
/** @var HandlerInterface $handler */
$handler = Factory::getCurrentHandler();
if (!$handler) {
$className = $worker::class;
throw new WorkerException("Please run Factory::init or set $className::\$EventLoopClass = event_loop(). ");
}
$handler::initEnv();
}

Expand All @@ -71,6 +76,7 @@ public function onWorkerStart($worker)
*
* - 不用返回值和参数标定是为了兼容
*
* @codeCoverageIgnore 父级没有该方法,暂时不用覆盖
* @param Worker|mixed $worker
* @return void
*/
Expand All @@ -86,6 +92,7 @@ public function onWorkerStop($worker, ...$params)
*
* - 不用返回值和参数标定是为了兼容
*
* @codeCoverageIgnore 父级没有该方法,暂时不用覆盖
* @param ConnectionInterface $connection
* @param mixed ...$params
* @return void
Expand All @@ -109,6 +116,7 @@ public function onConnect($connection, ...$params): void
*
* - 不用返回值和参数标定是为了兼容
*
* @codeCoverageIgnore 父级没有该方法,暂时不用覆盖
* @param ConnectionInterface|mixed $connection
* @param ...$params
* @return void
Expand Down
16 changes: 8 additions & 8 deletions tests/UtilsCase/Coroutine/RevoltCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function testConstruct()

// mock
$callback = null;
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -56,11 +56,11 @@ public function testDestruct()

// mock
$callback = null;
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -82,11 +82,11 @@ public function testOrigin()
};
// mock
$callback = null;
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -105,11 +105,11 @@ public function testId()
};
// mock
$callback = null;
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand Down
16 changes: 8 additions & 8 deletions tests/UtilsCase/Coroutine/RippleCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testConstruct()
// 模拟构造
$coroutine = Mockery::mock(RippleCoroutine::class)->makePartial();
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_getSuspension')
->andReturn($suspension = Mockery::mock('Revolt\EventLoop\Suspension'));
->andReturn($suspension = Mockery::mock('alias:Revolt\EventLoop\Suspension'));
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_async')
->andReturnUsing(function ($closure) use ($coroutine, &$result, &$reject) {
// 模拟发生协程执行
Expand All @@ -40,7 +40,7 @@ public function testConstruct()
$reject = $rj;
});
// 模拟返回
return Mockery::mock('Psc\Core\Coroutine\Promise');
return Mockery::mock('alias:Psc\Core\Coroutine\Promise');
});

// 模拟构造函数执行
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testDestruct()
// 模拟构造
$coroutine = Mockery::mock(RippleCoroutine::class)->makePartial();
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_getSuspension')
->andReturn($suspension = Mockery::mock('Revolt\EventLoop\Suspension'));
->andReturn($suspension = Mockery::mock('alias:Revolt\EventLoop\Suspension'));
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_async')
->andReturnUsing(function ($closure) use ($coroutine, &$result, &$reject) {
// 模拟发生协程执行
Expand All @@ -97,7 +97,7 @@ public function testDestruct()
$reject = $rj;
});
// 模拟返回
return Mockery::mock('Psc\Core\Coroutine\Promise');
return Mockery::mock('alias:Psc\Core\Coroutine\Promise');
});

// 模拟构造函数执行
Expand All @@ -120,7 +120,7 @@ public function testOrigin()
// 模拟构造
$coroutine = Mockery::mock(RippleCoroutine::class)->makePartial();
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_getSuspension')
->andReturn($suspension = Mockery::mock('Revolt\EventLoop\Suspension'));
->andReturn($suspension = Mockery::mock('alias:Revolt\EventLoop\Suspension'));
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_async')
->andReturnUsing(function ($closure) use ($coroutine, &$result, &$reject) {
// 模拟发生协程执行
Expand All @@ -130,7 +130,7 @@ public function testOrigin()
$reject = $rj;
});
// 模拟返回
return Mockery::mock('Psc\Core\Coroutine\Promise');
return Mockery::mock('alias:Psc\Core\Coroutine\Promise');
});

// 模拟构造函数执行
Expand All @@ -148,7 +148,7 @@ public function testId()
// 模拟构造
$coroutine = Mockery::mock(RippleCoroutine::class)->makePartial();
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_getSuspension')
->andReturn($suspension = Mockery::mock('Revolt\EventLoop\Suspension'));
->andReturn($suspension = Mockery::mock('alias:Revolt\EventLoop\Suspension'));
$coroutine->shouldAllowMockingProtectedMethods()->shouldReceive('_async')
->andReturnUsing(function ($closure) use ($coroutine, &$result, &$reject) {
// 模拟发生协程执行
Expand All @@ -158,7 +158,7 @@ public function testId()
$reject = $rj;
});
// 模拟返回
return Mockery::mock('Psc\Core\Coroutine\Promise');
return Mockery::mock('alias:Psc\Core\Coroutine\Promise');
});

// 模拟构造函数执行
Expand Down

0 comments on commit 9e9104a

Please sign in to comment.