/** * Finalize the workflow * * @return Workflow Constructed workflow */ public function build() { // Build the workflow $workflow = new Workflow($this->workflowName, $this->contextClass); // Set the limits if they exist if ($this->activeLimit !== null) { $workflow->setActiveInstanceLimit($this->activeLimit); } if ($this->totalLimit !== null) { $workflow->setTotalInstanceLimit($this->totalLimit); } // Construct the map of states $stateMap = array(); foreach ($this->stateBuilders as $stateName => $stateBuilder) { $stateMap[$stateName] = $stateBuilder->getUnbuiltState(); } // Build each state foreach ($this->stateBuilders as $stateBuilder) { $workflow->addState($stateBuilder->build($stateMap)); } // Set the Initial state if (!array_key_exists($this->initialStateName, $stateMap)) { throw new StateNotFoundException($this->initialStateName, array_keys($stateMap)); } $workflow->setInitialState($stateMap[$this->initialStateName]); // Return the completed workflow return $workflow; }
/** * @expectedException \TyHand\WorkflowBundle\Exceptions\ContextOverWorkflowLimitException * @expectedExceptionMessage This workflow only allows a context to have 2 total instances */ public function testStartContextOverTotalWorkflowLimitException() { $dummy = new DummyContext(); $workflow = new Workflow('test', 'TyHand\\WorkflowBundle\\Tests\\DummyContext'); $stateA = new State('A'); $workflow->addState($stateA); $workflow->setInitialState($stateA); $workflow->setTotalInstanceLimit(2); $instance = $workflow->start($dummy); $instance2 = $workflow->start($dummy); $this->assertTrue(true); // Checkpoint check $instance3 = $workflow->start($dummy); }