Skip to content

Commit

Permalink
Allow Symfony 6.0 & Updated tests according to changes (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-eugone authored Dec 23, 2021
1 parent 01744ff commit e98614b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 37 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ jobs:
include:
- php-version: 7.1
symfony-version: 4.4.*
- php-version: 8.0
- php-version: 8.1
symfony-version: 4.4.*
- php-version: 7.2
symfony-version: 5.3.*
symfony-version: 5.4.*
- php-version: 8.1
symfony-version: 5.4.*
- php-version: 8.0
symfony-version: 5.3.*
symfony-version: 6.0.*
- php-version: 8.1
symfony-version: 6.0.*

steps:
- name: "Checkout"
Expand All @@ -36,6 +40,7 @@ jobs:
- name: "Install dependencies with composer"
run: |
composer require --no-update symfony/framework-bundle:${{ matrix.symfony-version }}
composer require --no-update --dev symfony/http-kernel:${{ matrix.symfony-version }}
composer require --no-update --dev symfony/form:${{ matrix.symfony-version }}
composer require --no-update --dev symfony/twig-bundle:${{ matrix.symfony-version }}
composer require --no-update --dev symfony/validator:${{ matrix.symfony-version }}
Expand All @@ -53,7 +58,7 @@ jobs:
strategy:
matrix:
include:
- php-version: 8.0
- php-version: 8.1

steps:
- name: "Checkout"
Expand Down Expand Up @@ -84,7 +89,7 @@ jobs:
strategy:
matrix:
include:
- php-version: 8.0
- php-version: 8.1

steps:
- name: "Checkout"
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
],
"require": {
"php": "^7.1.3|^8.0",
"symfony/framework-bundle": "^4.4|^5.0"
"symfony/framework-bundle": "^4.4|^5.0|^6.0"
},
"require-dev": {
"doctrine/annotations": "^1.3",
"myclabs/php-enum": "^1.7",
"phpunit/phpunit": "^7.5|^8.5|^9.5",
"sensio/framework-extra-bundle": "^5.5|^6.1",
"squizlabs/php_codesniffer": "^3.5",
"symfony/form": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"symfony/validator": "^4.4|^5.0",
"symfony/yaml": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0|^6.0",
"symfony/translation": "^4.4|^5.0|^6.0",
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
"symfony/validator": "^4.4|^5.0|^6.0",
"symfony/yaml": "^4.4|^5.0|^6.0",
"twig/twig": "^2.0|^3.0"
},
"suggest": {
Expand Down
17 changes: 17 additions & 0 deletions tests/Integration/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Yokai\EnumBundle\Tests\Integration\App;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

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

$loader->load(__DIR__ . '/../config/services.yaml');
}

/**
* @inheritDoc
*/
protected function build(ContainerBuilder $container)
{
$container->addCompilerPass(
new class implements CompilerPassInterface {
public function process(ContainerBuilder $container)
{
$container->findDefinition('form.factory')->setPublic(true);
}
}
);
}
}
11 changes: 8 additions & 3 deletions tests/Integration/tests/PullRequestFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Integration\tests;
namespace Yokai\EnumBundle\Tests\Integration;

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

public function invalid(): Generator
{
$message = 'This value is not valid.';
if (Kernel::MAJOR_VERSION >= 6) {
$message = 'The selected choice is invalid.';
}

$newModel = self::pullRequest();
yield [
['status' => 3, 'labels' => ['bugfix', '5.x']],
$newModel,
['status' => 'This value is not valid.', 'labels' => 'The choices "5.x" do not exist in the choice list.']
['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.']
];

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

Expand Down
86 changes: 63 additions & 23 deletions tests/Unit/Translator.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,83 @@
<?php
// phpcs:ignoreFile

declare(strict_types=1);

namespace Yokai\EnumBundle\Tests\Unit;

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
class Translator implements TranslatorInterface
{
if (Kernel::MAJOR_VERSION >= 6) {
/**
* @var array
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
private $map;
class Translator implements TranslatorInterface
{
/**
* @var array
*/
private $map;

/**
* @var string
*/
private $domain;

public function __construct(array $map, string $domain = 'messages')
{
$this->map = $map;
$this->domain = $domain;
}

public function getLocale(): string
{
return 'fr';
}

public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
{
if ($domain !== $this->domain) {
return $id;
}

return $this->map[$id] ?? $id;
}
}
} else {
/**
* @var string
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
private $domain;

public function __construct(array $map, string $domain = 'messages')
class Translator implements TranslatorInterface
{
$this->map = $map;
$this->domain = $domain;
}
/**
* @var array
*/
private $map;

public function getLocale(): string
{
return 'fr';
}
/**
* @var string
*/
private $domain;

public function trans($id, array $parameters = [], $domain = null, $locale = null)
{
if ($domain !== $this->domain) {
return $id;
public function __construct(array $map, string $domain = 'messages')
{
$this->map = $map;
$this->domain = $domain;
}

return $this->map[$id] ?? $id;
public function getLocale(): string
{
return 'fr';
}

public function trans($id, array $parameters = [], $domain = null, $locale = null)
{
if ($domain !== $this->domain) {
return $id;
}

return $this->map[$id] ?? $id;
}
}
}

0 comments on commit e98614b

Please sign in to comment.