Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Symfony/Component/Workflow/Exception/TransitionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Workflow\Exception;

/**
* @author Andrew Tch <[email protected]>
*/
class TransitionException extends LogicException
{
/**
* @var mixed
*/
private $subject;

/**
* @var string
*/
private $transitionName;

/**
* @var string
*/
private $workflowName;

public function __construct($subject, $transitionName, $workflowName)
{
$this->subject = $subject;
$this->transitionName = $transitionName;
$this->workflowName = $workflowName;

parent::__construct(sprintf('Unable to apply transition "%s" for workflow "%s".', $this->transitionName, $this->workflowName));
}

/**
* @return mixed
*/
public function getSubject()
{
return $this->subject;
}

/**
* @return string
*/
public function getTransitionName()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use a return type hint here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You commented a closed pr :-)

{
return $this->transitionName;
}

/**
* @return string
*/
public function getWorkflowName()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

{
return $this->workflowName;
}
}
19 changes: 18 additions & 1 deletion src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Exception\TransitionException;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
Expand Down Expand Up @@ -163,7 +164,7 @@ public function testCanDoesNotTriggerGuardEventsForNotEnabledTransitions()
}

/**
* @expectedException \Symfony\Component\Workflow\Exception\LogicException
* @expectedException \Symfony\Component\Workflow\Exception\TransitionException
* @expectedExceptionMessage Unable to apply transition "t2" for workflow "unnamed".
*/
public function testApplyWithImpossibleTransition()
Expand All @@ -176,6 +177,22 @@ public function testApplyWithImpossibleTransition()
$workflow->apply($subject, 't2');
}

public function testTransitionExceptionHasCorrectFields()
{
$definition = $this->createComplexWorkflowDefinition();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new MultipleStateMarkingStore());

try {
$workflow->apply($subject, 't2');
} catch (TransitionException $exception) {
$this->assertEquals('t2', $exception->getTransitionName());
$this->assertEquals('unnamed', $exception->getWorkflowName());
$this->assertEquals($subject, $exception->getSubject());
}
}

public function testCanWithSameNameTransition()
{
$definition = $this->createWorkflowWithSameNameTransition();
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Exception\LogicException;
use Symfony\Component\Workflow\Exception\TransitionException;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;

Expand Down Expand Up @@ -138,7 +139,7 @@ public function apply($subject, $transitionName)
}

if (!$applied) {
throw new LogicException(sprintf('Unable to apply transition "%s" for workflow "%s".', $transitionName, $this->name));
throw new TransitionException($subject, $transitionName, $this->name);
}

return $marking;
Expand Down