/** * @param $type */ private function createPropheciesForTaskRunnerRun($type) { $prophet = $this; $queueRunMethodProphecy = $this->queueProphecy->run($type, Argument::type('callable'))->will(function ($parameters) use($prophet) { $inputMessage = new InputMessage('input' . mt_rand(0, 65535)); $taskClass = 'Task' . mt_rand(0, 65535); $taskInput = new TaskInput([mt_rand(0, 65535)]); $prophet->taskInputMessageTransformerProphecy->getTaskClassFromMessage($inputMessage)->willReturn($taskClass); $prophet->taskInputMessageTransformerProphecy->getTaskInputFromMessage($inputMessage)->willReturn($taskInput); $prophet->taskFactoryProphecy->createTask($taskClass)->will(function () use($taskInput, &$outputMessage, $prophet) { $taskProphecy = $prophet->prophesize(Task::class); $taskRunMethodProphecy = $taskProphecy->run($taskInput)->will(function () use(&$outputMessage, $prophet) { $result = mt_rand(0, 65535); $outputMessage = new OutputMessage('output' . mt_rand(0, 65535)); $prophet->taskResultMessageTransformerProphecy->getOutputMessageFromResult(TaskResult::fromReturn($result))->willReturn($outputMessage); return $result; }); $taskRunMethodProphecy->shouldBeCalledTimes(1); return $taskProphecy->reveal(); }); $callable = $parameters[1]; $outputMessageResult = $callable($inputMessage); $prophet->assertEquals($outputMessage, $outputMessageResult); }); return $queueRunMethodProphecy; }
public function getTaskResultFromMessage(OutputMessage $message) { $data = $message->getData(); $type = substr($data, 0, 1); $serializedData = substr($data, 1); if ($type === 'r') { $return = unserialize($serializedData); $taskResult = TaskResult::fromReturn($return); } elseif ($type === 'e') { list($class, $message, $code, $file, $line, ) = unserialize($serializedData); $exception = $this->createResultException($class); $this->setResultExceptionInternalData($exception, $class, $message, $code, $file, $line); $taskResult = TaskResult::fromException($exception); } else { $taskResult = TaskResult::fromReturn(null); } return $taskResult; }
public function testExceptionSerialization() { $sut = new TaskMessageSerializeTransformer(); $message = 'test message'; $code = 123; $exception = new TestException($message, $code); $taskResult = TaskResult::fromException($exception); $message = $sut->getOutputMessageFromResult($taskResult); $taskResult2 = $sut->getTaskResultFromMessage($message); try { $taskResult2->getResult(); $this->fail('No exception was thrown'); } catch (TestException $exception2) { } $this->assertEquals($exception->getMessage(), $exception2->getMessage()); $this->assertEquals($exception->getCode(), $exception2->getCode()); $this->assertEquals($exception->getFile(), $exception2->getFile()); $this->assertEquals($exception->getLine(), $exception2->getLine()); $this->assertCount(1, $exception2->getTrace()); }