diff --git a/src/Type/Definition/EnumType.php b/src/Type/Definition/EnumType.php index a436144..b320bd5 100644 --- a/src/Type/Definition/EnumType.php +++ b/src/Type/Definition/EnumType.php @@ -72,12 +72,10 @@ class EnumType extends Type implements InputType, OutputType, LeafType foreach ($config['values'] as $name => $value) { if (is_string($name)) { if (!is_array($value)) { - throw new InvariantViolation( - "{$this->name}.$name must refer to an associative array with a " . - '"value" key representing an internal value but got: ' . Utils::printSafe($value) - ); + $value = ['name' => $name, 'value' => $value]; + } else { + $value += ['name' => $name, 'value' => $name]; } - $value += ['name' => $name, 'value' => $name]; } else if (is_int($name) && is_string($value)) { $value = ['name' => $value, 'value' => $value]; } else { diff --git a/tests/Type/ValidationTest.php b/tests/Type/ValidationTest.php index 3aa93e4..f1dcb25 100644 --- a/tests/Type/ValidationTest.php +++ b/tests/Type/ValidationTest.php @@ -1597,46 +1597,6 @@ class ValidationTest extends \PHPUnit_Framework_TestCase $type->assertValid(); } - /** - * @it rejects an Enum type with missing value definition - */ - public function testRejectsAnEnumTypeWithMissingValueDefinition() - { - $type = new EnumType([ - 'name' => 'SomeEnum', - 'values' => [ - 'FOO' => null - ] - ]); - - $this->setExpectedException( - InvariantViolation::class, - 'SomeEnum.FOO must refer to an associative array with a "value" key representing an internal value but got: null' - ); - - $type->assertValid(); - } - - /** - * @it rejects an Enum type with incorrectly typed value definition - */ - public function testRejectsAnEnumTypeWithIncorrectlyTypedValueDefinition() - { - $enumType = new EnumType([ - 'name' => 'SomeEnum', - 'values' => [ - 'FOO' => 10 - ] - ]); - - $this->setExpectedException( - InvariantViolation::class, - 'SomeEnum.FOO must refer to an associative array with a "value" key representing an internal value but got: 10' - ); - - $enumType->assertValid(); - } - /** * @it rejects an Enum type with incorrectly named values */