From 432328909b5f3ef373842c7f037d0629c409b714 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 9 Jan 2020 18:24:27 -0300 Subject: [PATCH 1/3] Update tests --- .travis.yml | 10 ++++ README.md | 46 ++++++++++++++++--- composer.json | 7 +-- .../Admin/Extension/WorkflowExtensionTest.php | 5 +- tests/Controller/WorkflowControllerTest.php | 5 +- tests/Fixtures/LegacyWorkflowRegistry.php | 26 +++++++++++ tests/Fixtures/StubTranslator.php | 42 +++++++++++++++++ 7 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 tests/Fixtures/LegacyWorkflowRegistry.php create mode 100644 tests/Fixtures/StubTranslator.php diff --git a/.travis.yml b/.travis.yml index bdf6f77..93aa963 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,14 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 env: - SYMFONY_VERSION="3.4.*" - SYMFONY_VERSION="4.2.*" - SYMFONY_VERSION="4.3.*" + - SYMFONY_VERSION="4.4.*" + - SYMFONY_VERSION="5.0.*" matrix: exclude: @@ -18,6 +21,13 @@ matrix: env: SYMFONY_VERSION="4.2.*" - php: 7.0 env: SYMFONY_VERSION="4.3.*" + - php: 7.0 + env: SYMFONY_VERSION="4.4.*" + - php: 7.0 + env: SYMFONY_VERSION="5.0.*" + # Symfony >= 5.0 PHP requirement is ^7.2.5 + - php: 7.1 + env: SYMFONY_VERSION="5.0.*" sudo: false diff --git a/README.md b/README.md index ebaac63..898aaf9 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ This library add Symfony Workflow component integration within Sonata Admin. ### Code -- a Sonata Admin [Extension](https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html) : +- a Sonata Admin [Extension](https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html) : [WorkflowExtension](src/Admin/Extension/WorkflowExtension.php) -- a Controller trait : +- a Controller trait : [WorkflowControllerTrait](src/Controller/WorkflowControllerTrait.php) -- a Controller : +- a Controller : [WorkflowController](src/Controller/WorkflowController.php) @@ -44,6 +44,7 @@ Configuration Let say that you have an entity named `PullRequest` that is under workflow and for which you have an admin. +#### symfony/workflow <4.3 ```yaml # config/packages/workflow.yml framework: @@ -74,11 +75,42 @@ framework: to: closed ``` +#### symfony/workflow ^4.3|^5.0 +```yaml +# config/packages/workflow.yml +framework: + workflows: + pull_request: + type: state_machine + marking_store: + type: state_machine + property: status + supports: + - App\Entity\PullRequest + places: + - opened + - pending_review + - merged + - closed + initial_marking: + - opened + transitions: + start_review: + from: opened + to: pending_review + merge: + from: pending_review + to: merged + close: + from: pending_review + to: closed +``` + ### One extension for everything The extension is usable for many entities and with no configuration. -You only need to create a service for it, configure the controller that will handle the transition action +You only need to create a service for it, configure the controller that will handle the transition action and configure on which admin you want it available. For instance : @@ -108,7 +140,7 @@ sonata_admin: - admin.pull_request ``` -> **note**: You may noticed that we also registered the controller +> **note**: You may noticed that we also registered the controller `Yokai\SonataWorkflow\Controller\WorkflowController` as a service. It is important, because it needs the workflow registry service to work. @@ -170,12 +202,12 @@ What are these options ? Hook into the transition process -------------------------------- -Let say that when you start a review for a pull request, as a user, +Let say that when you start a review for a pull request, as a user, you will be asked to enter which users are involved in the review. To achieve this, you will be asked to fill a dedicated form. -You only need to create a custom controller for your entity admin : +You only need to create a custom controller for your entity admin : ```yaml # config/packages/sonata_admin.yml diff --git a/composer.json b/composer.json index 1fe96b0..803b90d 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,13 @@ } }, "require": { - "php": "^5.6||^7.0", + "php": "^5.6|^7.0", "sonata-project/admin-bundle": "^3.0", - "symfony/workflow": "^3.2|^4.0" + "symfony/workflow": "^3.2|^4.0|^5.0" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^5.0", + "symfony/translation": "^3.4|^4.0|^5.0" }, "minimum-stability": "stable", "extra": { diff --git a/tests/Admin/Extension/WorkflowExtensionTest.php b/tests/Admin/Extension/WorkflowExtensionTest.php index 37e7b70..bdf47ab 100644 --- a/tests/Admin/Extension/WorkflowExtensionTest.php +++ b/tests/Admin/Extension/WorkflowExtensionTest.php @@ -12,6 +12,7 @@ use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\StateMachine; use Yokai\SonataWorkflow\Admin\Extension\WorkflowExtension; +use Yokai\SonataWorkflow\Tests\Fixtures\LegacyWorkflowRegistry; use Yokai\SonataWorkflow\Controller\WorkflowController; use Yokai\SonataWorkflow\Tests\PullRequest; @@ -56,7 +57,7 @@ public function testAlterNewInstance() /** @var AdminInterface|ObjectProphecy $admin */ $admin = $this->prophesize(AdminInterface::class); - $registry = new Registry(); + $registry = new LegacyWorkflowRegistry(); $registry->add( new StateMachine(PullRequest::createWorkflowDefinition()), PullRequest::createSupportStrategy() @@ -118,7 +119,7 @@ public function testConfigureSideMenu($marking, array $transitions) ->willReturn('/pull-request/42/workflow/transition/'.$transition.'/apply'); } - $registry = new Registry(); + $registry = new LegacyWorkflowRegistry(); $registry->add( new StateMachine(PullRequest::createWorkflowDefinition()), PullRequest::createSupportStrategy() diff --git a/tests/Controller/WorkflowControllerTest.php b/tests/Controller/WorkflowControllerTest.php index d2fe63b..dc0dc88 100644 --- a/tests/Controller/WorkflowControllerTest.php +++ b/tests/Controller/WorkflowControllerTest.php @@ -8,7 +8,6 @@ use Sonata\AdminBundle\Exception\LockException; use Sonata\AdminBundle\Exception\ModelManagerException; use Sonata\AdminBundle\Templating\TemplateRegistryInterface; -use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -20,6 +19,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\StateMachine; +use Yokai\SonataWorkflow\Tests\Fixtures\LegacyWorkflowRegistry; +use Yokai\SonataWorkflow\Tests\Fixtures\StubTranslator; use Yokai\SonataWorkflow\Tests\PullRequest; use Yokai\SonataWorkflow\Tests\PullRequestWorkflowController; use Yokai\SonataWorkflow\Tests\TestKernel; @@ -63,7 +64,7 @@ public function setUp() { $this->container = $this->prophesize(ContainerInterface::class); $this->admin = $this->prophesize(AdminInterface::class); - $this->registry = new Registry(); + $this->registry = new LegacyWorkflowRegistry(); $this->flashBag = new FlashBag(); $this->translator = new StubTranslator(); diff --git a/tests/Fixtures/LegacyWorkflowRegistry.php b/tests/Fixtures/LegacyWorkflowRegistry.php new file mode 100644 index 0000000..497aa52 --- /dev/null +++ b/tests/Fixtures/LegacyWorkflowRegistry.php @@ -0,0 +1,26 @@ +addWorkflow($workflow, $supportStrategy); + + return; + } + + parent::add($workflow, $supportStrategy); + } +} diff --git a/tests/Fixtures/StubTranslator.php b/tests/Fixtures/StubTranslator.php new file mode 100644 index 0000000..90d56bf --- /dev/null +++ b/tests/Fixtures/StubTranslator.php @@ -0,0 +1,42 @@ + Date: Thu, 27 Feb 2020 22:18:03 -0300 Subject: [PATCH 2/3] Update `.travis.yml` in order to require "symfony/translation" in a specific version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93aa963..26b5a2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ cache: before_install: - rm -rf composer.lock vendor/ - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/workflow:${SYMFONY_VERSION}" --no-update; fi; + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/workflow:${SYMFONY_VERSION}" "symfony/translation:${SYMFONY_VERSION}" --no-update; fi; install: COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction From ac9f6065c5747c1bd8c5f416dc45d886b07ac56a Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Fri, 28 Feb 2020 08:30:49 -0300 Subject: [PATCH 3/3] Remove dev requirement for "symfony/translation" --- .travis.yml | 2 +- composer.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 26b5a2e..93aa963 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ cache: before_install: - rm -rf composer.lock vendor/ - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/workflow:${SYMFONY_VERSION}" "symfony/translation:${SYMFONY_VERSION}" --no-update; fi; + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/workflow:${SYMFONY_VERSION}" --no-update; fi; install: COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction diff --git a/composer.json b/composer.json index 803b90d..4fe8b1d 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,7 @@ "symfony/workflow": "^3.2|^4.0|^5.0" }, "require-dev": { - "phpunit/phpunit": "^5.0", - "symfony/translation": "^3.4|^4.0|^5.0" + "phpunit/phpunit": "^5.0" }, "minimum-stability": "stable", "extra": {