/** * @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); }
/** * @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); }
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); }
/** * @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); }
/** * 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; }