Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed T'es qu'un con

  • Loading branch information...
commit 929f4cf17f648dfe428394f7cdf6b2eb5369491c 1 parent 755f006
@jeremyFreeAgent authored
Showing with 34 additions and 18 deletions.
  1. +10 −10 Manager/Manager.php
  2. +7 −7 Step/Step.php
  3. +17 −1 Tests/Manager/ManagerTest.php
View
20 Manager/Manager.php
@@ -34,7 +34,7 @@ public function __construct(Container $container)
*/
public function getDefaultStepName()
{
- return $this->defaultStep;
+ return $this->defaultStep->getName();
}
/**
@@ -58,7 +58,7 @@ public function configureWorkflow($workflowName)
}
foreach ($this->workflow['steps'] as $stepName => $stepConfiguration) {
- $this->steps->add($stepName, new Step($stepName, $stepConfiguration));
+ $this->steps->offsetSet($stepName, new Step($stepName, $stepConfiguration));
}
$this->defaultStep = new Step($defaultStep, $this->workflow['steps'][$defaultStep]);
@@ -168,23 +168,23 @@ public function canReachStep($stepName)
$this->validationErrors[$stepName] = array();
if ($stepName != $this->getCurrentStepName()) {
- $step = $this->getStep($stepName);
+ $stepToReach = $this->getStep($stepName);
$currentStep = $this->getCurrentStep();
- if ($step->hasPossibleNextStep($stepName)) {
+ if ($currentStep->hasPossibleNextStep($stepToReach->getName())) {
- if (!$step->hasValidations()) {
- $this->canReachStep[$stepName] = true;
+ if (!$stepToReach->hasValidations()) {
+ $this->canReachStep[$stepToReach->getName()] = true;
} else {
- foreach ($step->getValidations() as $validation) {
+ foreach ($stepToReach->getValidations() as $validation) {
$validation = $this->getValidation($validation);
try {
$validation->validate($this->getModel());
- $this->canReachStep[$stepName] = true;
+ $this->canReachStep[$stepToReach->getName()] = true;
} catch (\Exception $e) {
- $this->validationErrors[$stepName][] = $e->getMessage();
- $this->canReachStep[$stepName] = false;
+ $this->validationErrors[$stepToReach->getName()][] = $e->getMessage();
+ $this->canReachStep[$stepToReach->getName()] = false;
}
}
}
View
14 Step/Step.php
@@ -12,12 +12,12 @@ class Step
public function __construct($name, $configuration = array())
{
$this->name = $name;
- $this->actions = array_key_exists('actions', $configuration) ? $configuration['actions'] = array();
- $this->validations = array_key_exists('validations', $configuration) ? $configuration['validations'] = array();
- $this->possible_next_steps = array_key_exists('possible_next_steps', $configuration) ? $configuration['possible_next_steps'] = array();
+ $this->actions = array_key_exists('actions', $configuration) ? $configuration['actions'] : array();
+ $this->validations = array_key_exists('validations', $configuration) ? $configuration['validations'] : array();
+ $this->possible_next_steps = array_key_exists('possible_next_steps', $configuration) ? $configuration['possible_next_steps'] : array();
}
- public function getName($name)
+ public function getName()
{
return $this->name;
}
@@ -39,16 +39,16 @@ public function getPossibleNextSteps()
public function hasValidations()
{
- return !empty($this->getValidations());
+ return !empty($this->validations);
}
public function hasActions()
{
- return !empty($this->getActions());
+ return !empty($this->actions);
}
public function hasPossibleNextStep($stepName)
{
- return array_key_exists($stepName, $this->getPossibleNextSteps());
+ return in_array($stepName, $this->getPossibleNextSteps());
}
}
View
18 Tests/Manager/ManagerTest.php
@@ -7,6 +7,7 @@
use FreeAgent\WorkflowBundle\Model\ModelInterface;
use FreeAgent\WorkflowBundle\Action\ActionInterface;
use FreeAgent\WorkflowBundle\Validation\ValidationInterface;
+use FreeAgent\WorkflowBundle\Step\Step;
/**
* ModelExample
@@ -82,6 +83,8 @@ class ManagerForTest extends Manager
{
public function configureWorkflow($workflowName)
{
+ $this->workflowName = $workflowName;
+
$this->workflow = array(
'default_step' => 'draft',
'steps' => array(
@@ -159,7 +162,20 @@ public function configureWorkflow($workflowName)
),
);
- return $this->getWorkflow();
+ $defaultStep = $this->workflow['default_step'];
+ if (!array_key_exists($defaultStep, $this->workflow['steps'])) {
+ throw new \Exception('The default step of "'.$this->workflowName.'" does not exist');
+ }
+
+ foreach ($this->workflow['steps'] as $stepName => $stepConfiguration) {
+ $this->steps->offsetSet($stepName, new Step($stepName, $stepConfiguration));
+ }
+
+ $this->defaultStep = new Step($defaultStep, $this->workflow['steps'][$defaultStep]);
+
+ return $this->getSteps();
+
+ return $this->getSteps();
}
public function getValidation($validation)
Please sign in to comment.
Something went wrong with that request. Please try again.