/** * @return \Ackintosh\Snidel\Result\Result */ protected function makeResult() { $result = new Result(); $result->setFork($this->makeFork()); $result->setTask($this->makeTask()); return $result; }
/** * @test */ public function setError() { $result = new Result(); $error = array('foo' => 'bar'); $result->setError($error); $this->assertTrue($result->isFailure()); $this->assertSame($error, $result->getError()); }
/** * @test */ public function minifyAndSerialize() { $result = new Result(); $result->setTask(new Task(function () { return 'foo'; }, null, null)); $minified = Formatter::minifyAndSerialize($result); $this->assertTrue(is_string($minified)); }
/** * @test * @expectedException \RuntimeException */ public function dequeueThrowsException() { $result = new Result(); $result->setFork(new Fork(getmypid())); $result->setTask(new Task('receivesArgumentsAndReturnsIt', 'foo', null)); $this->queue->enqueue($result); require_once __DIR__ . '/../../msg_receive.php'; $this->queue->dequeue(); }
/** * @return void * @throws \RuntimeException */ public function error() { $result = new Result(); $result->setError(error_get_last()); $result->setTask($this->task); $result->setFork($this->fork); try { $this->resultQueue->enqueue($result); } catch (\RuntimeException $e) { throw $e; } }
/** * @test */ public function implementsIteratorInterface() { $resultA = new Result(); $resultA->setFork(new Fork($dummyPid = 100, new Task('receivesArgumentsAndReturnsIt', 'foo', null))); $resultB = new Result(); $resultB->setFork(new Fork($dummyPid = 200, new Task('receivesArgumentsAndReturnsIt', 'foo', null))); $results = array($resultA, $resultB); $collection = new Collection($results); foreach ($collection as $position => $result) { $this->assertSame(($position + 1) * 100, $result->getFork()->getPid()); } }
/** * @return Ackintosh\Snidel\Result\Result */ public function execute() { ob_start(); $result = new Result(); try { $result->setReturn(call_user_func_array($this->getCallable(), is_array($args = $this->getArgs()) ? $args : array($args))); } catch (\RuntimeException $e) { ob_get_clean(); throw $e; } $result->setOutput(ob_get_clean()); $result->setTask($this); return $result; }