Exemplo n.º 1
0
 /**
  * @covers ::closureToString
  */
 public function testClosureToString()
 {
     $closure = function ($args) {
         return $args . 'bar';
     };
     $serialized = $this->helper->closureToString($closure);
     /** @var \Closure $actual */
     $actual = @unserialize($serialized);
     $actual = $actual('foo');
     $expected = $closure('foo');
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 2
0
 /**
  * @param array $config
  * @return array
  */
 private function getJobConfig(array $config)
 {
     $helper = new Helper();
     if ($config['command'] instanceof \Closure) {
         $config['command'] = $helper->closureToString($config['command']);
     }
     return array_merge(array("enabled" => 1, "haltDir" => null, "runOnHost" => $helper->getHost(), "dateFormat" => "Y-m-d H:i:s", "schedule" => "* * * * *", "output" => $this->logFile, "maxRuntime" => null), $config);
 }
Exemplo n.º 3
0
 public function testProcessClosure()
 {
     $command = 'ClosureExample';
     $config = array('command' => function () {
         echo "I'm a function!\n";
         return true;
     }, 'schedule' => '0 * * * *', 'output' => 'logs/closure.log', 'enabled' => true);
     $helper = new Helper();
     $config['command'] = $helper->closureToString($config['command']);
     $message = $this->prepareMessage();
     $message->body = serialize(array('cmd' => $command, 'config' => $config));
     $worker = new Job('localhost');
     $worker->setJobFactory($this->prepareJobFactory($command, $config));
     $worker->process($message);
 }
Exemplo n.º 4
0
 /**
  * @param array $config
  *
  * @return array
  */
 private function getJobConfig(array $config)
 {
     $helper = new Helper();
     if ($config['command'] instanceof \Closure) {
         $config['command'] = $helper->closureToString($config['command']);
     }
     return array_merge(['enabled' => 1, 'haltDir' => null, 'runOnHost' => $helper->getHost(), 'dateFormat' => 'Y-m-d H:i:s', 'schedule' => '* * * * *', 'output' => $this->logFile, 'maxRuntime' => null, 'runAs' => null], $config);
 }
Exemplo n.º 5
0
 /**
  * Serialize command if necessary (e.g. anonymous function).
  *
  * @param $config
  * @return array
  */
 protected function prepare(array $config)
 {
     if ($config['command'] instanceof \Closure) {
         $helper = new Helper();
         $config['command'] = $helper->closureToString($config['command']);
     }
     return $config;
 }