Skip to content

Commit 3705681

Browse files
authored
Merge pull request #17 from phansys/tests
Tests on PHP 7.4 & Symfony 5.0
2 parents cdf1396 + ac9f606 commit 3705681

File tree

7 files changed

+125
-13
lines changed

7 files changed

+125
-13
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ php:
55
- 7.1
66
- 7.2
77
- 7.3
8+
- 7.4
89

910
env:
1011
- SYMFONY_VERSION="3.4.*"
1112
- SYMFONY_VERSION="4.2.*"
1213
- SYMFONY_VERSION="4.3.*"
14+
- SYMFONY_VERSION="4.4.*"
15+
- SYMFONY_VERSION="5.0.*"
1316

1417
matrix:
1518
exclude:
@@ -18,6 +21,13 @@ matrix:
1821
env: SYMFONY_VERSION="4.2.*"
1922
- php: 7.0
2023
env: SYMFONY_VERSION="4.3.*"
24+
- php: 7.0
25+
env: SYMFONY_VERSION="4.4.*"
26+
- php: 7.0
27+
env: SYMFONY_VERSION="5.0.*"
28+
# Symfony >= 5.0 PHP requirement is ^7.2.5
29+
- php: 7.1
30+
env: SYMFONY_VERSION="5.0.*"
2131

2232
sudo: false
2333

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ This library add Symfony Workflow component integration within Sonata Admin.
2424

2525
### Code
2626

27-
- a Sonata Admin [Extension](https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html) :
27+
- a Sonata Admin [Extension](https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html) :
2828
[WorkflowExtension](src/Admin/Extension/WorkflowExtension.php)
29-
- a Controller trait :
29+
- a Controller trait :
3030
[WorkflowControllerTrait](src/Controller/WorkflowControllerTrait.php)
31-
- a Controller :
31+
- a Controller :
3232
[WorkflowController](src/Controller/WorkflowController.php)
3333

3434

@@ -44,6 +44,7 @@ Configuration
4444

4545
Let say that you have an entity named `PullRequest` that is under workflow and for which you have an admin.
4646

47+
#### symfony/workflow <4.3
4748
```yaml
4849
# config/packages/workflow.yml
4950
framework:
@@ -74,11 +75,42 @@ framework:
7475
to: closed
7576
```
7677
78+
#### symfony/workflow ^4.3|^5.0
79+
```yaml
80+
# config/packages/workflow.yml
81+
framework:
82+
workflows:
83+
pull_request:
84+
type: state_machine
85+
marking_store:
86+
type: state_machine
87+
property: status
88+
supports:
89+
- App\Entity\PullRequest
90+
places:
91+
- opened
92+
- pending_review
93+
- merged
94+
- closed
95+
initial_marking:
96+
- opened
97+
transitions:
98+
start_review:
99+
from: opened
100+
to: pending_review
101+
merge:
102+
from: pending_review
103+
to: merged
104+
close:
105+
from: pending_review
106+
to: closed
107+
```
108+
77109
### One extension for everything
78110
79111
The extension is usable for many entities and with no configuration.
80112
81-
You only need to create a service for it, configure the controller that will handle the transition action
113+
You only need to create a service for it, configure the controller that will handle the transition action
82114
and configure on which admin you want it available.
83115
84116
For instance :
@@ -108,7 +140,7 @@ sonata_admin:
108140
- admin.pull_request
109141
```
110142
111-
> **note**: You may noticed that we also registered the controller
143+
> **note**: You may noticed that we also registered the controller
112144
`Yokai\SonataWorkflow\Controller\WorkflowController` as a service.
113145
It is important, because it needs the workflow registry service to work.
114146

@@ -170,12 +202,12 @@ What are these options ?
170202
Hook into the transition process
171203
--------------------------------
172204

173-
Let say that when you start a review for a pull request, as a user,
205+
Let say that when you start a review for a pull request, as a user,
174206
you will be asked to enter which users are involved in the review.
175207

176208
To achieve this, you will be asked to fill a dedicated form.
177209

178-
You only need to create a custom controller for your entity admin :
210+
You only need to create a custom controller for your entity admin :
179211

180212
```yaml
181213
# config/packages/sonata_admin.yml

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
}
2626
},
2727
"require": {
28-
"php": "^5.6||^7.0",
28+
"php": "^5.6|^7.0",
2929
"sonata-project/admin-bundle": "^3.0",
30-
"symfony/workflow": "^3.2|^4.0"
30+
"symfony/workflow": "^3.2|^4.0|^5.0"
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "^5.0"

tests/Admin/Extension/WorkflowExtensionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Workflow\Registry;
1313
use Symfony\Component\Workflow\StateMachine;
1414
use Yokai\SonataWorkflow\Admin\Extension\WorkflowExtension;
15+
use Yokai\SonataWorkflow\Tests\Fixtures\LegacyWorkflowRegistry;
1516
use Yokai\SonataWorkflow\Controller\WorkflowController;
1617
use Yokai\SonataWorkflow\Tests\PullRequest;
1718

@@ -56,7 +57,7 @@ public function testAlterNewInstance()
5657
/** @var AdminInterface|ObjectProphecy $admin */
5758
$admin = $this->prophesize(AdminInterface::class);
5859

59-
$registry = new Registry();
60+
$registry = new LegacyWorkflowRegistry();
6061
$registry->add(
6162
new StateMachine(PullRequest::createWorkflowDefinition()),
6263
PullRequest::createSupportStrategy()
@@ -118,7 +119,7 @@ public function testConfigureSideMenu($marking, array $transitions)
118119
->willReturn('/pull-request/42/workflow/transition/'.$transition.'/apply');
119120
}
120121

121-
$registry = new Registry();
122+
$registry = new LegacyWorkflowRegistry();
122123
$registry->add(
123124
new StateMachine(PullRequest::createWorkflowDefinition()),
124125
PullRequest::createSupportStrategy()

tests/Controller/WorkflowControllerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Sonata\AdminBundle\Exception\LockException;
99
use Sonata\AdminBundle\Exception\ModelManagerException;
1010
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
11-
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
1211
use Symfony\Component\DependencyInjection\ContainerInterface;
1312
use Symfony\Component\HttpFoundation\JsonResponse;
1413
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -20,6 +19,8 @@
2019
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
2120
use Symfony\Component\Workflow\Registry;
2221
use Symfony\Component\Workflow\StateMachine;
22+
use Yokai\SonataWorkflow\Tests\Fixtures\LegacyWorkflowRegistry;
23+
use Yokai\SonataWorkflow\Tests\Fixtures\StubTranslator;
2324
use Yokai\SonataWorkflow\Tests\PullRequest;
2425
use Yokai\SonataWorkflow\Tests\PullRequestWorkflowController;
2526
use Yokai\SonataWorkflow\Tests\TestKernel;
@@ -63,7 +64,7 @@ public function setUp()
6364
{
6465
$this->container = $this->prophesize(ContainerInterface::class);
6566
$this->admin = $this->prophesize(AdminInterface::class);
66-
$this->registry = new Registry();
67+
$this->registry = new LegacyWorkflowRegistry();
6768
$this->flashBag = new FlashBag();
6869
$this->translator = new StubTranslator();
6970

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yokai\SonataWorkflow\Tests\Fixtures;
6+
7+
use Symfony\Component\Workflow\Registry;
8+
use Symfony\Component\Workflow\Workflow;
9+
10+
/**
11+
* This class is provided in order to allow tests to call `add()` method, which
12+
* is deprecated since symfony/workflow 4.1 and was removed in version 5.0.
13+
*/
14+
final class LegacyWorkflowRegistry extends Registry
15+
{
16+
public function add(Workflow $workflow, $supportStrategy)
17+
{
18+
if (method_exists($this, 'addWorkflow')) {
19+
$this->addWorkflow($workflow, $supportStrategy);
20+
21+
return;
22+
}
23+
24+
parent::add($workflow, $supportStrategy);
25+
}
26+
}

tests/Fixtures/StubTranslator.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yokai\SonataWorkflow\Tests\Fixtures;
6+
7+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
8+
use Symfony\Contracts\Translation\TranslatorInterface;
9+
10+
/**
11+
* `StubTranslator` provides a simple implementation for the "translator" service.
12+
*/
13+
if (interface_exists(TranslatorInterface::class)) {
14+
final class StubTranslator implements TranslatorInterface
15+
{
16+
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
17+
{
18+
return '[trans]'.strtr($id, $parameters).'[/trans]';
19+
}
20+
}
21+
} else {
22+
final class StubTranslator implements LegacyTranslatorInterface
23+
{
24+
public function trans($id, array $parameters = [], $domain = null, $locale = null)
25+
{
26+
return '[trans]'.$id.'[/trans]';
27+
}
28+
29+
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
30+
{
31+
return '[trans]'.$id.'[/trans]';
32+
}
33+
34+
public function setLocale($locale)
35+
{
36+
}
37+
38+
public function getLocale()
39+
{
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)