public function testGetSetWorkflowName() { $instance = new WorkflowInstanceEntity(); $this->assertNull($instance->getWorkflowName()); $instance->setWorkflowName('testtesttest'); $this->assertEquals('testtesttest', $instance->getWorkflowName()); }
/** * @depends testGetWorkflowInstanceForWorkflow */ public function testHasWorkflowInstanceForWorkflow() { $context = $this->getMockForTrait('\\TyHand\\WorkflowBundle\\Workflow\\Context\\ContextTrait'); $workflowInstance = new WorkflowInstanceEntity(); $workflowInstance->setWorkflowName('test1'); $context->addWorkflowInstance($workflowInstance); $workflowInstance2 = new WorkflowInstanceEntity(); $workflowInstance2->setWorkflowName('test2'); $workflowInstance2->setIsComplete(true); $context->addWorkflowInstance($workflowInstance2); $this->assertTrue($context->hasWorkflowInstancesForWorkflow('test1')); $this->assertTrue($context->hasWorkflowInstancesForWorkflow('test2')); $this->assertTrue($context->hasWorkflowInstancesForWorkflow('test1', true)); $this->assertFalse($context->hasWorkflowInstancesForWorkflow('test2', true)); $this->assertFalse($context->hasWorkflowInstancesForWorkflow('test5')); $this->assertFalse($context->hasWorkflowInstancesForWorkflow('test5', true)); }
/** * Put a context into the workflow * * @return WorkflowInstanceEntity New instance entity */ public function start(ContextInterface $context) { // Check that the context can be placed into the workflow if (!$this->checkType($context)) { throw new ContextNotAcceptedByWorkflowException(get_class($context), $this->contextClass); } // Check that the context is within the limits of the workflow if ($context->hasWorkflowInstancesForWorkflow($this->getName())) { if (null !== $this->activeInstanceLimit) { if ($this->activeInstanceLimit <= count($context->getWorkflowInstancesForWorkflow($this->getName(), true))) { throw new ContextOverWorkflowLimitException($this->activeInstanceLimit, ContextOverWorkflowLimitException::ACTIVE_LIMIT); } } if (null !== $this->totalInstanceLimit) { if ($this->totalInstanceLimit <= count($context->getWorkflowInstancesForWorkflow($this->getName(), false))) { throw new ContextOverWorkflowLimitException($this->totalInstanceLimit, ContextOverWorkflowLimitException::TOTAL_LIMIT); } } } // Create the new workflow instance entity and move to the initial state $instanceEntity = new WorkflowInstanceEntity(); $instanceEntity->setWorkflowName($this->getName()); // Add the instance entity to the context $context->addWorkflowInstance($instanceEntity); // Move to the first state return $this->getInitialState()->moveTo($context, $instanceEntity); }