Altax\Module\Task\Resource\DefinedTask::setClosure PHP Method

setClosure() public method

public setClosure ( $closure )
    public function setClosure($closure)
    {
        if (!$closure instanceof \Closure) {
            throw new \RuntimeException("Passed not a closure");
        }
        $this->closure = $closure;
        return $this;
    }

Usage Example

 public function testDefault()
 {
     $container = new Container();
     $task = new DefinedTask();
     $task->setName("test");
     $task->setDescription("Description of the test task");
     $task->setClosure(function ($task) {
         $task->getOutput()->write("test message for closure task command");
     });
     $application = new Application($container);
     $application->setAutoExit(false);
     $application->add(new ClosureTaskCommand($task));
     $command = $application->find("test");
     $commandTester = new CommandTester($command);
     $commandTester->execute(array("command" => $command->getName()));
     $this->assertEquals("test message for closure task command", $commandTester->getDisplay());
 }