public function testExecuteAndConsume()
 {
     $logger = new Logger('test');
     $handler = new TestHandler();
     $logger->pushHandler($handler);
     $queueHandler = new BernardQueueHandler($this->producer);
     $workflow = WorkflowCommon::createWorkflow($logger, $queueHandler);
     $token = new Token();
     $token->setLocation('queue_test');
     $token->setData('label', 'test');
     $token->setData('array', ['a' => 'b']);
     $token->setData('object', new TestObject());
     $task = $this->getMock('Vespolina\\Workflow\\Task\\Queue', ['consume']);
     $task->expects($this->once())->method('consume')->with($token)->will($this->returnValue(true));
     $task->setWorkflow($workflow, $logger);
     $workflow->addNode($task, 'queue_test');
     $this->assertTrue($task->accept($token), 'true should be returned when the token is pushed into the queue');
     $envelope = $this->queues->create('queue_test')->dequeue();
     $message = $envelope->getMessage();
     $this->assertEquals($token, $message->getToken());
     $this->queues->create('queue_test')->enqueue($envelope);
     $receiver = new BernardReceiver($workflow);
     $this->router = new SimpleRouter(['queue_test' => $receiver]);
     $this->middleware = new MiddlewareBuilder();
     $this->consumer = new Consumer($this->router, $this->middleware);
     $this->consumer->consume($this->queues->create('queue_test'), ['max-runtime' => 1]);
 }
Exemple #2
0
 /**
  * @param  AbstractVisitor $visitor
  * @param  array           $data
  * @param  string          $type
  * @param  Context         $context
  * @return Envelope
  */
 public function deserializeToken(AbstractVisitor $visitor, array $data, $type, Context $context)
 {
     $token = new Token();
     $token->setLocation($data['location']);
     foreach ($data['data'] as $datum) {
         $type = $datum['type'];
         if ($type['name'] === 'array') {
             $argsData = [];
             foreach ($datum['args'] as $arrayData) {
                 $arrayKey = $arrayData['key'];
                 $argsData[$arrayKey] = $context->accept($arrayData['args'], $arrayData['type']);
             }
         } else {
             $argsData = $context->accept($datum['args'], $type);
         }
         $token->setData($datum['key'], $argsData);
     }
     return $token;
 }