Example #1
0
 public function testProcessExceptionHandling()
 {
     $handler = new TestHandler();
     $logger = new Logger('test', array($handler));
     $workflow = WorkflowCommon::createWorkflow($logger);
     $token = WorkflowCommon::createToken();
     $tokenable = $this->getMock('Vespolina\\Workflow\\Node', array('preExecute'));
     $tokenable->setWorkflow($workflow, $logger);
     $tokenable->expects($this->once())->method('preExecute')->will($this->throwException(new ProcessingFailureException('testing')));
     $this->assertFalse($tokenable->accept($token), 'a failure should return false');
     $this->assertContains('testing', $workflow->getErrors(), 'the error message from the failure should be in workflow');
 }
Example #2
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}");
     }
 }
Example #3
0
 public function setUp()
 {
     $this->token = WorkflowCommon::createToken();
 }
Example #4
0
 public function testFinalizeMultipleArcs()
 {
     $handler = new TestHandler();
     $logger = new Logger('test', array($handler));
     $workflow = WorkflowCommon::createWorkflow($logger);
     $transaction = new ExtendedTransaction();
     $workflow->addNode($transaction, 'transaction');
     $place1 = WorkflowCommon::createPlace();
     $workflow->addNode($place1, 'place1');
     $place2 = WorkflowCommon::createPlace();
     $workflow->addNode($place2, 'place2');
     $workflow->connect('transaction', 'place1');
     $workflow->connect('transaction', 'place2');
     $token = WorkflowCommon::createToken();
     $transaction->addToken($token);
     $workflow->addToken($token);
     $this->assertTrue($workflow->finalize($transaction, $token));
     $outputTokens = array_merge($place1->getTokens(), $place2->getTokens());
     foreach ($outputTokens as $curToken) {
         $this->assertNotSame($token, $curToken, 'the token should be a clone');
     }
     $this->assertNotContains($token, $transaction->getTokens(), 'the token should not longer be in tokenable');
     $this->assertCount(2, $workflow->getTokens());
     foreach ($workflow->getTokens() as $workflowToken) {
         $this->assertNotSame($token, $workflowToken, 'the tokens should be clones');
         $this->assertContains($workflowToken, $outputTokens, 'the workflow tokens should also be the same token in the arc "to"');
     }
 }