Skip to content

Commit e98614b

Browse files
authored
Allow Symfony 6.0 & Updated tests according to changes (#51)
1 parent 01744ff commit e98614b

File tree

5 files changed

+104
-37
lines changed

5 files changed

+104
-37
lines changed

.github/workflows/tests.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ jobs:
1616
include:
1717
- php-version: 7.1
1818
symfony-version: 4.4.*
19-
- php-version: 8.0
19+
- php-version: 8.1
2020
symfony-version: 4.4.*
2121
- php-version: 7.2
22-
symfony-version: 5.3.*
22+
symfony-version: 5.4.*
23+
- php-version: 8.1
24+
symfony-version: 5.4.*
2325
- php-version: 8.0
24-
symfony-version: 5.3.*
26+
symfony-version: 6.0.*
27+
- php-version: 8.1
28+
symfony-version: 6.0.*
2529

2630
steps:
2731
- name: "Checkout"
@@ -36,6 +40,7 @@ jobs:
3640
- name: "Install dependencies with composer"
3741
run: |
3842
composer require --no-update symfony/framework-bundle:${{ matrix.symfony-version }}
43+
composer require --no-update --dev symfony/http-kernel:${{ matrix.symfony-version }}
3944
composer require --no-update --dev symfony/form:${{ matrix.symfony-version }}
4045
composer require --no-update --dev symfony/twig-bundle:${{ matrix.symfony-version }}
4146
composer require --no-update --dev symfony/validator:${{ matrix.symfony-version }}
@@ -53,7 +58,7 @@ jobs:
5358
strategy:
5459
matrix:
5560
include:
56-
- php-version: 8.0
61+
- php-version: 8.1
5762

5863
steps:
5964
- name: "Checkout"
@@ -84,7 +89,7 @@ jobs:
8489
strategy:
8590
matrix:
8691
include:
87-
- php-version: 8.0
92+
- php-version: 8.1
8893

8994
steps:
9095
- name: "Checkout"

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
],
1212
"require": {
1313
"php": "^7.1.3|^8.0",
14-
"symfony/framework-bundle": "^4.4|^5.0"
14+
"symfony/framework-bundle": "^4.4|^5.0|^6.0"
1515
},
1616
"require-dev": {
1717
"doctrine/annotations": "^1.3",
1818
"myclabs/php-enum": "^1.7",
1919
"phpunit/phpunit": "^7.5|^8.5|^9.5",
2020
"sensio/framework-extra-bundle": "^5.5|^6.1",
2121
"squizlabs/php_codesniffer": "^3.5",
22-
"symfony/form": "^4.4|^5.0",
23-
"symfony/translation": "^4.4|^5.0",
24-
"symfony/twig-bundle": "^4.4|^5.0",
25-
"symfony/validator": "^4.4|^5.0",
26-
"symfony/yaml": "^4.4|^5.0",
22+
"symfony/form": "^4.4|^5.0|^6.0",
23+
"symfony/translation": "^4.4|^5.0|^6.0",
24+
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
25+
"symfony/validator": "^4.4|^5.0|^6.0",
26+
"symfony/yaml": "^4.4|^5.0|^6.0",
2727
"twig/twig": "^2.0|^3.0"
2828
},
2929
"suggest": {

tests/Integration/src/Kernel.php

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Yokai\EnumBundle\Tests\Integration\App;
66

77
use Symfony\Component\Config\Loader\LoaderInterface;
8+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9+
use Symfony\Component\DependencyInjection\ContainerBuilder;
810
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
911

1012
/**
@@ -36,4 +38,19 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
3638

3739
$loader->load(__DIR__ . '/../config/services.yaml');
3840
}
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
protected function build(ContainerBuilder $container)
46+
{
47+
$container->addCompilerPass(
48+
new class implements CompilerPassInterface {
49+
public function process(ContainerBuilder $container)
50+
{
51+
$container->findDefinition('form.factory')->setPublic(true);
52+
}
53+
}
54+
);
55+
}
3956
}

tests/Integration/tests/PullRequestFormTest.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Integration\tests;
5+
namespace Yokai\EnumBundle\Tests\Integration;
66

77
use Generator;
88
use Psr\Container\ContainerInterface;
@@ -125,11 +125,16 @@ public function testSubmitInvalidData(array $formData, $model, array $errors): v
125125

126126
public function invalid(): Generator
127127
{
128+
$message = 'This value is not valid.';
129+
if (Kernel::MAJOR_VERSION >= 6) {
130+
$message = 'The selected choice is invalid.';
131+
}
132+
128133
$newModel = self::pullRequest();
129134
yield [
130135
['status' => 3, 'labels' => ['bugfix', '5.x']],
131136
$newModel,
132-
['status' => 'This value is not valid.', 'labels' => 'The choices "5.x" do not exist in the choice list.']
137+
['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.']
133138
];
134139

135140
$updateModel = self::pullRequest();
@@ -138,7 +143,7 @@ public function invalid(): Generator
138143
yield [
139144
['status' => 3, 'labels' => ['bugfix', '5.x']],
140145
$updateModel,
141-
['status' => 'This value is not valid.', 'labels' => 'The choices "5.x" do not exist in the choice list.']
146+
['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.']
142147
];
143148
}
144149

tests/Unit/Translator.php

+63-23
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,83 @@
11
<?php
2+
// phpcs:ignoreFile
23

34
declare(strict_types=1);
45

56
namespace Yokai\EnumBundle\Tests\Unit;
67

8+
use Symfony\Component\HttpKernel\Kernel;
79
use Symfony\Contracts\Translation\TranslatorInterface;
810

9-
/**
10-
* @author Yann Eugoné <[email protected]>
11-
*/
12-
class Translator implements TranslatorInterface
13-
{
11+
if (Kernel::MAJOR_VERSION >= 6) {
1412
/**
15-
* @var array
13+
* @author Yann Eugoné <[email protected]>
1614
*/
17-
private $map;
15+
class Translator implements TranslatorInterface
16+
{
17+
/**
18+
* @var array
19+
*/
20+
private $map;
21+
22+
/**
23+
* @var string
24+
*/
25+
private $domain;
1826

27+
public function __construct(array $map, string $domain = 'messages')
28+
{
29+
$this->map = $map;
30+
$this->domain = $domain;
31+
}
32+
33+
public function getLocale(): string
34+
{
35+
return 'fr';
36+
}
37+
38+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
39+
{
40+
if ($domain !== $this->domain) {
41+
return $id;
42+
}
43+
44+
return $this->map[$id] ?? $id;
45+
}
46+
}
47+
} else {
1948
/**
20-
* @var string
49+
* @author Yann Eugoné <[email protected]>
2150
*/
22-
private $domain;
23-
24-
public function __construct(array $map, string $domain = 'messages')
51+
class Translator implements TranslatorInterface
2552
{
26-
$this->map = $map;
27-
$this->domain = $domain;
28-
}
53+
/**
54+
* @var array
55+
*/
56+
private $map;
2957

30-
public function getLocale(): string
31-
{
32-
return 'fr';
33-
}
58+
/**
59+
* @var string
60+
*/
61+
private $domain;
3462

35-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
36-
{
37-
if ($domain !== $this->domain) {
38-
return $id;
63+
public function __construct(array $map, string $domain = 'messages')
64+
{
65+
$this->map = $map;
66+
$this->domain = $domain;
3967
}
4068

41-
return $this->map[$id] ?? $id;
69+
public function getLocale(): string
70+
{
71+
return 'fr';
72+
}
73+
74+
public function trans($id, array $parameters = [], $domain = null, $locale = null)
75+
{
76+
if ($domain !== $this->domain) {
77+
return $id;
78+
}
79+
80+
return $this->map[$id] ?? $id;
81+
}
4282
}
4383
}

0 commit comments

Comments
 (0)