Esempio n. 1
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());
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Check if the time limit has passed if one exists
  * NOTE: this method will return null if the time limit is not set
  *
  * @param  DateTime $started When the context was placed in the state
  *
  * @return State|null Time limit followup state if the limit is passed, null elsewise
  */
 public function hasTimeLimitPassed(\DateTime $started)
 {
     if ($this->hasTimeLimit()) {
         if ($this->timeLimit->isPassed($started)) {
             return $this->timeLimit->getState();
         } else {
             return null;
         }
     } else {
         return null;
         // Cant be passed a non-existent time limit
     }
 }
Esempio n. 4
0
 public function testGetStateName()
 {
     $limit = new TimeLimit(60, 'dummy');
     $this->assertEquals('dummy', $limit->getStateName());
 }