Esempio n. 1
0
 public function testAddOutput()
 {
     $tokenable = $this->getMockForAbstractClass('Vespolina\\Workflow\\Node');
     $arc = WorkflowCommon::createArc();
     $tokenable->addOutput($arc);
     $this->assertContains($arc, $tokenable->getOutputs());
 }
Esempio n. 2
0
 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]);
 }
Esempio n. 3
0
 /**
  *  O -> [A] -> O -> [B] -> O
  * in          p1          out
  */
 public function testSequentialPattern()
 {
     $handler = new TestHandler();
     $logger = new Logger('test', array($handler));
     $workflow = WorkflowCommon::createWorkflow($logger);
     // create sequence
     $a = new AutoA();
     $workflow->addNode($a, 'a');
     $place = WorkflowCommon::createPlace();
     $workflow->addNode($place, 'p1');
     $b = new AutoB();
     $workflow->addNode($b, 'b');
     $workflow->connectToStart('a');
     $workflow->connect('a', 'p1');
     $workflow->connect('p1', 'b');
     $workflow->connectToFinish('b');
     $token = WorkflowCommon::createToken();
     $workflow->accept($token);
     $expected = array('Token accepted into workflow', 'Token advanced into workflow.start', 'Token advanced into a', 'Token advanced into p1', 'Token advanced into b', 'Token advanced into workflow.finish');
     foreach ($expected as $logEntry) {
         $this->assertTrue($handler->hasInfo($logEntry), "failed log entry {$logEntry}");
     }
 }
Esempio n. 4
0
 public function setUp()
 {
     $this->token = WorkflowCommon::createToken();
 }
Esempio n. 5
0
 public function testValidateWorkflowSimple()
 {
     $this->markTestSkipped('validation needs to be looked at');
     $logger = new Logger('test');
     $handler = new TestHandler();
     $logger->pushHandler($handler);
     $workflow = WorkflowCommon::createWorkflow($logger);
     $transaction = WorkflowCommon::createTransaction();
     $transaction->setName('transaction');
     $a1 = WorkflowCommon::createArc();
     $a1->setName('a1');
     $a1->setFrom($workflow->getStart());
     $a1->setTo($transaction);
     $a2 = WorkflowCommon::createArc();
     $a2->setName('a2');
     $a2->setFrom($transaction);
     $a2->setTo($workflow->getFinish());
     $this->assertTrue($workflow->validateWorkflow());
     $expected = array('Node workflow.start reached, step 1', 'Traversing arc a1, step 2', 'Node transaction reached, step 3', 'Traversing arc a2, step 4', 'Node workflow.finish reached, step 5');
     foreach ($expected as $logEntry) {
         $this->assertTrue($handler->hasInfo($logEntry));
     }
 }