This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Workflow/Tests/DefinitionTest.php
Nicolas Grekas 64e3a327bc Merge branch '3.4' into 4.3
* 3.4:
  Remove use of ForwardCompatTrait
  Remove deprecated methods assertArraySubset
2019-08-03 23:50:52 +02:00

73 lines
2.3 KiB
PHP

<?php
namespace Symfony\Component\Workflow\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Transition;
class DefinitionTest extends TestCase
{
public function testAddPlaces()
{
$places = range('a', 'e');
$definition = new Definition($places, []);
$this->assertCount(5, $definition->getPlaces());
$this->assertEquals(['a'], $definition->getInitialPlaces());
}
public function testSetInitialPlace()
{
$places = range('a', 'e');
$definition = new Definition($places, [], $places[3]);
$this->assertEquals([$places[3]], $definition->getInitialPlaces());
}
public function testSetInitialPlaces()
{
$places = range('a', 'e');
$definition = new Definition($places, [], ['a', 'e']);
$this->assertEquals(['a', 'e'], $definition->getInitialPlaces());
}
public function testSetInitialPlaceAndPlaceIsNotDefined()
{
$this->expectException('Symfony\Component\Workflow\Exception\LogicException');
$this->expectExceptionMessage('Place "d" cannot be the initial place as it does not exist.');
$definition = new Definition([], [], 'd');
}
public function testAddTransition()
{
$places = range('a', 'b');
$transition = new Transition('name', $places[0], $places[1]);
$definition = new Definition($places, [$transition]);
$this->assertCount(1, $definition->getTransitions());
$this->assertSame($transition, $definition->getTransitions()[0]);
}
public function testAddTransitionAndFromPlaceIsNotDefined()
{
$this->expectException('Symfony\Component\Workflow\Exception\LogicException');
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
$places = range('a', 'b');
new Definition($places, [new Transition('name', 'c', $places[1])]);
}
public function testAddTransitionAndToPlaceIsNotDefined()
{
$this->expectException('Symfony\Component\Workflow\Exception\LogicException');
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
$places = range('a', 'b');
new Definition($places, [new Transition('name', $places[0], 'c')]);
}
}