示例#1
0
 public function testParseAndRunCommand()
 {
     $result = TaskRunner::parseAndRunCommand('mult1mate\\crontab_tests\\ActionMock::returnResult()');
     $this->assertTrue($result);
     $result = TaskRunner::parseAndRunCommand('mult1mate\\crontab_tests\\ActionMock::wrongMethod()');
     $this->assertFalse($result);
     TaskLoader::setClassFolder(__DIR__ . '/runner_mocks');
     $result = TaskRunner::parseAndRunCommand('RunnerMock::anyMethod()');
     $this->assertFalse($result);
 }
 public function taskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::find($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     if (!empty($_POST)) {
         $task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
     }
     $this->renderView('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder)));
 }
示例#3
0
 /**
  * Parses given command, creates new class object and calls its method via call_user_func_array
  * @param string $command
  * @return mixed
  */
 public static function parseAndRunCommand($command)
 {
     try {
         list($class, $method, $args) = TaskManager::parseCommand($command);
         if (!class_exists($class)) {
             TaskLoader::loadController($class);
         }
         $obj = new $class();
         if (!method_exists($obj, $method)) {
             throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
         }
         return call_user_func_array(array($obj, $method), $args);
     } catch (\Exception $e) {
         echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
         return false;
     }
 }
 public function taskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findByPk($_GET['task_id']);
     } else {
         $task = Task::createNew();
     }
     /**
      * @var Task $task
      */
     if (!empty($_POST)) {
         $task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
     }
     $this->load->view('tasks/task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods($this->controller_folder)));
 }
 public function actionTaskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findOne($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     $post = \Yii::$app->request->post();
     if ($task->load($post) && $task->validate()) {
         $task = TaskManager::editTask($task, $post['Task']['time'], $post['Task']['command'], $post['Task']['status'], $post['Task']['comment']);
         \Yii::$app->response->redirect('/?r=tasks/task-edit&task_id=' . $task->task_id);
     }
     return $this->render('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder, self::$tasks_namespace)));
 }
示例#6
0
 public function testLoadControllerExceptions()
 {
     $this->setExpectedException('mult1mate\\crontab\\TaskManagerException');
     TaskLoader::setClassFolder(__DIR__);
     TaskLoader::loadController('MockClass');
 }