diff --git a/composer.json b/composer.json index 28921ed..877a160 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yohang/finite", - "description": "A simple PHP5.3+ Finite State Machine", + "description": "A simple PHP7.2+ Finite State Machine", "keywords": ["statemachine", "workflow", "state", "transition", "symfony", "bundle"], "homepage": "https://github.com/yohang/Finite", "type": "library", @@ -17,22 +17,22 @@ } ], "require": { - "php": ">=5.5", - "symfony/options-resolver": "^2.6|^3.0|^4.0", - "symfony/event-dispatcher": "^2.6|^3.0|^4.0", - "symfony/property-access": "^2.6|^3.0|^4.0" + "php": ">=8.3", + "symfony/options-resolver": "^6.0|^7.0", + "symfony/event-dispatcher": "^6.0|^7.0", + "symfony/property-access": "^6.0|^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.0", + "phpunit/phpunit": "^9.0", "pimple/pimple": "^1.0", - "symfony/dependency-injection": "^2.6|^3.0|^4.0", - "symfony/framework-bundle": "^2.6|^3.0|^4.0", - "symfony/security": "^2.6|^3.0|^4.0", - "twig/twig": "^1.13" + "symfony/dependency-injection": "^6.0|^7.0", + "symfony/framework-bundle": "^6.0|^7.0", + "symfony/security-bundle": "^6.0|^7.0", + "twig/twig": "^3.00" }, "suggest": { "pimple/pimple": "Needed for use with PimpleFactory", - "symfony/security": "Needed for using SecurityAwareStateMachine", + "symfony/security-bundle": "Needed for using SecurityAwareStateMachine", "symfony/yaml": "Yaml allows you to define your State graph in YAML" }, "autoload": { @@ -43,7 +43,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.1.x-dev", + "dev-upgrade/symfony-5" : "2.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e9e6995..b1710c5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions = "true" processIsolation = "false" stopOnFailure = "false" - syntaxCheck = "false" bootstrap = "tests/bootstrap.php" > diff --git a/src/Finite/Bundle/FiniteBundle/DependencyInjection/Configuration.php b/src/Finite/Bundle/FiniteBundle/DependencyInjection/Configuration.php index 5a2b8d0..2c1a7b6 100644 --- a/src/Finite/Bundle/FiniteBundle/DependencyInjection/Configuration.php +++ b/src/Finite/Bundle/FiniteBundle/DependencyInjection/Configuration.php @@ -18,8 +18,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('finite_finite'); + $treeBuilder = new TreeBuilder('finite_finite'); + $rootNode = $treeBuilder->getRootNode(); $rootProto = $rootNode->useAttributeAsKey('name')->prototype('array')->children(); $rootProto diff --git a/src/Finite/Event/Initialize.php b/src/Finite/Event/Initialize.php new file mode 100644 index 0000000..af58455 --- /dev/null +++ b/src/Finite/Event/Initialize.php @@ -0,0 +1,10 @@ + */ -class FiniteExtension extends \Twig_Extension +class FiniteExtension extends AbstractExtension { /** * @var Context @@ -30,11 +32,11 @@ public function __construct(Context $context) public function getFunctions() { return array( - new \Twig_SimpleFunction('finite_state', array($this, 'getFiniteState')), - new \Twig_SimpleFunction('finite_transitions', array($this, 'getFiniteTransitions')), - new \Twig_SimpleFunction('finite_properties', array($this, 'getFiniteProperties')), - new \Twig_SimpleFunction('finite_has', array($this, 'hasFiniteProperty')), - new \Twig_SimpleFunction('finite_can', array($this, 'canFiniteTransition')), + new TwigFunction('finite_state', array($this, 'getFiniteState')), + new TwigFunction('finite_transitions', array($this, 'getFiniteTransitions')), + new TwigFunction('finite_properties', array($this, 'getFiniteProperties')), + new TwigFunction('finite_has', array($this, 'hasFiniteProperty')), + new TwigFunction('finite_can', array($this, 'canFiniteTransition')), ); } diff --git a/src/Finite/Factory/AbstractFactory.php b/src/Finite/Factory/AbstractFactory.php index daf4fcc..988ed10 100644 --- a/src/Finite/Factory/AbstractFactory.php +++ b/src/Finite/Factory/AbstractFactory.php @@ -30,6 +30,7 @@ public function get($object, $graph = 'default') $hash = spl_object_hash($object).'.'.$graph; if (!isset($this->stateMachines[$hash])) { $stateMachine = $this->createStateMachine(); + if (null !== ($loader = $this->getLoader($object, $graph))) { $loader->load($stateMachine); } @@ -39,6 +40,7 @@ public function get($object, $graph = 'default') $this->stateMachines[$hash] = $stateMachine; } + return $this->stateMachines[$hash]; } diff --git a/src/Finite/StateMachine/StateMachine.php b/src/Finite/StateMachine/StateMachine.php index 47caad8..5411dd2 100644 --- a/src/Finite/StateMachine/StateMachine.php +++ b/src/Finite/StateMachine/StateMachine.php @@ -3,6 +3,8 @@ namespace Finite\StateMachine; use Finite\Event\FiniteEvents; +use Finite\Event\Initialize; +use Finite\Event\SetInitialState; use Finite\Event\StateMachineEvent; use Finite\Event\TransitionEvent; use Finite\Exception; @@ -102,12 +104,12 @@ public function initialize() $initialState = $this->findInitialState(); $this->stateAccessor->setState($this->object, $initialState); - $this->dispatcher->dispatch(FiniteEvents::SET_INITIAL_STATE, new StateMachineEvent($this)); + $this->dispatcher->dispatch(new SetInitialState($this)); } $this->currentState = $this->getState($initialState); - $this->dispatcher->dispatch(FiniteEvents::INITIALIZE, new StateMachineEvent($this)); + $this->dispatcher->dispatch(new Initialize($this)); } /** @@ -223,7 +225,7 @@ public function getTransition($name) throw new Exception\TransitionException(sprintf( 'Unable to find a transition called "%s" on object "%s" with graph "%s".', $name, - get_class($this->getObject()), + $this->getObject() !== null ? get_class($this->getObject()) : null, $this->getGraph() )); } @@ -242,7 +244,7 @@ public function getState($name) throw new Exception\StateException(sprintf( 'Unable to find a state called "%s" on object "%s" with graph "%s".', $name, - get_class($this->getObject()), + $this->getObject() !== null ? get_class($this->getObject()) : null, $this->getGraph() )); } @@ -397,10 +399,10 @@ function (State $state) use ($property, $value) { */ private function dispatchTransitionEvent(TransitionInterface $transition, TransitionEvent $event, $transitionState) { - $this->dispatcher->dispatch($transitionState, $event); - $this->dispatcher->dispatch($transitionState.'.'.$transition->getName(), $event); + $this->dispatcher->dispatch($event, $transitionState); + $this->dispatcher->dispatch($event, $transitionState.'.'.$transition->getName()); if (null !== $this->getGraph()) { - $this->dispatcher->dispatch($transitionState.'.'.$this->getGraph().'.'.$transition->getName(), $event); + $this->dispatcher->dispatch($event, $transitionState.'.'.$this->getGraph().'.'.$transition->getName()); } } } diff --git a/tests/Finite/Test/Acceptance/CallbacksTest.php b/tests/Finite/Test/Acceptance/CallbacksTest.php index c7e5d3f..8bce15c 100644 --- a/tests/Finite/Test/Acceptance/CallbacksTest.php +++ b/tests/Finite/Test/Acceptance/CallbacksTest.php @@ -4,11 +4,12 @@ use Finite\Loader\ArrayLoader; use Finite\StateMachine\StateMachine; +use PHPUnit\Framework\TestCase; /** * @author Yohan Giarelli */ -class CallbacksTest extends \PHPUnit_Framework_TestCase +class CallbacksTest extends TestCase { /** * @var StateMachine @@ -20,16 +21,14 @@ class CallbacksTest extends \PHPUnit_Framework_TestCase */ protected $alternativeStateMachine; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ + protected $callbacksMock; protected $object; protected $alternativeObject; - protected function setUp() + protected function setUp(): void { $this->object = new \stdClass; $this->object->finiteState = null; @@ -41,7 +40,7 @@ protected function setUp() $this->alternativeStateMachine = new StateMachine($this->alternativeObject, $this->stateMachine->getDispatcher()); $this->callbacksMock = $this - ->getMockBuilder('\stdClass') + ->getMockBuilder(\stdClass::class) ->setMethods( array( 'afterItWasProposed', diff --git a/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/Compiler/ContainerCallbackPassTest.php b/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/Compiler/ContainerCallbackPassTest.php index 782b6ec..cb1e85d 100644 --- a/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/Compiler/ContainerCallbackPassTest.php +++ b/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/Compiler/ContainerCallbackPassTest.php @@ -6,20 +6,21 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use PHPUnit\Framework\TestCase; /** * Test of ContainerCallbackPass * * @author Alexandre Bacco */ -class ContainerCallbackPassTest extends \PHPUnit_Framework_TestCase +class ContainerCallbackPassTest extends TestCase { /** * @var ContainerBuilder */ protected $container; - protected function setUp() + protected function setUp(): void { $this->container = new ContainerBuilder; diff --git a/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/FiniteFiniteExtensionTest.php b/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/FiniteFiniteExtensionTest.php index 6f47922..cf8b13e 100644 --- a/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/FiniteFiniteExtensionTest.php +++ b/tests/Finite/Test/Bundle/FiniteBundle/DependencyInjection/FiniteFiniteExtensionTest.php @@ -4,13 +4,14 @@ use Finite\Bundle\FiniteBundle\DependencyInjection\FiniteFiniteExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; +use PHPUnit\Framework\TestCase; /** * Test of FiniteExtension * * @author Yohan Giarelli */ -class FiniteFiniteExtensionTest extends \PHPUnit_Framework_TestCase +class FiniteFiniteExtensionTest extends TestCase { /** * @var FiniteFiniteExtension @@ -22,7 +23,7 @@ class FiniteFiniteExtensionTest extends \PHPUnit_Framework_TestCase */ protected $container; - protected function setUp() + protected function setUp(): void { $this->object = new FiniteFiniteExtension; $this->container = new ContainerBuilder; diff --git a/tests/Finite/Test/ContextTest.php b/tests/Finite/Test/ContextTest.php index 923130c..6b96685 100644 --- a/tests/Finite/Test/ContextTest.php +++ b/tests/Finite/Test/ContextTest.php @@ -6,11 +6,17 @@ use Finite\Factory\PimpleFactory; use Finite\StateMachine\StateMachine; use Finite\State\State; +use PHPUnit\Framework\TestCase; +use Finite\State\Accessor\StateAccessorInterface; +use Finite\StatefulInterface; +use Finite\Transition\TransitionInterface; +use Finite\StateMachine\StateMachineInterface; +use Finite\Factory\FactoryInterface; /** * @author Yohan Giarelli */ -class ContextTest extends \PHPUnit_Framework_TestCase +class ContextTest extends TestCase { /** * @var Context @@ -19,9 +25,9 @@ class ContextTest extends \PHPUnit_Framework_TestCase protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); + $this->accessor = $accessor = $this->getMockBuilder(StateAccessorInterface::class)->getMock(); $container = new \Pimple(array( 'state_machine' => function() use ($accessor) { $sm = new StateMachine(null, null, $accessor); @@ -39,32 +45,34 @@ public function setUp() public function testGetStateMachine() { $this->accessor->expects($this->once())->method('getState')->will($this->returnValue('s1')); - $sm = $this->object->getStateMachine($this->getMock('Finite\StatefulInterface')); - $this->assertInstanceOf('Finite\StateMachine\StateMachine', $sm); + $mock = $this->getMockBuilder(StatefulInterface::class)->getMock(); + $sm = $this->object->getStateMachine($mock); + + $this->assertInstanceOf(StateMachine::class, $sm); $this->assertSame('s1', $sm->getCurrentState()->getName()); } public function testGetState() { $this->accessor->expects($this->once())->method('getState')->will($this->returnValue('s1')); - $this->assertSame('s1', $this->object->getState($this->getMock('Finite\StatefulInterface'))); + $this->assertSame('s1', $this->object->getState($this->getMockBuilder(StatefulInterface::class)->getMock())); } public function testGetTransitions() { $this->accessor->expects($this->once())->method('getState')->will($this->returnValue('s1')); - $this->assertEquals(array('t12'), $this->object->getTransitions($this->getMock('Finite\StatefulInterface'))); + $this->assertEquals(array('t12'), $this->object->getTransitions($this->getMockBuilder(StatefulInterface::class)->getMock())); } public function testGetTransitionObjects() { $this->accessor->expects($this->once())->method('getState')->will($this->returnValue('s1')); - $transitions = $this->object->getTransitions($this->getMock('Finite\StatefulInterface'), 'default', true); + $transitions = $this->object->getTransitions($this->getMockBuilder(StatefulInterface::class)->getMock(), 'default', true); $this->assertCount(1, $transitions); - $this->assertInstanceOf('Finite\Transition\TransitionInterface', $transitions[0]); + $this->assertInstanceOf(TransitionInterface::class, $transitions[0]); } public function testGetProperties() @@ -72,22 +80,22 @@ public function testGetProperties() $this->accessor->expects($this->once())->method('getState')->will($this->returnValue('s1')); $this->assertEquals( array('foo' => true, 'bar' => false), - $this->object->getProperties($this->getMock('Finite\StatefulInterface')) + $this->object->getProperties($this->getMockBuilder(StatefulInterface::class)->getMock()) ); } public function testHasProperty() { $this->accessor->expects($this->exactly(2))->method('getState')->will($this->returnValue('s1')); - $this->assertTrue($this->object->hasProperty($this->getMock('Finite\StatefulInterface'), 'foo')); - $this->assertFalse($this->object->hasProperty($this->getMock('Finite\StatefulInterface'), 'baz')); + $this->assertTrue($this->object->hasProperty($this->getMockBuilder(StatefulInterface::class)->getMock(), 'foo')); + $this->assertFalse($this->object->hasProperty($this->getMockBuilder(StatefulInterface::class)->getMock(), 'baz')); } public function testItRetrievesGoodStateMachine() { - $object = $this->getMock('Finite\StatefulInterface'); - $factory = $this->getMock('Finite\Factory\FactoryInterface'); - $sm = $this->getMock('Finite\StateMachine\StateMachineInterface'); + $object = $this->getMockBuilder(StatefulInterface::class)->getMock(); + $factory = $this->getMockBuilder(FactoryInterface::class)->getMock(); + $sm = $this->getMockBuilder(StateMachineInterface::class)->getMock(); $factory->expects($this->once())->method('get')->with($object, 'foo')->will($this->returnValue($sm)); diff --git a/tests/Finite/Test/Event/Callback/CallbackBuilderFactoryTest.php b/tests/Finite/Test/Event/Callback/CallbackBuilderFactoryTest.php index ac89474..2a1995a 100644 --- a/tests/Finite/Test/Event/Callback/CallbackBuilderFactoryTest.php +++ b/tests/Finite/Test/Event/Callback/CallbackBuilderFactoryTest.php @@ -3,19 +3,22 @@ namespace Finite\Test\Event\Callback; use Finite\Event\Callback\CallbackBuilderFactory; +use PHPUnit\Framework\TestCase; +use Finite\StateMachine\StateMachineInterface; +use Finite\Event\Callback\CallbackBuilder; /** * @author Yohan Giarelli */ -class CallbackBuilderFactoryTest extends \PHPUnit_Framework_TestCase +class CallbackBuilderFactoryTest extends TestCase { public function testItConstructsCallbackBuilder() { - $sm = $this->getMock('Finite\StateMachine\StateMachineInterface'); + $sm = $this->getMockBuilder(StateMachineInterface::class)->getMock(); $factory = new CallbackBuilderFactory; - $this->assertInstanceOf('Finite\Event\Callback\CallbackBuilder', $builder = $factory->createBuilder($sm)); + $this->assertInstanceOf(CallbackBuilder::class, $builder = $factory->createBuilder($sm)); $this->assertNotSame($builder, $factory->createBuilder($sm)); } } diff --git a/tests/Finite/Test/Event/Callback/CallbackBuilderTest.php b/tests/Finite/Test/Event/Callback/CallbackBuilderTest.php index 8c06017..33ef080 100644 --- a/tests/Finite/Test/Event/Callback/CallbackBuilderTest.php +++ b/tests/Finite/Test/Event/Callback/CallbackBuilderTest.php @@ -3,20 +3,24 @@ namespace Finite\Test\Event\Callback; use Finite\Event\Callback\CallbackBuilder; +use PHPUnit\Framework\TestCase; +use Finite\StateMachine\StateMachine; +use Finite\Event\Callback\Callback; +use Finite\Event\Callback\CallbackSpecification; /** * @author Yohan Giarelli */ -class CallbackBuilderTest extends \PHPUnit_Framework_TestCase +class CallbackBuilderTest extends TestCase { public function testItBuildsCallback() { $stateMachine = $this - ->getMockBuilder('Finite\StateMachine\StateMachine') + ->getMockBuilder(StateMachine::class) ->disableOriginalConstructor() ->getMock(); - $callableMock = $this->getMockBuilder('\stdClass')->setMethods(array('call'))->getMock(); + $callableMock = $this->getMockBuilder(\stdClass::class)->setMethods(array('call'))->getMock(); $callback = CallbackBuilder::create($stateMachine, array($callableMock, 'call')) ->setFrom(array('s1')) @@ -27,7 +31,7 @@ public function testItBuildsCallback() ->addOn('t23') ->getCallback(); - $this->assertInstanceOf('Finite\Event\Callback\Callback', $callback); - $this->assertInstanceOf('Finite\Event\Callback\CallbackSpecification', $callback->getSpecification()); + $this->assertInstanceOf(Callback::class, $callback); + $this->assertInstanceOf(CallbackSpecification::class, $callback->getSpecification()); } } diff --git a/tests/Finite/Test/Event/Callback/CallbackSpecificationTest.php b/tests/Finite/Test/Event/Callback/CallbackSpecificationTest.php index 3bc9de5..36efe90 100644 --- a/tests/Finite/Test/Event/Callback/CallbackSpecificationTest.php +++ b/tests/Finite/Test/Event/Callback/CallbackSpecificationTest.php @@ -6,17 +6,19 @@ use Finite\Event\TransitionEvent; use Finite\State\State; use Finite\Transition\Transition; +use PHPUnit\Framework\TestCase; +use Finite\StateMachine\StateMachine; /** * @author Yohan Giarelli */ -class CallbackSpecificationTest extends \PHPUnit_Framework_TestCase +class CallbackSpecificationTest extends TestCase { private $stateMachine; - protected function setUp() + protected function setUp(): void { - $this->stateMachine = $this->getMock('Finite\StateMachine\StateMachine'); + $this->stateMachine = $this->getMockBuilder(StateMachine::class)->getMock(); } public function testItIsSatisfiedByFrom() diff --git a/tests/Finite/Test/Event/Callback/CallbackTest.php b/tests/Finite/Test/Event/Callback/CallbackTest.php index 4dcbd92..60a1f69 100644 --- a/tests/Finite/Test/Event/Callback/CallbackTest.php +++ b/tests/Finite/Test/Event/Callback/CallbackTest.php @@ -3,18 +3,22 @@ namespace Finite\Test\Event\Callback; use Finite\Event\Callback\Callback; +use PHPUnit\Framework\TestCase; +use Finite\Event\Callback\CallbackSpecification; +use Finite\Event\TransitionEvent; +use Finite\StateMachine\StateMachine; /** * @author Yohan Giarelli */ -class CallbackTest extends \PHPUnit_Framework_TestCase +class CallbackTest extends TestCase { public function testInvokeWithGoodSpec() { - $spec = $this->getMockBuilder('Finite\Event\Callback\CallbackSpecification')->disableOriginalConstructor()->getMock(); - $callableMock = $this->getMockBuilder('\stdClass')->setMethods(array('call'))->getMock(); - $event = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $stateMachine = $this->getMockBuilder('Finite\StateMachine\StateMachine')->disableOriginalConstructor()->getMock(); + $spec = $this->getMockBuilder(CallbackSpecification::class)->disableOriginalConstructor()->getMock(); + $callableMock = $this->getMockBuilder(\stdClass::class)->setMethods(array('call'))->getMock(); + $event = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $stateMachine = $this->getMockBuilder(StateMachine::class)->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getStateMachine')->will($this->returnValue($stateMachine)); $spec->expects($this->once())->method('isSatisfiedBy')->with($event)->will($this->returnValue(true)); @@ -27,9 +31,9 @@ public function testInvokeWithGoodSpec() public function testInvokeWithBadSpec() { - $spec = $this->getMockBuilder('Finite\Event\Callback\CallbackSpecification')->disableOriginalConstructor()->getMock(); - $callableMock = $this->getMockBuilder('\stdClass')->setMethods(array('call'))->getMock(); - $event = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); + $spec = $this->getMockBuilder(CallbackSpecification::class)->disableOriginalConstructor()->getMock(); + $callableMock = $this->getMockBuilder(\stdClass::class)->setMethods(array('call'))->getMock(); + $event = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); $spec->expects($this->once())->method('isSatisfiedBy')->with($event)->will($this->returnValue(false)); $callableMock->expects($this->never())->method('call'); diff --git a/tests/Finite/Test/Event/CallbackHandlerTest.php b/tests/Finite/Test/Event/CallbackHandlerTest.php index 15e93c5..d31750c 100644 --- a/tests/Finite/Test/Event/CallbackHandlerTest.php +++ b/tests/Finite/Test/Event/CallbackHandlerTest.php @@ -7,31 +7,31 @@ use Finite\Event\CallbackHandler; use Finite\Event\FiniteEvents; use Finite\Event\TransitionEvent; +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Finite\StateMachine\StateMachineInterface; +use Finite\Transition\TransitionInterface; +use Finite\State\StateInterface; +use Finite\StatefulInterface; /** * @author Yohan Giarelli */ -class CallbackHandlerTest extends \PHPUnit_Framework_TestCase +class CallbackHandlerTest extends TestCase { /** * @var CallbackHandler */ protected $object; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ protected $dispatcher; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ protected $statemachine; - public function setUp() + public function setUp(): void { - $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'); - $this->statemachine = $this->getMock('Finite\StateMachine\StateMachineInterface'); + $this->dispatcher = $this->getMockBuilder(EventDispatcher::class)->getMock(); + $this->statemachine = $this->getMockBuilder(StateMachineInterface::class)->getMock(); $this->object = new CallbackHandler($this->dispatcher); } @@ -40,7 +40,7 @@ public function testItAttachsAllPreTransition() $this->dispatcher ->expects($this->once()) ->method('addListener') - ->with(FiniteEvents::PRE_TRANSITION, $this->isInstanceOf('Finite\Event\Callback\Callback')); + ->with(FiniteEvents::PRE_TRANSITION, $this->isInstanceOf(Callback::class)); $this->object->addBefore( CallbackBuilder::create($this->statemachine)->setCallable(function() {})->getCallback() @@ -64,12 +64,12 @@ public function testItAttachsGivenPreTransition() public function testItAttachsPreTransitionWithToSpec() { - $transitionOk = $this->getMock('Finite\Transition\TransitionInterface'); - $transitionNotOk = $this->getMock('Finite\Transition\TransitionInterface'); - $state = $this->getMock('Finite\State\StateInterface'); - $e1 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $e2 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $stateful = $this->getMock('Finite\StatefulInterface'); + $transitionOk = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $transitionNotOk = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $state = $this->getMockBuilder(StateInterface::class)->getMock(); + $e1 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $e2 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $stateful = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->statemachine->expects($this->any())->method('getObject')->will($this->returnValue($stateful)); $e1->expects($this->any())->method('getStateMachine')->will($this->returnValue($this->statemachine)); @@ -87,7 +87,7 @@ public function testItAttachsPreTransitionWithToSpec() ->with( FiniteEvents::PRE_TRANSITION, $this->logicalAnd( - $this->isInstanceOf('Finite\Event\Callback\Callback'), + $this->isInstanceOf(Callback::class), $this->callback(function(Callback $c) use ($e1, $e2) { $c($e1); $c($e2); return true; }) ) ); @@ -107,12 +107,12 @@ function($object, TransitionEvent $event) use ($that, $stateful) { public function testItAttachsPreTransitionWithFromSpec() { - $e1 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $e2 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $stateOk = $this->getMock('Finite\State\StateInterface'); - $stateNotOk = $this->getMock('Finite\State\StateInterface'); - $transition = $this->getMock('Finite\Transition\TransitionInterface'); - $stateful = $this->getMock('Finite\StatefulInterface'); + $e1 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $e2 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $stateOk = $this->getMockBuilder(StateInterface::class)->getMock(); + $stateNotOk = $this->getMockBuilder(StateInterface::class)->getMock(); + $transition = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $stateful = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->statemachine->expects($this->any())->method('getObject')->will($this->returnValue($stateful)); $e1->expects($this->any())->method('getStateMachine')->will($this->returnValue($this->statemachine)); @@ -150,12 +150,12 @@ function($object, TransitionEvent $event) use ($that, $stateful) { public function testItAttachsPreTransitionWithExcludeFromSpec() { - $e1 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $e2 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $stateOk = $this->getMock('Finite\State\StateInterface'); - $stateNotOk = $this->getMock('Finite\State\StateInterface'); - $transition = $this->getMock('Finite\Transition\TransitionInterface'); - $stateful = $this->getMock('Finite\StatefulInterface'); + $e1 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $e2 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $stateOk = $this->getMockBuilder(StateInterface::class)->getMock(); + $stateNotOk = $this->getMockBuilder(StateInterface::class)->getMock(); + $transition = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $stateful = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->statemachine->expects($this->any())->method('getObject')->will($this->returnValue($stateful)); $e1->expects($this->any())->method('getStateMachine')->will($this->returnValue($this->statemachine)); @@ -193,12 +193,12 @@ function ($object, TransitionEvent $event) use ($that, $stateful) { public function testItAttachsPreTransitionWithExcludeToSpec() { - $transitionOk = $this->getMock('Finite\Transition\TransitionInterface'); - $transitionNotOk = $this->getMock('Finite\Transition\TransitionInterface'); - $state = $this->getMock('Finite\State\StateInterface'); - $e1 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $e2 = $this->getMockBuilder('Finite\Event\TransitionEvent')->disableOriginalConstructor()->getMock(); - $stateful = $this->getMock('Finite\StatefulInterface'); + $transitionOk = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $transitionNotOk = $this->getMockBuilder(TransitionInterface::class)->getMock(); + $state = $this->getMockBuilder(StateInterface::class)->getMock(); + $e1 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $e2 = $this->getMockBuilder(TransitionEvent::class)->disableOriginalConstructor()->getMock(); + $stateful = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->statemachine->expects($this->any())->method('getObject')->will($this->returnValue($stateful)); $e1->expects($this->any())->method('getStateMachine')->will($this->returnValue($this->statemachine)); diff --git a/tests/Finite/Test/Event/TransitionEventTest.php b/tests/Finite/Test/Event/TransitionEventTest.php index 1416d30..9333357 100644 --- a/tests/Finite/Test/Event/TransitionEventTest.php +++ b/tests/Finite/Test/Event/TransitionEventTest.php @@ -3,8 +3,12 @@ namespace Finite\Test\Event; use Finite\Event\TransitionEvent; +use PHPUnit\Framework\TestCase; +use Finite\Transition\Transition; +use Finite\State\State; +use Finite\StateMachine\StateMachine; -class TransitionEventTest extends \PHPUnit_Framework_TestCase +class TransitionEventTest extends TestCase { /** * @var Finite\Transition\Transition @@ -16,9 +20,9 @@ class TransitionEventTest extends \PHPUnit_Framework_TestCase */ protected $object; - protected function setUp() + protected function setUp(): void { - $this->transition = $this->getMockBuilder('Finite\Transition\Transition')->disableOriginalConstructor()->getMock(); + $this->transition = $this->getMockBuilder(Transition::class)->disableOriginalConstructor()->getMock(); $this->transition ->expects($this->once()) @@ -27,9 +31,9 @@ protected function setUp() ->will($this->returnValue(array('returned' => 1))); $this->object = new TransitionEvent( - $this->getMockBuilder('Finite\State\State')->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(State::class)->disableOriginalConstructor()->getMock(), $this->transition, - $this->getMockBuilder('Finite\StateMachine\StateMachine')->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(StateMachine::class)->disableOriginalConstructor()->getMock(), array() ); } diff --git a/tests/Finite/Test/Extension/Twig/FiniteExtensionTest.php b/tests/Finite/Test/Extension/Twig/FiniteExtensionTest.php index fcf1bd9..6e7e708 100644 --- a/tests/Finite/Test/Extension/Twig/FiniteExtensionTest.php +++ b/tests/Finite/Test/Extension/Twig/FiniteExtensionTest.php @@ -7,29 +7,31 @@ use Finite\Factory\PimpleFactory; use Finite\StateMachine\StateMachine; use Finite\State\State; +use PHPUnit\Framework\TestCase; +use Finite\State\Accessor\StateAccessorInterface; +use Finite\StatefulInterface; +use Twig\Environment; +use Twig\Loader\ArrayLoader; /** * @author Yohan Giarelli */ -class FiniteExtensionTest extends \PHPUnit_Framework_TestCase +class FiniteExtensionTest extends TestCase { /** * @var \Twig_Environment */ protected $env; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ protected $context; protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); - $this->env = new \Twig_Environment( - new \Twig_Loader_Array( + $this->accessor = $accessor = $this->getMockBuilder(StateAccessorInterface::class)->getMock(); + $this->env = new Environment( + new ArrayLoader( array( 'state' => '{{ finite_state(object) }}', 'transitions' => '{% for transition in finite_transitions(object) %}{{ transition }}{% endfor %}', @@ -88,7 +90,7 @@ public function testCan() public function getObjectMock() { - $mock = $this->getMock('Finite\StatefulInterface'); + $mock = $this->getMockBuilder(StatefulInterface::class)->getMock(); return $mock; } diff --git a/tests/Finite/Test/Factory/PimpleFactoryTest.php b/tests/Finite/Test/Factory/PimpleFactoryTest.php index 13826b3..7fbb58e 100644 --- a/tests/Finite/Test/Factory/PimpleFactoryTest.php +++ b/tests/Finite/Test/Factory/PimpleFactoryTest.php @@ -4,8 +4,12 @@ use Finite\Factory\PimpleFactory; use Finite\StateMachine\StateMachine; +use PHPUnit\Framework\TestCase; +use Finite\State\Accessor\StateAccessorInterface; +use Finite\StatefulInterface; +use Finite\Loader\LoaderInterface; -class PimpleFactoryTest extends \PHPUnit_Framework_TestCase +class PimpleFactoryTest extends TestCase { /** * @var PimpleFactory @@ -14,9 +18,9 @@ class PimpleFactoryTest extends \PHPUnit_Framework_TestCase protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); + $this->accessor = $accessor = $this->getMockBuilder(StateAccessorInterface::class)->getMock(); $container = new \Pimple(array( 'state_machine' => function() use ($accessor) { $sm = new StateMachine(null, null, $accessor); @@ -32,14 +36,14 @@ public function setUp() public function testGet() { - $object = $this->getMock('Finite\StatefulInterface'); + $object = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s2')); $sm = $this->object->get($object); - $this->assertInstanceOf('Finite\StateMachine\StateMachine', $sm); + $this->assertInstanceOf(StateMachine::class, $sm); $this->assertSame('s2', $sm->getCurrentState()->getName()); - $object2 = $this->getMock('Finite\StatefulInterface'); + $object2 = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s2')); $sm2 = $this->object->get($object2); @@ -48,13 +52,13 @@ public function testGet() public function testLoad() { - $object = $this->getMock('Finite\StatefulInterface'); + $object = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->any())->method('getState')->will($this->returnValue('s1')); - $loader1 = $this->getMock('Finite\Loader\LoaderInterface'); + $loader1 = $this->getMockBuilder(LoaderInterface::class)->getMock(); $loader1->expects($this->at(0))->method('supports')->with($object, 'foo')->will($this->returnValue(false)); $loader1->expects($this->at(1))->method('supports')->with($object, 'bar')->will($this->returnValue(true)); - $loader2 = $this->getMock('Finite\Loader\LoaderInterface'); + $loader2 = $this->getMockBuilder(LoaderInterface::class)->getMock(); $loader2->expects($this->at(0))->method('supports')->with($object, 'foo')->will($this->returnValue(true)); $loader2->expects($this->at(1))->method('load'); diff --git a/tests/Finite/Test/Factory/SymfonyDependencyInjectionFactoryTest.php b/tests/Finite/Test/Factory/SymfonyDependencyInjectionFactoryTest.php index 27ba5d2..99dde8e 100644 --- a/tests/Finite/Test/Factory/SymfonyDependencyInjectionFactoryTest.php +++ b/tests/Finite/Test/Factory/SymfonyDependencyInjectionFactoryTest.php @@ -6,8 +6,11 @@ use Finite\StateMachine\StateMachine; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; +use PHPUnit\Framework\TestCase; +use Finite\State\Accessor\StateAccessorInterface; +use Finite\StatefulInterface; -class SymfonyDependencyInjectionFactoryTest extends \PHPUnit_Framework_TestCase +class SymfonyDependencyInjectionFactoryTest extends TestCase { /** * @var PimpleFactory @@ -16,12 +19,12 @@ class SymfonyDependencyInjectionFactoryTest extends \PHPUnit_Framework_TestCase protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); + $this->accessor = $this->getMockBuilder(StateAccessorInterface::class)->getMock(); $container = new ContainerBuilder; $container - ->register('state_machine', 'Finite\StateMachine\StateMachine') + ->register('state_machine', StateMachine::class) ->setShared(false) ->setArguments(array(null, null, $this->accessor)) ->addMethodCall('addTransition', array('t12', 's1', 's2')) @@ -32,14 +35,14 @@ public function setUp() public function testGet() { - $object = $this->getMock('Finite\StatefulInterface'); + $object = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s2')); $sm = $this->object->get($object); - $this->assertInstanceOf('Finite\StateMachine\StateMachine', $sm); + $this->assertInstanceOf(StateMachine::class, $sm); $this->assertSame('s2', $sm->getCurrentState()->getName()); - $object2 = $this->getMock('Finite\StatefulInterface'); + $object2 = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s2')); $sm2 = $this->object->get($object2); diff --git a/tests/Finite/Test/Loader/ArrayLoaderTest.php b/tests/Finite/Test/Loader/ArrayLoaderTest.php index 4217845..517d863 100644 --- a/tests/Finite/Test/Loader/ArrayLoaderTest.php +++ b/tests/Finite/Test/Loader/ArrayLoaderTest.php @@ -5,25 +5,25 @@ use Finite\Loader\ArrayLoader; use Finite\StateMachine\StateMachine; use Symfony\Component\OptionsResolver\OptionsResolver; +use PHPUnit\Framework\TestCase; +use Finite\Event\CallbackHandler; +use Finite\State\Accessor\PropertyPathStateAccessor; /** * @author Yohan Giarelli */ -class ArrayLoaderTest extends \PHPUnit_Framework_TestCase +class ArrayLoaderTest extends TestCase { /** * @var ArrayLoader */ protected $object; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ protected $callbackHandler; - protected function setUp() + protected function setUp(): void { - $this->callbackHandler = $this->getMockBuilder('Finite\Event\CallbackHandler') + $this->callbackHandler = $this->getMockBuilder(CallbackHandler::class) ->disableOriginalConstructor() ->getMock(); @@ -52,7 +52,7 @@ protected function setUp() public function testLoad() { - $sm = $this->getMock('Finite\StateMachine\StateMachine'); + $sm = $this->getMockBuilder(StateMachine::class)->getMock(); $sm->expects($this->once())->method('setStateAccessor'); $sm->expects($this->once())->method('setGraph'); $sm->expects($this->exactly(3))->method('addState'); @@ -62,7 +62,7 @@ public function testLoad() public function testLoadGraph() { - $sm = $this->getMock('Finite\StateMachine\StateMachine'); + $sm = $this->getMockBuilder(StateMachine::class)->getMock(); $graphName = 'foobar'; $loader = new ArrayLoader(array('class' => 'Stateful1', 'graph' => $graphName), $this->callbackHandler); @@ -74,7 +74,7 @@ public function testLoadGraph() public function testLoadWithMissingOptions() { - $sm = $this->getMock('Finite\StateMachine\StateMachine'); + $sm = $this->getMockBuilder(StateMachine::class)->getMock(); $this->object = new ArrayLoader( array( @@ -105,7 +105,7 @@ public function testLoadWithMissingOptions() public function testLoadCallbacks() { - $sm = $this->getMock('Finite\StateMachine\StateMachine'); + $sm = $this->getMockBuilder(StateMachine::class)->getMock(); $allTimes = function () {}; $beforeMiddleize = function () {}; $fromStartToOtherThanMiddle = function () {}; @@ -183,7 +183,9 @@ public function testLoadWithProperties() public function testLoadWithCustomStateAccessor() { - $sa = $this->getMock('Finite\State\Accessor\PropertyPathStateAccessor', array(), array(), 'CustomAccessor'); + $sa = $this->getMockBuilder(PropertyPathStateAccessor::class) + ->setMockClassName('CustomAccessor') + ->getMock(); $sm = new StateMachine; $sm->setStateAccessor($sa); @@ -195,8 +197,13 @@ public function testLoadWithCustomStateAccessor() public function testSupports() { - $object = $this->getMock('Finite\StatefulInterface', array(), array(), 'Stateful1'); - $object2 = $this->getMock('Finite\StatefulInterface', array(), array(), 'Stateful2'); + $object = $this->getMockBuilder('Finite\StatefulInterface') + ->setMockClassName('Stateful1') + ->getMock(); + + $object2 = $this->getMockBuilder('Finite\StatefulInterface') + ->setMockClassName('Stateful2') + ->getMock(); $this->assertTrue($this->object->supports($object)); $this->assertFalse($this->object->supports($object2)); diff --git a/tests/Finite/Test/State/Accessor/PropertyPathStateAccessorTest.php b/tests/Finite/Test/State/Accessor/PropertyPathStateAccessorTest.php index dafafe2..bfeeebc 100644 --- a/tests/Finite/Test/State/Accessor/PropertyPathStateAccessorTest.php +++ b/tests/Finite/Test/State/Accessor/PropertyPathStateAccessorTest.php @@ -4,23 +4,25 @@ use Finite\State\Accessor\PropertyPathStateAccessor; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; +use PHPUnit\Framework\TestCase; +use Finite\StatefulInterface; -class PropertyPathStateAccessorTest extends \PHPUnit_Framework_TestCase +class PropertyPathStateAccessorTest extends TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject */ protected $propertyAccessor; - protected function setUp() + protected function setUp(): void { - $this->propertyAccessor = $this->getMock('Symfony\Component\PropertyAccess\PropertyAccessorInterface'); + $this->propertyAccessor = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyAccessorInterface')->getMock(); } public function testGetState() { $object = new PropertyPathStateAccessor('bar', $this->propertyAccessor); - $stateful = $this->getMock('Finite\StatefulInterface'); + $stateful = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->propertyAccessor ->expects($this->at(0)) @@ -43,7 +45,7 @@ public function testGetState() public function testSetState() { $object = new PropertyPathStateAccessor('bar', $this->propertyAccessor); - $stateful = $this->getMock('Finite\StatefulInterface'); + $stateful = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->propertyAccessor ->expects($this->at(0)) @@ -69,7 +71,7 @@ public function testSetState() public function testSetOnUnknownProperty() { $object = new PropertyPathStateAccessor('bar', $this->propertyAccessor); - $stateful = $this->getMock('Finite\StatefulInterface'); + $stateful = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->propertyAccessor ->expects($this->once()) @@ -87,7 +89,7 @@ public function testSetOnUnknownProperty() public function testGetOnUnknownProperty() { $object = new PropertyPathStateAccessor('bar', $this->propertyAccessor); - $stateful = $this->getMock('Finite\StatefulInterface'); + $stateful = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->propertyAccessor ->expects($this->once()) diff --git a/tests/Finite/Test/State/StateTest.php b/tests/Finite/Test/State/StateTest.php index 6f0fee2..c76f893 100644 --- a/tests/Finite/Test/State/StateTest.php +++ b/tests/Finite/Test/State/StateTest.php @@ -3,20 +3,22 @@ namespace Finite\Test\State; use Finite\State\State; +use PHPUnit\Framework\MockObject\Builder\InvocationMocker; +use PHPUnit\Framework\TestCase; /** * * * @author Yohan Giarelli */ -class StateTest extends \PHPUnit_Framework_TestCase +class StateTest extends TestCase { /** * @var State */ protected $object; - protected function setUp() + protected function setUp(): void { $this->object = new State('test'); } @@ -57,11 +59,11 @@ public function testCanDataProvider() /** * @param string $transitionName * - * @return \PHPUnit_Framework_MockObject_Builder_InvocationMocker + * @return InvocationMocker */ private function getTransitionMock($transitionName) { - $transition = $this->getMock('\Finite\Transition\TransitionInterface'); + $transition = $this->getMockBuilder('\Finite\Transition\TransitionInterface')->getMock(); $transition->expects($this->once()) ->method('getName') diff --git a/tests/Finite/Test/StateMachine/ListenableStateMachineTest.php b/tests/Finite/Test/StateMachine/ListenableStateMachineTest.php index 544512c..5ee65a1 100644 --- a/tests/Finite/Test/StateMachine/ListenableStateMachineTest.php +++ b/tests/Finite/Test/StateMachine/ListenableStateMachineTest.php @@ -2,6 +2,7 @@ namespace Finite\Test\StateMachine; +use Finite\Event\Initialize; use Finite\StateMachine\ListenableStateMachine; use Finite\Test\StateMachineTestCase; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -21,11 +22,11 @@ class ListenableStateMachineTest extends StateMachineTestCase */ protected $dispatcher; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + $this->dispatcher = $this->getMockBuilder(EventDispatcher::class) ->disableOriginalConstructor() ->getMock(); @@ -34,10 +35,11 @@ public function setUp() public function testInitialize() { + $this->dispatcher ->expects($this->once()) ->method('dispatch') - ->with('finite.initialize', $this->isInstanceOf('Finite\Event\StateMachineEvent')); + ->with($this->isInstanceOf('Finite\Event\Initialize')); $this->initialize(); } @@ -47,32 +49,32 @@ public function testApply() $this->dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with('finite.test_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition'); $this->dispatcher ->expects($this->at(2)) ->method('dispatch') - ->with('finite.test_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition.t23'); $this->dispatcher ->expects($this->at(3)) ->method('dispatch') - ->with('finite.pre_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition'); $this->dispatcher ->expects($this->at(4)) ->method('dispatch') - ->with('finite.pre_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition.t23'); $this->dispatcher ->expects($this->at(5)) ->method('dispatch') - ->with('finite.post_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition'); $this->dispatcher ->expects($this->at(6)) ->method('dispatch') - ->with('finite.post_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition.t23'); $this->initialize(); $this->object->apply('t23'); @@ -83,12 +85,12 @@ public function testCan() $this->dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with('finite.test_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition'); $this->dispatcher ->expects($this->at(2)) ->method('dispatch') - ->with('finite.test_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition.t23'); $this->initialize(); $this->assertFalse($this->object->can('t34')); @@ -100,15 +102,15 @@ public function testCanWithListener() $this->dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with('finite.test_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition'); $this->dispatcher ->expects($this->at(2)) ->method('dispatch') - ->with('finite.test_transition.t23', $this->callback(function($event) { + ->with($this->callback(function($event) { $event->reject(); return $event instanceof \Finite\Event\TransitionEvent; - })); + }), 'finite.test_transition.t23'); $this->initialize(); $this->assertFalse($this->object->can('t34')); diff --git a/tests/Finite/Test/StateMachine/SecurityAwareStateMachineTest.php b/tests/Finite/Test/StateMachine/SecurityAwareStateMachineTest.php index 6ac3feb..ecbc894 100644 --- a/tests/Finite/Test/StateMachine/SecurityAwareStateMachineTest.php +++ b/tests/Finite/Test/StateMachine/SecurityAwareStateMachineTest.php @@ -3,11 +3,15 @@ namespace Finite\Test\StateMachine; use Finite\StateMachine\SecurityAwareStateMachine; +use PHPUnit\Framework\TestCase; +use Finite\StatefulInterface; +use Finite\State\Accessor\StateAccessorInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * @author Yohan Giarelli */ -class SecurityAwareStateMachineTest extends \PHPUnit_Framework_TestCase +class SecurityAwareStateMachineTest extends TestCase { /** * @var SecurityAwareStateMachine @@ -15,10 +19,10 @@ class SecurityAwareStateMachineTest extends \PHPUnit_Framework_TestCase protected $object; protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); - $statefulMock = $this->getMock('Finite\StatefulInterface'); + $this->accessor = $this->getMockBuilder(StateAccessorInterface::class)->getMock(); + $statefulMock = $this->getMockBuilder(StatefulInterface::class)->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s1')); $this->object = new SecurityAwareStateMachine($statefulMock, null, $this->accessor); @@ -29,7 +33,7 @@ public function setUp() public function testCan() { - $securityMock = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'); + $securityMock = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock(); $this->object->setSecurityContext($securityMock); $that = $this; diff --git a/tests/Finite/Test/StateMachine/StateMachineTest.php b/tests/Finite/Test/StateMachine/StateMachineTest.php index f6fef12..e7b8fec 100644 --- a/tests/Finite/Test/StateMachine/StateMachineTest.php +++ b/tests/Finite/Test/StateMachine/StateMachineTest.php @@ -2,6 +2,7 @@ namespace Finite\Test\StateMachine; +use Finite\Event\Initialize; use Finite\State\State; use Finite\StateMachine\StateMachine; use Finite\Test\StateMachineTestCase; @@ -16,7 +17,7 @@ public function testAddState() $this->object->addState('foo'); $this->assertInstanceOf('Finite\State\StateInterface', $this->object->getState('foo')); - $stateMock = $this->getMock('Finite\State\StateInterface'); + $stateMock = $this->getMockBuilder('Finite\State\StateInterface')->getMock(); $stateMock ->expects($this->once()) ->method('getName') @@ -31,7 +32,7 @@ public function testAddTransition() $this->object->addTransition('t12', 'state1', 'state2'); $this->assertInstanceOf('Finite\Transition\TransitionInterface', $this->object->getTransition('t12')); - $transitionMock = $this->getMock('Finite\Transition\TransitionInterface'); + $transitionMock = $this->getMockBuilder('Finite\Transition\TransitionInterface')->getMock(); $transitionMock->expects($this->atLeastOnce())->method('getName') ->will($this->returnValue('t23')); $transitionMock->expects($this->once()) ->method('getInitialStates')->will($this->returnValue(array('state2'))); @@ -48,14 +49,14 @@ public function testInitialize() $this->dispatcher ->expects($this->once()) ->method('dispatch') - ->with('finite.initialize', $this->isInstanceOf('Finite\Event\StateMachineEvent')); + ->with($this->isInstanceOf(Initialize::class)); $this->initialize(); } public function testInitializeWithInitialState() { - $object = $this->getMock('Finite\StatefulInterface'); + $object = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->accessor->expects($this->at(1))->method('setState')->will($this->returnValue('s1')); @@ -81,7 +82,7 @@ public function testCan() public function testCanWithGuardReturningFalse() { - $transition = $this->getMock('\Finite\Transition\TransitionInterface'); + $transition = $this->getMockBuilder('\Finite\Transition\TransitionInterface')->getMock(); $transition->expects($this->any()) ->method('getGuard') ->will($this->returnValue(function () { @@ -96,14 +97,14 @@ public function testCanWithGuardReturningFalse() public function testCanWithGuardReturningTrue() { - $transition = $this->getMock('\Finite\Transition\TransitionInterface'); + $transition = $this->getMockBuilder('\Finite\Transition\TransitionInterface')->getMock(); $transition->expects($this->any()) ->method('getGuard') ->will($this->returnValue(function () { return true; })); - $stateful = $this->getMock('Finite\StatefulInterface'); + $stateful = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->object->addState(new State('state1', State::TYPE_INITIAL)); $this->object->setObject($stateful); @@ -123,32 +124,32 @@ public function testApply() $this->dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with('finite.test_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition'); $this->dispatcher ->expects($this->at(2)) ->method('dispatch') - ->with('finite.test_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition.t23'); $this->dispatcher ->expects($this->at(3)) ->method('dispatch') - ->with('finite.pre_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition'); $this->dispatcher ->expects($this->at(4)) ->method('dispatch') - ->with('finite.pre_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition.t23'); $this->dispatcher ->expects($this->at(5)) ->method('dispatch') - ->with('finite.post_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition'); $this->dispatcher ->expects($this->at(6)) ->method('dispatch') - ->with('finite.post_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition.t23'); $this->initialize(); $this->object->apply('t23'); @@ -174,7 +175,7 @@ public function testGetStateFromObject() { $this->initialize(); - $state = $this->getMock('stdClass', array('__toString')); + $state = $this->getMockBuilder('stdClass', array('__toString'))->getMock(); $state->expects($this->once())->method('__toString')->will($this->returnValue('s1')); $this->assertInstanceOf('Finite\State\State', $this->object->getState($state)); @@ -189,47 +190,47 @@ public function testApplyWithGraph() $this->dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with('finite.test_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition'); $this->dispatcher ->expects($this->at(2)) ->method('dispatch') - ->with('finite.test_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition.t23'); $this->dispatcher ->expects($this->at(3)) ->method('dispatch') - ->with('finite.test_transition.foo.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.test_transition.foo.t23'); $this->dispatcher ->expects($this->at(4)) ->method('dispatch') - ->with('finite.pre_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition'); $this->dispatcher ->expects($this->at(5)) ->method('dispatch') - ->with('finite.pre_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition.t23'); $this->dispatcher ->expects($this->at(6)) ->method('dispatch') - ->with('finite.pre_transition.foo.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.pre_transition.foo.t23'); $this->dispatcher ->expects($this->at(7)) ->method('dispatch') - ->with('finite.post_transition', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition'); $this->dispatcher ->expects($this->at(8)) ->method('dispatch') - ->with('finite.post_transition.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition.t23'); $this->dispatcher ->expects($this->at(9)) ->method('dispatch') - ->with('finite.post_transition.foo.t23', $this->isInstanceOf('Finite\Event\TransitionEvent')); + ->with($this->isInstanceOf('Finite\Event\TransitionEvent'), 'finite.post_transition.foo.t23'); $this->object->setGraph('foo'); diff --git a/tests/Finite/Test/StateMachineTestCase.php b/tests/Finite/Test/StateMachineTestCase.php index 12bb097..9fc9b03 100644 --- a/tests/Finite/Test/StateMachineTestCase.php +++ b/tests/Finite/Test/StateMachineTestCase.php @@ -4,11 +4,13 @@ use Finite\State\State; use Finite\StateMachine\StateMachine; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\MockObject\MockObject; /** * @author Yohan Giarelli */ -class StateMachineTestCase extends \PHPUnit_Framework_TestCase +class StateMachineTestCase extends TestCase { /** * @var StateMachine @@ -16,15 +18,15 @@ class StateMachineTestCase extends \PHPUnit_Framework_TestCase protected $object; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $dispatcher; protected $accessor; - public function setUp() + public function setUp(): void { - $this->accessor = $this->getMock('Finite\State\Accessor\StateAccessorInterface'); + $this->accessor = $this->getMockBuilder('Finite\State\Accessor\StateAccessorInterface')->getMock(); $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -77,7 +79,7 @@ protected function initialize() protected function getStatefulObjectMock() { - $mock = $this->getMock('Finite\StatefulInterface'); + $mock = $this->getMockBuilder('Finite\StatefulInterface')->getMock(); $this->accessor->expects($this->at(0))->method('getState')->will($this->returnValue('s2')); return $mock; diff --git a/tests/Finite/Test/Transition/TransitionTest.php b/tests/Finite/Test/Transition/TransitionTest.php index 81952ca..393de6b 100644 --- a/tests/Finite/Test/Transition/TransitionTest.php +++ b/tests/Finite/Test/Transition/TransitionTest.php @@ -4,11 +4,12 @@ use Finite\Transition\Transition; use Symfony\Component\OptionsResolver\OptionsResolver; +use PHPUnit\Framework\TestCase; /** * @author Yohan Giarelli */ -class TransitionTest extends \PHPUnit_Framework_TestCase +class TransitionTest extends TestCase { /** * @var Transition @@ -20,7 +21,7 @@ class TransitionTest extends \PHPUnit_Framework_TestCase */ protected $optionsResolver; - protected function setUp() + protected function setUp(): void { $this->optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolver') ->disableOriginalConstructor()