Skip to content

Commit 71f7eaa

Browse files
authored
Symfony 5.1 and Doctrine 3.0
1 parent 1258a87 commit 71f7eaa

12 files changed

+70
-44
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ sudo: false
55
cache:
66
directories:
77
- $HOME/.composer/cache/files
8-
- $HOME/symfony-bridge/.phpunit
98

109
php:
1110
- 7.2
@@ -15,8 +14,8 @@ php:
1514
env:
1615
global:
1716
- PHPUNIT_FLAGS="-v"
18-
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
1917
jobs:
18+
- SYMFONY_VERSION=5.1.*
2019
- SYMFONY_VERSION=5.0.*
2120

2221
stages:
@@ -32,23 +31,23 @@ jobs:
3231
# Composer validation
3332
- stage: composer validation
3433
php: 7.2
35-
env: SYMFONY_VERSION=5.0.*
34+
env: SYMFONY_VERSION=5.1.*
3635
script:
3736
- composer validate --strict --no-check-lock
3837
# Code style
3938
- stage: code style
4039
php: 7.2
41-
env: SYMFONY_VERSION=5.0.*
40+
env: SYMFONY_VERSION=5.1.*
4241
script: ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore="vendor|Tests" --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony
4342
# PHPStan analyze
4443
- stage: static analyze
4544
php: 7.2
46-
env: SYMFONY_VERSION=5.0.*
47-
script: ./vendor/bin/phpstan analyse -l 7 --no-progress -c phpstan.neon ./
45+
env: SYMFONY_VERSION=5.1.*
46+
script: ./vendor/bin/phpstan analyse --no-progress -c phpstan.neon ./
4847
# Code coverage with Codecov.io
4948
- stage: code coverage
5049
php: 7.2
51-
env: COVERAGE=true SYMFONY_VERSION=5.0.*
50+
env: COVERAGE=true SYMFONY_VERSION=5.1.*
5251
script:
5352
- ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml
5453
after_script:
@@ -65,7 +64,7 @@ install:
6564
- composer install --no-interaction --prefer-dist
6665

6766
script:
68-
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAG -c phpunit.xml.dist
67+
- ./vendor/bin/phpunit $PHPUNIT_FLAG -c phpunit.xml.dist
6968

7069
notifications:
7170
email:

Form/EnumTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(ManagerRegistry $registry, array $registeredTypes)
5252
*
5353
* @throws EnumTypeIsRegisteredButClassDoesNotExistException
5454
*/
55-
public function guessType($class, $property): ?TypeGuess
55+
public function guessType(string $class, string $property): ?TypeGuess
5656
{
5757
$classMetadata = $this->getMetadata($class);
5858

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#### Check the `config/bundles.php` file
3434

35-
By default Symfony Flex will add this bundle to the `config/bundles.php` file.
35+
By default, Symfony Flex will add this bundle to the `config/bundles.php` file.
3636
But in case when you ignored `contrib-recipe` during bundle installation it would not be added. In this case add the bundle manually.
3737

3838
```php

Tests/DBAL/Types/AbstractEnumTypeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ protected function tearDown(): void
5555

5656
/**
5757
* @dataProvider platformProvider
58+
*
59+
* @param array $fieldDeclaration
60+
* @param AbstractPlatform $platform
61+
* @param string $expected
5862
*/
5963
public function testGetSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform, string $expected): void
6064
{

Tests/Fixtures/DBAL/Types/BasketballPositionType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ final class BasketballPositionType extends AbstractEnumType
3030
/** @var string */
3131
protected $name = 'BasketballPositionType';
3232

33+
/**
34+
* {@inheritdoc}
35+
*/
3336
protected static $choices = [
3437
self::POINT_GUARD => 'Point Guard',
3538
self::SHOOTING_GUARD => 'Shooting Guard',

Tests/Fixtures/DBAL/Types/MapLocationType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ final class MapLocationType extends AbstractEnumType
3434
/** @var string */
3535
protected $name = 'MapLocationType';
3636

37+
/**
38+
* {@inheritdoc}
39+
*/
3740
protected static $choices = [
3841
self::NORTH => 'North',
3942
self::EAST => 'East',

Tests/Fixtures/DBAL/Types/NumericType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ final class NumericType extends AbstractEnumType
3030
/** @var string */
3131
protected $name = 'NumericType';
3232

33+
/**
34+
* {@inheritdoc}
35+
*/
3336
protected static $choices = [
3437
self::ZERO => 0,
3538
self::ONE => 1,

Tests/Twig/Extension/EnumConstantExtensionTest.php renamed to Tests/Twig/Extension/EnumConstantTwigExtensionTest.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
use Twig\TwigFilter;
2525

2626
/**
27-
* EnumConstantExtensionTest.
27+
* EnumConstantTwigExtensionTest.
2828
*
2929
* @author Artem Henvald <genvaldartem@gmail.com>
3030
*/
31-
final class EnumConstantExtensionTest extends TestCase
31+
final class EnumConstantTwigExtensionTest extends TestCase
3232
{
3333
/** @var EnumConstantTwigExtension */
34-
private $enumConstantExtension;
34+
private $enumConstantTwigExtension;
3535

3636
protected function setUp(): void
3737
{
38-
$this->enumConstantExtension = new EnumConstantTwigExtension([
38+
$this->enumConstantTwigExtension = new EnumConstantTwigExtension([
3939
'BasketballPositionType' => ['class' => BasketballPositionType::class],
4040
'MapLocationType' => ['class' => MapLocationType::class],
4141
'NumericType' => ['class' => NumericType::class],
@@ -44,25 +44,29 @@ protected function setUp(): void
4444

4545
protected function tearDown(): void
4646
{
47-
unset($this->enumConstantExtension);
47+
unset($this->enumConstantTwigExtension);
4848
}
4949

5050
public function testGetFilters(): void
5151
{
5252
self::assertEquals(
53-
[new TwigFilter('enum_constant', [$this->enumConstantExtension, 'getEnumConstant'])],
54-
$this->enumConstantExtension->getFilters()
53+
[new TwigFilter('enum_constant', [$this->enumConstantTwigExtension, 'getEnumConstant'])],
54+
$this->enumConstantTwigExtension->getFilters()
5555
);
5656
}
5757

5858
/**
5959
* @dataProvider dataProviderForGetEnumConstantTest
60+
*
61+
* @param string $expectedValueOfConstant
62+
* @param string $enumConstant
63+
* @param string|null $enumType
6064
*/
6165
public function testGetEnumConstant(string $expectedValueOfConstant, string $enumConstant, ?string $enumType): void
6266
{
6367
self::assertEquals(
6468
$expectedValueOfConstant,
65-
$this->enumConstantExtension->getEnumConstant($enumConstant, $enumType)
69+
$this->enumConstantTwigExtension->getEnumConstant($enumConstant, $enumType)
6670
);
6771
}
6872

@@ -78,19 +82,19 @@ public function dataProviderForGetEnumConstantTest(): iterable
7882
public function testEnumTypeIsNotRegisteredException(): void
7983
{
8084
$this->expectException(EnumTypeIsNotRegisteredException::class);
81-
$this->enumConstantExtension->getEnumConstant('Pitcher', 'BaseballPositionType');
85+
$this->enumConstantTwigExtension->getEnumConstant('Pitcher', 'BaseballPositionType');
8286
}
8387

8488
public function testConstantIsFoundInFewRegisteredEnumTypesException(): void
8589
{
8690
$this->expectException(ConstantIsFoundInFewRegisteredEnumTypesException::class);
87-
$this->enumConstantExtension->getEnumConstant('CENTER');
91+
$this->enumConstantTwigExtension->getEnumConstant('CENTER');
8892
}
8993

9094
public function testConstantIsNotFoundInAnyRegisteredEnumTypeException(): void
9195
{
9296
$this->expectException(ConstantIsNotFoundInAnyRegisteredEnumTypeException::class);
93-
$this->enumConstantExtension->getEnumConstant('Pitcher');
97+
$this->enumConstantTwigExtension->getEnumConstant('Pitcher');
9498
}
9599

96100
public function testNoRegisteredEnumTypesException(): void

Tests/Twig/Extension/EnumValuesAsArrayExtensionTest.php renamed to Tests/Twig/Extension/EnumValuesAsArrayTwigExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
use Twig\TwigFunction;
2222

2323
/**
24-
* EnumValuesAsArrayExtensionTest.
24+
* EnumValuesAsArrayTwigExtensionTest.
2525
*
2626
* @author Artem Henvald <genvaldartem@gmail.com>
2727
*/
28-
final class EnumValuesAsArrayExtensionTest extends TestCase
28+
final class EnumValuesAsArrayTwigExtensionTest extends TestCase
2929
{
3030
/** @var EnumValuesAsArrayTwigExtension */
3131
private $enumValuesAsArrayTwigExtension;

Tests/Twig/Extension/ReadableEnumValueExtensionTest.php renamed to Tests/Twig/Extension/ReadableEnumValueTwigExtensionTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,52 @@
2323
use Twig\TwigFilter;
2424

2525
/**
26-
* ReadableEnumValueExtensionTest.
26+
* ReadableEnumValueTwigExtensionTest.
2727
*
2828
* @author Artem Henvald <genvaldartem@gmail.com>
2929
*/
30-
final class ReadableEnumValueExtensionTest extends TestCase
30+
final class ReadableEnumValueTwigExtensionTest extends TestCase
3131
{
3232
/** @var ReadableEnumValueTwigExtension */
33-
private $readableEnumValueExtension;
33+
private $readableEnumValueTwigExtension;
3434

3535
protected function setUp(): void
3636
{
37-
$this->readableEnumValueExtension = new ReadableEnumValueTwigExtension([
37+
$this->readableEnumValueTwigExtension = new ReadableEnumValueTwigExtension([
3838
'BasketballPositionType' => ['class' => BasketballPositionType::class],
3939
'MapLocationType' => ['class' => MapLocationType::class],
4040
]);
4141
}
4242

4343
protected function tearDown(): void
4444
{
45-
unset($this->readableEnumValueExtension);
45+
unset($this->readableEnumValueTwigExtension);
4646
}
4747

4848
public function testGetFilters(): void
4949
{
5050
self::assertEquals(
51-
[new TwigFilter('readable_enum', [$this->readableEnumValueExtension, 'getReadableEnumValue'])],
52-
$this->readableEnumValueExtension->getFilters()
51+
[new TwigFilter('readable_enum', [$this->readableEnumValueTwigExtension, 'getReadableEnumValue'])],
52+
$this->readableEnumValueTwigExtension->getFilters()
5353
);
5454
}
5555

56-
/** @dataProvider dataProviderForGetReadableEnumValueTest */
56+
/**
57+
* @dataProvider dataProviderForGetReadableEnumValueTest
58+
*
59+
* @param string|null $expectedReadableValue
60+
* @param string|null $enumValue
61+
* @param string|null $enumType
62+
*/
5763
public function testGetReadableEnumValue(?string $expectedReadableValue, ?string $enumValue, ?string $enumType): void
5864
{
5965
self::assertEquals(
6066
$expectedReadableValue,
61-
$this->readableEnumValueExtension->getReadableEnumValue($enumValue, $enumType)
67+
$this->readableEnumValueTwigExtension->getReadableEnumValue($enumValue, $enumType)
6268
);
6369
}
6470

65-
public function dataProviderForGetReadableEnumValueTest(): iterable
71+
public static function dataProviderForGetReadableEnumValueTest(): iterable
6672
{
6773
yield ['Point Guard', BasketballPositionType::POINT_GUARD, 'BasketballPositionType'];
6874
yield ['Point Guard', BasketballPositionType::POINT_GUARD, null];
@@ -74,19 +80,19 @@ public function dataProviderForGetReadableEnumValueTest(): iterable
7480
public function testEnumTypeIsNotRegisteredException(): void
7581
{
7682
$this->expectException(EnumTypeIsNotRegisteredException::class);
77-
$this->readableEnumValueExtension->getReadableEnumValue('Pitcher', 'BaseballPositionType');
83+
$this->readableEnumValueTwigExtension->getReadableEnumValue('Pitcher', 'BaseballPositionType');
7884
}
7985

8086
public function testValueIsFoundInFewRegisteredEnumTypesException(): void
8187
{
8288
$this->expectException(ValueIsFoundInFewRegisteredEnumTypesException::class);
83-
$this->readableEnumValueExtension->getReadableEnumValue(BasketballPositionType::CENTER);
89+
$this->readableEnumValueTwigExtension->getReadableEnumValue(BasketballPositionType::CENTER);
8490
}
8591

8692
public function testValueIsNotFoundInAnyRegisteredEnumTypeException(): void
8793
{
8894
$this->expectException(ValueIsNotFoundInAnyRegisteredEnumTypeException::class);
89-
$this->readableEnumValueExtension->getReadableEnumValue('Pitcher');
95+
$this->readableEnumValueTwigExtension->getReadableEnumValue('Pitcher');
9096
}
9197

9298
public function testNoRegisteredEnumTypesException(): void

Twig/Extension/ReadableEnumValueTwigExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Twig\Extension;
1414

15+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
1516
use Fresh\DoctrineEnumBundle\Exception\EnumType\EnumTypeIsNotRegisteredException;
1617
use Fresh\DoctrineEnumBundle\Exception\EnumType\NoRegisteredEnumTypesException;
1718
use Fresh\DoctrineEnumBundle\Exception\EnumValue\ValueIsFoundInFewRegisteredEnumTypesException;
@@ -48,7 +49,7 @@ public function getReadableEnumValue(?string $enumValue, ?string $enumType = nul
4849
{
4950
if ($this->hasRegisteredEnumTypes()) {
5051
if (null === $enumValue) {
51-
return $enumValue;
52+
return null;
5253
}
5354

5455
// If ENUM type was set, e.g. {{ player.position|readable_enum('BasketballPositionType') }}
@@ -62,7 +63,11 @@ public function getReadableEnumValue(?string $enumValue, ?string $enumType = nul
6263
$this->findOccurrences($enumValue);
6364

6465
if ($this->onlyOneOccurrenceFound()) {
65-
return \array_pop($this->occurrences)::getReadableValue($enumValue);
66+
$occurrence = \array_pop($this->occurrences);
67+
68+
if (null !== $occurrence && \is_subclass_of($occurrence, AbstractEnumType::class)) {
69+
return $occurrence::getReadableValue($enumValue);
70+
}
6671
}
6772

6873
if ($this->moreThanOneOccurrenceFound()) {

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,27 @@
2323
},
2424
"require": {
2525
"php": ">=7.2.5",
26-
"doctrine/common": "^2.11",
27-
"doctrine/doctrine-bundle": "^2.0",
26+
"doctrine/common": "^2.11 || ^3.0",
27+
"doctrine/doctrine-bundle": "^2.1",
2828
"doctrine/orm": "^2.7",
2929
"symfony/config": "^5.0",
3030
"symfony/dependency-injection": "^5.0",
3131
"symfony/doctrine-bridge": "^5.0",
3232
"symfony/framework-bundle": "^5.0",
3333
"symfony/http-kernel": "^5.0",
3434
"symfony/validator": "^5.0",
35-
"twig/twig": "~2.11 || ^3.0"
35+
"twig/twig": "^3.0"
3636
},
3737
"require-dev": {
38-
"escapestudios/symfony2-coding-standard": "^3.10",
39-
"johnkary/phpunit-speedtrap": "^3.1",
38+
"escapestudios/symfony2-coding-standard": "^3.11",
39+
"johnkary/phpunit-speedtrap": "^3.2",
4040
"phpstan/phpstan": "^0.12",
4141
"phpstan/phpstan-doctrine":"^0.12",
4242
"phpstan/phpstan-phpunit": "^0.12",
4343
"phpstan/phpstan-symfony": "^0.12",
4444
"phpunit/phpunit": "^8.5",
4545
"slam/phpstan-extensions": "^4.0",
4646
"symfony/form": "^5.0",
47-
"symfony/phpunit-bridge": "^5.0",
4847
"symfony/yaml": "^5.0"
4948
},
5049
"autoload": {

0 commit comments

Comments
 (0)