Example #1
0
 /**
  * Build the state
  *
  * @param array Map of states keyed by name for the workflow
  *
  * @return State Newly minted state
  */
 public function build(array $stateMap)
 {
     // Build each condition trigger
     foreach ($this->conditionBuilders as $conditionBuilder) {
         $this->state->addCondition($conditionBuilder->build($stateMap));
     }
     // Build each event trigger
     foreach ($this->eventTriggers as $eventTrigger) {
         if (array_key_exists($eventTrigger->getStateName(), $stateMap)) {
             $eventTrigger->setState($stateMap[$eventTrigger->getStateName()]);
             $this->state->addEventTrigger($eventTrigger);
         } else {
             throw new StateNotFoundException($eventTrigger->getStateName(), array_keys($stateMap));
         }
     }
     // Build each time limit trigger
     if (null !== $this->timeLimit) {
         if (array_key_exists($this->timeLimit->getStateName(), $stateMap)) {
             $this->timeLimit->setState($stateMap[$this->timeLimit->getStateName()]);
             $this->state->setTimeLimit($this->timeLimit);
         } else {
             throw new StateNotFoundException($this->timeLimit->getStateName(), array_keys($stateMap));
         }
     }
     // Return the complete state
     return $this->state;
 }
Example #2
0
 public function testGetSetState()
 {
     $limit = new TimeLimit(60, 'dummy');
     $limit->setState(new State('dummy'));
     $this->assertInstanceOf('\\TyHand\\WorkflowBundle\\Workflow\\State', $limit->getState());
     $this->assertEquals('dummy', $limit->getState()->getName());
 }
Example #3
0
 /**
  * @depends testSetHasTimeLimit
  */
 public function testHasTimeLimitPassed()
 {
     $state = new State('limited');
     $limit = new TimeLimit(60, 'outoftime');
     $limit->setState(new State('outoftime'));
     $time = new \DateTime();
     $this->assertNull($state->hasTimeLimitPassed($time));
     $state->setTimeLimit($limit);
     $this->assertNull($state->hasTimeLimitPassed($time));
     $time->modify('-1 hour');
     $this->assertInstanceOf('\\TyHand\\WorkflowBundle\\Workflow\\State', $state->hasTimeLimitPassed($time));
     $this->assertEquals('outoftime', $state->hasTimeLimitPassed($time)->getName());
 }