Skip to content

Commit

Permalink
feature #74 Allow Symfony5 (benji07)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x-dev branch.

Discussion
----------

Allow Symfony5

Commits
-------

8044cfd Allow Symfony5
  • Loading branch information
ogizanagi committed Jan 14, 2020
2 parents 7a8ed35 + 8044cfd commit 5e5884a
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 199 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ return PhpCsFixer\Config::create()
'yoda_style' => null,
'no_unneeded_final_method' => false, // final private __construct is a valid use-case
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'single_line_throw' => false,
])
;
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ matrix:
env:
- SYMFONY_VERSION="3.4.*"
- COMPOSER_FLAGS="--prefer-lowest"
- SYMFONY_PHPUNIT_VERSION=5.7

# most recent versions:
- SYMFONY_DEPRECATIONS_HELPER=weak_vendors
- SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1
- php: 7.3
env:
- SYMFONY_VERSION="4.2.*"
- SYMFONY_VERSION="4.4.*"
- CHECK_CODE_STYLE="yes"
# most recent versions:
- php: 7.3
env:
- SYMFONY_VERSION="4.3.*"
- SYMFONY_VERSION="5.0.*"
- CHECK_CODE_STYLE="yes"

# bleeding edge (unreleased dev versions where failures are allowed):
- php: 7.4snapshot
env: SYMFONY_VERSION="4.4.*"
allow_failures:
- php: 7.4snapshot
- php: 7.4
env:
- SYMFONY_VERSION="5.0.*"
- CHECK_CODE_STYLE="yes"

cache:
directories:
Expand Down
40 changes: 20 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@
"require-dev": {
"doctrine/data-fixtures": "^1.2",
"doctrine/dbal": "^2.4",
"doctrine/doctrine-bundle": "^1.4",
"doctrine/doctrine-bundle": "^1.4|^2.0",
"doctrine/orm": "^2.4",
"friendsofphp/php-cs-fixer": "^2.12.0",
"nelmio/alice": "^3.0",
"phpspec/prophecy": "~1.0",
"symfony/phpunit-bridge": "^3.4|^4.2",
"symfony/browser-kit": "^3.4|^4.2",
"symfony/css-selector": "^3.4|^4.2",
"symfony/console": "^3.4|^4.2",
"symfony/dependency-injection": "^3.4|^4.2",
"symfony/doctrine-bridge": "^3.4|^4.2",
"symfony/dom-crawler": "^3.4|^4.2",
"symfony/filesystem": "^3.4|^4.2",
"symfony/finder": "^3.4|^4.2",
"symfony/form": "^3.4|^4.2",
"symfony/framework-bundle": "^3.4|^4.2",
"symfony/http-foundation": "^3.4|^4.2",
"symfony/serializer": "^3.4|^4.2",
"symfony/translation": "^3.4|^4.2",
"symfony/twig-bundle": "^3.4|^4.2",
"symfony/validator": "^3.4|^4.2",
"symfony/templating": "^3.4|^4.2",
"symfony/yaml": "^3.4|^4.2",
"symfony/var-dumper": "^3.4|^4.2"
"symfony/phpunit-bridge": "^3.4|^4.4|^5.0",
"symfony/browser-kit": "^3.4|^4.4|^5.0",
"symfony/css-selector": "^3.4|^4.4|^5.0",
"symfony/console": "^3.4|^4.4|^5.0",
"symfony/dependency-injection": "^3.4|^4.4|^5.0",
"symfony/doctrine-bridge": "^3.4|^4.4|^5.0",
"symfony/dom-crawler": "^3.4|^4.4|^5.0",
"symfony/filesystem": "^3.4|^4.4|^5.0",
"symfony/finder": "^3.4|^4.4|^5.0",
"symfony/form": "^3.4|^4.4|^5.0",
"symfony/framework-bundle": "^3.4|^4.4|^5.0",
"symfony/http-foundation": "^3.4|^4.4|^5.0",
"symfony/serializer": "^3.4|^4.4|^5.0",
"symfony/translation": "^3.4|^4.4|^5.0",
"symfony/twig-bundle": "^3.4|^4.4|^5.0",
"symfony/validator": "^3.4|^4.4|^5.0",
"symfony/templating": "^3.4|^4.4|^5.0",
"symfony/yaml": "^3.4|^4.4|^5.0",
"symfony/var-dumper": "^3.4|^4.4|^5.0"
},
"extra": {
"branch-alias": {
Expand Down
2 changes: 0 additions & 2 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ abstract class AbstractEnumType extends Type
{
/**
* The enum FQCN for which we should make the DBAL conversion.
*
* @return string
*/
abstract protected function getEnumClass(): string;

Expand Down
8 changes: 0 additions & 8 deletions src/Bridge/Faker/Provider/EnumProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(array $enumMapping = [])
* Examples: 'Gender::MALE', 'App\Enum\Gender::FEMALE', 'Permissions::READ|WRITE', etc.
*
* @throws InvalidArgumentException When the alias part of $enumValueShortcut is not a valid alias
*
* @return EnumInterface
*/
public function enum(string $enumValueShortcut): EnumInterface
{
Expand Down Expand Up @@ -78,11 +76,7 @@ public function enum(string $enumValueShortcut): EnumInterface
}

/**
* @param string $enumClassOrAlias
*
* @throws InvalidArgumentException When $enumClassAlias is not a valid alias
*
* @return EnumInterface
*/
public function randomEnum(string $enumClassOrAlias): EnumInterface
{
Expand All @@ -99,8 +93,6 @@ public function randomEnum(string $enumClassOrAlias): EnumInterface
/**
* Make sure that $enumClass is a proper Enum class. Throws exception otherwise.
*
* @param string $enumClass
*
* @throws InvalidArgumentException When $enumClass is not a class or is not a proper Enum
*/
private function ensureEnumClass(string $enumClass)
Expand Down
4 changes: 0 additions & 4 deletions src/EnumInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ public function getValue();
* Determines whether two enumerations instances should be considered the same.
*
* @param EnumInterface $enum An enum object to compare with this instance
*
* @return bool
*/
public function equals(EnumInterface $enum): bool;

/**
* Determines if the enumeration instance value is equal to the given value.
*
* @param int|string $value
*
* @return bool
*/
public function is($value): bool;
}
6 changes: 0 additions & 6 deletions src/FlaggedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public static function readableFor($value, string $separator = '; '): string

/**
* Gets the human representation for the none value.
*
* @return string
*/
protected static function readableForNone(): string
{
Expand All @@ -105,8 +103,6 @@ protected static function readableForNone(): string
* Gets an integer value of the possible flags for enumeration.
*
* @throws LogicException If the possibles values are not valid bit flags
*
* @return int
*/
private static function getBitmask(): int
{
Expand Down Expand Up @@ -142,8 +138,6 @@ public function getReadable(string $separator = '; '): string

/**
* Gets an array of bit flags of the value.
*
* @return array
*/
public function getFlags(): array
{
Expand Down
2 changes: 0 additions & 2 deletions src/ReadableEnumInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public static function readableFor($value): string;

/**
* Gets the human representation of the value.
*
* @return string
*/
public function getReadable(): string;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Integration/Symfony/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ framework:
test: ~
session:
storage_id: 'session.storage.mock_file'
templating: false
assets: false

twig:
strict_variables: false
paths:
'%kernel.project_dir%/templates': tests
exception_controller: null

doctrine:
dbal:
Expand Down
49 changes: 49 additions & 0 deletions tests/Fixtures/Integration/Symfony/config/config_34.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
framework:
secret: 'elao'
form: true
router:
resource: '%kernel.project_dir%/config/routing.yml'
strict_requirements: '%kernel.debug%'
test: ~
session:
storage_id: 'session.storage.mock_file'
assets: false

twig:
strict_variables: false
paths:
'%kernel.project_dir%/templates': tests

doctrine:
dbal:
driver: 'pdo_sqlite'
path: '%kernel.cache_dir%/db.sqlite'
charset: 'UTF8'
types:
gender: 'Elao\Enum\Tests\Fixtures\Bridge\Doctrine\DBAL\Types\GenderEnumType'

orm:
auto_generate_proxy_classes: '%kernel.debug%'
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App

services:
logger:
class: Psr\Log\NullLogger
public: false

Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\EnumValueResolver:
class: Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\EnumValueResolver
tags:
- { name: controller.argument_value_resolver, priority: 101 }

controllers:
namespace: App\Controller\
resource: '%kernel.project_dir%/src/Controller'
autowire: true
autoconfigure: true
6 changes: 5 additions & 1 deletion tests/Fixtures/Integration/Symfony/src/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public function registerBundles()

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getProjectDir() . '/config/config.yml');
if (self::MAJOR_VERSION < 4) {
$loader->load($this->getProjectDir() . '/config/config_34.yml');
} else {
$loader->load($this->getProjectDir() . '/config/config.yml');
}
}

public function getProjectDir()
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Bridge/Doctrine/DBAL/Type/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EnumTypeTest extends KernelTestCase
/** @var EntityManagerInterface */
private $em;

protected function setUp()
protected function setUp(): void
{
static::bootKernel();
$kernel = static::$kernel;
Expand All @@ -30,7 +30,7 @@ protected function setUp()
(new ORMPurger($this->em))->purge();
}

protected function tearDown()
protected function tearDown(): void
{
$this->em->close();
$this->em = null;
Expand Down
9 changes: 4 additions & 5 deletions tests/Integration/Bridge/Symfony/ArgumentResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

use Elao\Enum\Tests\Fixtures\Enum\Gender;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;

class ArgumentResolverTest extends WebTestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!interface_exists(ArgumentValueResolverInterface::class)) {
self::markTestSkipped(
Expand All @@ -42,7 +41,7 @@ public function requestProvider()
{
return [
'valid enum' => [
function (Client $client) {
function ($client) {
$client->request(Request::METHOD_GET, '/enum-resolve/' . Gender::MALE);
},
function (Response $response) {
Expand All @@ -51,15 +50,15 @@ function (Response $response) {
},
],
'invalid enum' => [
function (Client $client) {
function ($client) {
$client->request(Request::METHOD_GET, '/enum-resolve/bar');
},
function (Response $response) {
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
},
],
'valid variadic enum' => [
function (Client $client) {
function ($client) {
$client->request(Request::METHOD_GET, '/enum-resolve-variadic', ['genders' => [Gender::MALE, Gender::FEMALE]]);
},
function (Response $response) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/AutoDiscoveredValuesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Elao\Enum\AutoDiscoveredValuesTrait;
use Elao\Enum\Enum;
use Elao\Enum\Exception\LogicException;
use Elao\Enum\FlaggedEnum;
use Elao\Enum\Tests\Fixtures\Enum\Php71AutoDiscoveredEnum;
use PHPUnit\Framework\TestCase;
Expand All @@ -36,12 +37,11 @@ public function testItAutoDiscoveredValuesBasedOnAvailableBitFlagConstants()
$this->assertSame([1, 2, 4], AutoDiscoveredFlaggedEnum::values());
}

/**
* @expectedException \Elao\Enum\Exception\LogicException
* @expectedExceptionMessage Method "Elao\Enum\AutoDiscoveredValuesTrait::choices" is only meant to be used when using the "Elao\Enum\ChoiceEnumTrait" trait which is not used in "Elao\Enum\Tests\Unit\AutoDiscoveredEnumMisusingChoices"
*/
public function testThrowsOnChoicesMisuses()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Method "Elao\Enum\AutoDiscoveredValuesTrait::choices" is only meant to be used when using the "Elao\Enum\ChoiceEnumTrait" trait which is not used in "Elao\Enum\Tests\Unit\AutoDiscoveredEnumMisusingChoices"');

AutoDiscoveredEnumMisusingChoices::foo();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Bridge/Doctrine/DBAL/Types/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class EnumTypeTest extends TestCase
/** @var GenderEnumType */
protected $type;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
Type::addType(GenderEnumType::NAME, GenderEnumType::class);
}

/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->platform = $this->prophesize(AbstractPlatform::class)->reveal();
$this->type = Type::getType(GenderEnumType::NAME);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Bridge/Doctrine/DBAL/Types/IntegerEnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class IntegerEnumTypeTest extends TestCase
/** @var SimpleEnumType */
protected $type;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
Type::addType(SimpleEnumType::NAME, SimpleEnumType::class);
}

/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->platform = $this->prophesize(AbstractPlatform::class)->reveal();
$this->type = Type::getType(SimpleEnumType::NAME);
Expand Down
Loading

0 comments on commit 5e5884a

Please sign in to comment.