Skip to content

Commit

Permalink
Remove transit and start method from Transition.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Dec 18, 2014
1 parent abcded5 commit b75ce73
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ function let(
$workflow->getTransition(static::TRANSITION_NAME)->willReturn($transition);

$transition->getName()->willReturn(static::TRANSITION_NAME);
$transition->isInputRequired()->willReturn(false);
$transition->transit(
$item,
$transition->isInputRequired($item)->willReturn(false);
$item->transit(
$transition,
Argument::type(static::CONTEXT_CLASS),
Argument::type(static::ERROR_COLLECTION_CLASS)
Argument::type(static::ERROR_COLLECTION_CLASS),
true
)->willReturn($state);

$item->isWorkflowStarted()->willReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ function let(

$transition->getName()->willReturn(static::TRANSITION_NAME);
$transition->isInputRequired($item)->willReturn(false);
$transition->transit(
$item,

$item->transit(
$transition,
Argument::type(static::CONTEXT_CLASS),
Argument::type(static::ERROR_COLLECTION_CLASS)
)->willReturn($state);
)
->willReturn($state);

$item->isWorkflowStarted()->willReturn(true);
$item->getCurrentStepName()->willReturn(static::STEP_NAME);
Expand Down Expand Up @@ -270,13 +272,26 @@ function it_throws_during_transits_if_not_validated(Workflow $workflow, Transiti
}

function it_transits_to_next_state(
Form $form, Transition $transition, Item $item, Listener $listener
Form $form, Transition $transition, Item $item, Listener $listener, State $state
) {
$listener->onBuildForm(Argument::cetera())->shouldBeCalled();
$listener->onValidate(Argument::cetera())->willReturn(true);
$listener->onPreTransit(Argument::cetera())->shouldBeCalled();
$listener->onPostTransit(Argument::cetera())->shouldBeCalled();

$item->transit(
$transition,
Argument::type(static::CONTEXT_CLASS),
Argument::type(static::ERROR_COLLECTION_CLASS),
true
)->shouldBeCalled()->willReturn($state);

$transition->executeActions(
$item,
Argument::type(static::CONTEXT_CLASS),
Argument::type(static::ERROR_COLLECTION_CLASS)
)->willReturn(true)->shouldBeCalled();

$transition->buildForm($form, $item)->shouldBeCalled();
$transition->checkPreCondition(
$item,
Expand Down
42 changes: 1 addition & 41 deletions src/Netzmacht/Workflow/Flow/Transition.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,46 +271,6 @@ public function isAvailable(Item $item, Context $context, ErrorCollection $error
return $this->isAllowed($item, $context, $errorCollection);
}

/**
* Start a transition.
*
* @param Item $item The Item.
* @param Context $context The transition context.
* @param ErrorCollection $errorCollection The error collection.
*
* @return State
*/
public function start(Item $item, Context $context, ErrorCollection $errorCollection)
{
if ($item->isWorkflowStarted()) {
return $item->getLatestState();
}

$success = $this->executeActions($item, $context, $errorCollection);
$state = $item->start($this, $context, $errorCollection, $success);

return $state;
}

/**
* Transit an Item using this transition.
*
* @param Item $item The Item.
* @param Context $context The transition context.
* @param ErrorCollection $errorCollection The error collection.
*
* @throws WorkflowException If process was not started yet.
*
* @return State
*/
public function transit(Item $item, Context $context, ErrorCollection $errorCollection)
{
$success = $this->executeActions($item, $context, $errorCollection);
$state = $item->transit($this, $context, $errorCollection, $success);

return $state;
}

/**
* Check the precondition.
*
Expand Down Expand Up @@ -388,7 +348,7 @@ public function getPermission()
*
* @return bool
*/
private function executeActions(Item $item, Context $context, ErrorCollection $errorCollection)
public function executeActions(Item $item, Context $context, ErrorCollection $errorCollection)
{
$success = $this->isAllowed($item, $context, $errorCollection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,13 @@ public function transit()
private function executeTransition()
{
$transition = $this->getTransition();
$success = $transition->executeActions($this->item, $this->context, $this->errorCollection);

if ($this->isWorkflowStarted()) {
return $transition->transit($this->item, $this->context, $this->errorCollection);
return $this->item->transit($transition, $this->context, $this->errorCollection, $success);
}

return $transition->start($this->item, $this->context, $this->errorCollection);
return $this->item->start($transition, $this->context, $this->errorCollection, $success);
}

/**
Expand Down

0 comments on commit b75ce73

Please sign in to comment.