Пример #1
0
 public function testKillTask()
 {
     $context = new Context();
     $job = new KillTask($context);
     $coroutine = $job->run();
     $task = new Task($coroutine, 8);
     $task->run();
     $result = $context->show();
     $this->assertArrayHasKey('step1', $result, 'KillTask job failed to set context');
     $this->assertArrayNotHasKey('step2', $result, 'KillTask job failed to set context');
     $this->assertEquals('before task killed', $context->get('step1'), 'KillTask job get wrong context value');
     $taskData = $task->getResult();
     $this->assertEquals('SysCall.KillTask.calling', $taskData, 'get KillTask task final output fail');
 }
Пример #2
0
 public function run($route)
 {
     $controller = $this->createController($route);
     if (!$controller instanceof Controller) {
         throw new InvalidRoute('Not found controller:' . $controller);
     }
     $action = $route['action'];
     if (!method_exists($controller, $action)) {
         throw new InvalidRoute('Class does not exist method ' . get_class($controller) . '::' . $action);
     }
     $this->doPreFilter();
     $result = $controller->{$action}();
     if ($result instanceof Generator) {
         $task = new Task($result);
         $task->run();
     }
     $this->doPostFilter();
 }
Пример #3
0
 public function testExceptionWorkFine()
 {
     $context = new Context();
     $job = new Error($context);
     $coroutine = $job->run();
     $task = new Task($coroutine);
     $task->run();
     $result = $context->show();
     $this->assertArrayHasKey('step1_response', $result, 'exception job failed to set context');
     $this->assertEquals('step1', $context->get('step1_response'), 'exception job get wrong context value');
     $this->assertArrayHasKey('exception_code', $result, 'exception job failed to set context');
     $this->assertEquals(404, $context->get('exception_code'), 'exception job get wrong context value');
     $this->assertArrayHasKey('exception_msg', $result, 'exception job failed to set context');
     $this->assertEquals('ErrorException Msg', $context->get('exception_msg'), 'exception job get wrong context value');
     $this->assertArrayHasKey('exception', $result, 'exception job failed to set context');
     $this->assertEquals('Zan\\Framework\\Test\\Foundation\\Coroutine\\Task\\ErrorException', $context->get('exception'), 'exception job get wrong context value');
     $this->assertArrayNotHasKey('work_response', $result, 'exception job failed to set context');
     $taskData = $task->getResult();
     $this->assertEquals('Error.catch.exception', $taskData, 'get exception task final output fail');
 }