Reverted unnecessary breaking change

This commit is contained in:
Vladimir Razuvaev 2017-08-15 23:39:07 +07:00
parent 88c959edad
commit f369d4e2d4
2 changed files with 3 additions and 45 deletions

View File

@ -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 {

View File

@ -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
*/