Skip to content

Commit 75fc1be

Browse files
committed
Merge pull request #19 from fre5h/fix-required-entity-option
Fix required entity option
2 parents 67cd890 + 83f5bf6 commit 75fc1be

File tree

12 files changed

+37
-77
lines changed

12 files changed

+37
-77
lines changed

DBAL/Types/AbstractEnumType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
abstract class AbstractEnumType extends Type
2626
{
2727
/**
28-
* @var string Name of this type
28+
* @var string $name Name of this type
2929
*/
3030
protected $name = '';
3131

3232
/**
33-
* @var array Array of ENUM Values, where ENUM values are keys and their readable versions are values
33+
* @var array $choices Array of ENUM Values, where ENUM values are keys and their readable versions are values
3434
* @static
3535
*/
3636
protected static $choices = [];
@@ -120,7 +120,7 @@ public static function getValues()
120120
*
121121
* @static
122122
*
123-
* @return string|null Value in readable format
123+
* @return string|null $value Value in readable format
124124
*
125125
* @throws \InvalidArgumentException
126126
*/

DependencyInjection/FreshDoctrineEnumExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
class FreshDoctrineEnumExtension extends Extension
2424
{
2525
/**
26-
* Loads a specific configuration
27-
*
28-
* @param array $configs An array of configuration values
29-
* @param ContainerBuilder $container A ContainerBuilder instance
26+
* {@inheritdoc}
3027
*/
3128
public function load(array $configs, ContainerBuilder $container)
3229
{

Fixtures/DBAL/Types/BasketballPositionType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ class BasketballPositionType extends AbstractEnumType
2626
const CENTER = 'C';
2727

2828
/**
29-
* @var string Name of this type
29+
* {@inheritdoc}
3030
*/
3131
protected $name = 'BasketballPositionType';
3232

3333
/**
34-
* @var array Readable choices
35-
* @static
34+
* {@inheritdoc}
3635
*/
3736
protected static $choices = [
3837
self::POINT_GUARD => 'Point guard',

Fixtures/DBAL/Types/MapLocationType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ class MapLocationType extends AbstractEnumType
3030
const SOUTH_EAST = 'SE';
3131

3232
/**
33-
* @var string Name of this type
33+
* {@inheritdoc}
3434
*/
3535
protected $name = 'MapLocationType';
3636

3737
/**
38-
* @var array Readable choices
39-
* @static
38+
* {@inheritdoc}
4039
*/
4140
protected static $choices = [
4241
self::NORTH => 'North',

Form/EnumTypeGuesser.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
class EnumTypeGuesser extends DoctrineOrmTypeGuesser
2626
{
2727
/**
28-
* Array of registered ENUM types
29-
*
30-
* @var AbstractEnumType[]
28+
* @var AbstractEnumType[] $registeredEnumTypes Array of registered ENUM types
3129
*/
3230
protected $registeredEnumTypes = [];
3331

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Provides support of **ENUM type** for Doctrine in Symfony applications.
3030

3131
### Install via Composer
3232

33-
```php composer.phar require fresh/doctrine-enum-bundle='v3.0'```
33+
```php composer.phar require fresh/doctrine-enum-bundle='v3.1'```
3434

3535
### Register the bundle
3636

Tests/DBAL/Types/AbstractEnumTypeTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@
2727
class AbstractEnumTypeTest extends \PHPUnit_Framework_TestCase
2828
{
2929
/**
30-
* @var AbstractEnumType
30+
* @var AbstractEnumType $type AbstractEnumType
3131
*/
3232
private $type;
3333

3434
/**
35-
* Set up before test suite
35+
* {@inheritdoc}
3636
*/
3737
public static function setUpBeforeClass()
3838
{
3939
Type::addType('BasketballPositionType', '\Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType');
4040
}
4141

4242
/**
43-
* Set up environment
43+
* {@inheritdoc}
4444
*/
4545
public function setUp()
4646
{
@@ -54,11 +54,9 @@ public function setUp()
5454
* @param AbstractPlatform $platform The DBAL platform
5555
* @param string $expected Expected SQL declaration
5656
*
57-
* @test
58-
* @covers ::getSqlDeclaration
5957
* @dataProvider platformProvider
6058
*/
61-
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform, $expected)
59+
public function testGetSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform, $expected)
6260
{
6361
$this->assertEquals($expected, $this->type->getSqlDeclaration($fieldDeclaration, $platform));
6462
}
@@ -72,14 +70,14 @@ public function platformProvider()
7270
{
7371
return [
7472
[
75-
['name' => 'sex'],
73+
['name' => 'position'],
7674
new MySqlPlatform(),
7775
"ENUM('PG', 'SG', 'SF', 'PF', 'C')"
7876
],
7977
[
80-
['name' => 'sex'],
78+
['name' => 'position'],
8179
new SqlitePlatform(),
82-
"TEXT CHECK(sex IN ('PG', 'SG', 'SF', 'PF', 'C'))"
80+
"TEXT CHECK(position IN ('PG', 'SG', 'SF', 'PF', 'C'))"
8381
]
8482
];
8583
}

Tests/Twig/Extension/ReadableEnumValueExtensionTest.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
* ReadableEnumValueExtensionTest
1919
*
2020
* @author Artem Genvald <genvaldartem@gmail.com>
21-
*
22-
* @coversDefaultClass \Fresh\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension
2321
*/
2422
class ReadableEnumValueExtensionTest extends \PHPUnit_Framework_TestCase
2523
{
2624
/**
27-
* @var ReadableEnumValueExtension
25+
* @var ReadableEnumValueExtension $readableEnumValueExtension ReadableEnumValueExtension
2826
*/
2927
private $readableEnumValueExtension;
3028

3129
/**
32-
* Set up ReadableEnumValueExtension
30+
* {@inheritdoc}
3331
*/
3432
public function setUp()
3533
{
@@ -50,11 +48,9 @@ public function setUp()
5048
* @param string $enumValue Enum value
5149
* @param string $enumType Enum type
5250
*
53-
* @test
54-
* @covers ::getReadableEnumValue
5551
* @dataProvider dataProviderForGetReadableEnumValueTest
5652
*/
57-
public function getReadableEnumValue($expectedReadableValue, $enumValue, $enumType)
53+
public function testGetReadableEnumValue($expectedReadableValue, $enumValue, $enumType)
5854
{
5955
$this->assertEquals(
6056
$expectedReadableValue,
@@ -80,11 +76,9 @@ public function dataProviderForGetReadableEnumValueTest()
8076
* Test that using readable ENUM value extension for ENUM type that is not registered
8177
* throws EnumTypeIsNotRegisteredException
8278
*
83-
* @test
84-
* @covers ::getReadableEnumValue
8579
* @expectedException \Fresh\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException
8680
*/
87-
public function enumTypeIsNotRegisteredException()
81+
public function testEnumTypeIsNotRegisteredException()
8882
{
8983
$this->readableEnumValueExtension->getReadableEnumValue('Pitcher', 'BaseballPositionType');
9084
}
@@ -93,11 +87,9 @@ public function enumTypeIsNotRegisteredException()
9387
* Test that using ENUM value that is found in few registered ENUM types
9488
* throws ValueIsFoundInFewRegisteredEnumTypesException
9589
*
96-
* @test
97-
* @covers ::getReadableEnumValue
9890
* @expectedException \Fresh\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException
9991
*/
100-
public function valueIsFoundInFewRegisteredEnumTypesException()
92+
public function testValueIsFoundInFewRegisteredEnumTypesException()
10193
{
10294
$this->readableEnumValueExtension->getReadableEnumValue(BasketballPositionType::CENTER);
10395
}
@@ -106,11 +98,9 @@ public function valueIsFoundInFewRegisteredEnumTypesException()
10698
* Test that using ENUM value that is not found in any registered ENUM type
10799
* throws ValueIsNotFoundInAnyRegisteredEnumTypeException
108100
*
109-
* @test
110-
* @covers ::getReadableEnumValue
111101
* @expectedException \Fresh\DoctrineEnumBundle\Exception\ValueIsNotFoundInAnyRegisteredEnumTypeException
112102
*/
113-
public function valueIsNotFoundInAnyRegisteredEnumTypeException()
103+
public function testValueIsNotFoundInAnyRegisteredEnumTypeException()
114104
{
115105
$this->readableEnumValueExtension->getReadableEnumValue('Pitcher');
116106
}
@@ -119,11 +109,9 @@ public function valueIsNotFoundInAnyRegisteredEnumTypeException()
119109
* Test that using readable ENUM value extension without any registered ENUM type
120110
* throws NoRegisteredEnumTypesException
121111
*
122-
* @test
123-
* @covers ::getReadableEnumValue
124112
* @expectedException \Fresh\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException
125113
*/
126-
public function noRegisteredEnumTypesException()
114+
public function testNoRegisteredEnumTypesException()
127115
{
128116
// Create ReadableEnumValueExtension without any registered ENUM type
129117
$extension = new ReadableEnumValueExtension([]);

Tests/Validator/EnumValidatorTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
* EnumValidatorTest
2020
*
2121
* @author Artem Genvald <genvaldartem@gmail.com>
22-
*
23-
* @coversDefaultClass \Fresh\DoctrineEnumBundle\Validator\Constraints\EnumValidator
2422
*/
2523
class EnumValidatorTest extends \PHPUnit_Framework_TestCase
2624
{
@@ -35,7 +33,7 @@ class EnumValidatorTest extends \PHPUnit_Framework_TestCase
3533
private $context;
3634

3735
/**
38-
* Set up ENUM validator
36+
* {@inheritdoc}
3937
*/
4038
public function setUp()
4139
{
@@ -49,22 +47,17 @@ public function setUp()
4947
/**
5048
* Test that creation of ENUM Constraint without type class throws ConstraintDefinitionException
5149
*
52-
* @test
53-
* @covers ::validate
54-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
50+
* @expectedException \Symfony\Component\Validator\Exception\MissingOptionsException
5551
*/
56-
public function exceptionEntityNotSpecified()
52+
public function testExceptionEntityNotSpecified()
5753
{
5854
$this->enumValidator->validate(BasketballPositionType::POINT_GUARD, new Enum());
5955
}
6056

6157
/**
6258
* Test valid basketball position
63-
*
64-
* @test
65-
* @covers ::validate
6659
*/
67-
public function validBasketballPositionType()
60+
public function testValidBasketballPositionType()
6861
{
6962
$constraint = new Enum([
7063
'entity' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType'
@@ -80,11 +73,8 @@ public function validBasketballPositionType()
8073

8174
/**
8275
* Test invalid basketball position
83-
*
84-
* @test
85-
* @covers ::validate
8676
*/
87-
public function invalidBasketballPositionType()
77+
public function testInvalidBasketballPositionType()
8878
{
8979
$constraint = new Enum([
9080
'entity' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType'

Twig/Extension/ReadableEnumValueExtension.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Fresh\DoctrineEnumBundle\Twig\Extension;
1212

13+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
1314
use Fresh\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException;
1415
use Fresh\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException;
1516
use Fresh\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException;
@@ -23,9 +24,7 @@
2324
class ReadableEnumValueExtension extends \Twig_Extension
2425
{
2526
/**
26-
* Array of registered ENUM types
27-
*
28-
* @var \Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType[] $registeredEnumTypes Registered ENUM types
27+
* @var AbstractEnumType[] $registeredEnumTypes Array of registered ENUM types
2928
*/
3029
protected $registeredEnumTypes = [];
3130

@@ -44,9 +43,7 @@ public function __construct(array $registeredTypes)
4443
}
4544

4645
/**
47-
* Returns a list of filters
48-
*
49-
* @return array
46+
* {@inheritdoc}
5047
*/
5148
public function getFilters()
5249
{
@@ -113,9 +110,7 @@ public function getReadableEnumValue($enumValue, $enumType = null)
113110
}
114111

115112
/**
116-
* Get name of this extension
117-
*
118-
* @return string Name of extension
113+
* {@inheritdoc}
119114
*/
120115
public function getName()
121116
{

Validator/Constraints/Enum.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ class Enum extends Choice
2727
public $entity;
2828

2929
/**
30-
* Returns the name of the required options
31-
*
32-
* @return array
30+
* {@inheritdoc}
3331
*/
34-
public function requiredOptions()
32+
public function getRequiredOptions()
3533
{
3634
return ['entity'];
3735
}
3836

3937
/**
40-
* Returns the name of the default option
41-
*
42-
* @return string
38+
* {@inheritdoc}
4339
*/
4440
public function getDefaultOption()
4541
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://github.com/fre5h/DoctrineEnumBundle",
66
"type": "symfony-bundle",
77
"license": "MIT",
8-
"time": "2014-11-23",
8+
"time": "2014-12-11",
99
"authors": [
1010
{
1111
"name": "Artem Genvald",

0 commit comments

Comments
 (0)