Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHPUnit 8, Symfony 5, PHP 7.2 #156

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand All @@ -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"
}
}
}
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "tests/bootstrap.php" >

<testsuites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Finite/Event/Initialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Finite\Event;

use Symfony\Contracts\EventDispatcher\Event;

class Initialize extends StateMachineEvent
{
public const NAME = FiniteEvents::INITIALIZE;
}
10 changes: 10 additions & 0 deletions src/Finite/Event/PostTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Finite\Event;

use Symfony\Contracts\EventDispatcher\Event;

class PostTransition extends Event
{
public const NAME = FiniteEvents::POST_TRANSITION;
}
10 changes: 10 additions & 0 deletions src/Finite/Event/PreTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Finite\Event;

use Symfony\Contracts\EventDispatcher\Event;

class PreTransition extends Event
{
public const NAME = FiniteEvents::PRE_TRANSITION;
}
11 changes: 11 additions & 0 deletions src/Finite/Event/SetInitialState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Finite\Event;

use Finite\StateMachine\StateMachine;
use Symfony\Contracts\EventDispatcher\Event;

class SetInitialState extends StateMachineEvent
{
public const NAME = FiniteEvents::SET_INITIAL_STATE;
}
2 changes: 1 addition & 1 deletion src/Finite/Event/StateMachineEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Finite\Event;

use Finite\StateMachine\StateMachine;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* The event object which is thrown on state machine actions.
Expand Down
10 changes: 10 additions & 0 deletions src/Finite/Event/TestTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Finite\Event;

use Symfony\Contracts\EventDispatcher\Event;

class TestTransition extends Event
{
public const NAME = FiniteEvents::TEST_TRANSITION;
}
14 changes: 8 additions & 6 deletions src/Finite/Extension/Twig/FiniteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace Finite\Extension\Twig;

use Finite\Context;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

/**
* The Finite Twig extension.
*
* @author Yohan Giarelli <[email protected]>
*/
class FiniteExtension extends \Twig_Extension
class FiniteExtension extends AbstractExtension
{
/**
* @var Context
Expand All @@ -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')),
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Finite/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -39,6 +40,7 @@ public function get($object, $graph = 'default')
$this->stateMachines[$hash] = $stateMachine;
}


return $this->stateMachines[$hash];
}

Expand Down
16 changes: 9 additions & 7 deletions src/Finite/StateMachine/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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()
));
}
Expand All @@ -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()
));
}
Expand Down Expand Up @@ -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());
}
}
}
11 changes: 5 additions & 6 deletions tests/Finite/Test/Acceptance/CallbacksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Finite\Loader\ArrayLoader;
use Finite\StateMachine\StateMachine;
use PHPUnit\Framework\TestCase;

/**
* @author Yohan Giarelli <[email protected]>
*/
class CallbacksTest extends \PHPUnit_Framework_TestCase
class CallbacksTest extends TestCase
{
/**
* @var StateMachine
Expand All @@ -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;
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
class FiniteFiniteExtensionTest extends \PHPUnit_Framework_TestCase
class FiniteFiniteExtensionTest extends TestCase
{
/**
* @var FiniteFiniteExtension
Expand All @@ -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;
Expand Down
Loading