testDetectsValuesRemovedFromEnum

This commit is contained in:
Ben Roberts 2017-11-17 16:24:04 -05:00
parent 98ce1ccc69
commit cac011246e
2 changed files with 48 additions and 1 deletions

View File

@ -479,7 +479,7 @@ class FindBreakingChanges
foreach ($oldType->getValues() as $value) { foreach ($oldType->getValues() as $value) {
if (!isset($valuesInNewEnum[$value->name])) { if (!isset($valuesInNewEnum[$value->name])) {
$valueName = $value->name; $valueName = $value->name;
$valuesRemovedFromEnums[] = ['type' => self::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM, 'description' => "${valueName} was removed from enum type ${typeName}"]; $valuesRemovedFromEnums[] = ['type' => self::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM, 'description' => "${valueName} was removed from enum type ${typeName}."];
} }
} }
} }

View File

@ -5,6 +5,7 @@
namespace GraphQL\Tests\Utils; namespace GraphQL\Tests\Utils;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\InterfaceType; use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\ObjectType;
@ -545,4 +546,50 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
FindBreakingChanges::findTypesRemovedFromUnions($oldSchema, $newSchema)[0] FindBreakingChanges::findTypesRemovedFromUnions($oldSchema, $newSchema)[0]
); );
} }
public function testDetectsValuesRemovedFromEnum()
{
$oldEnumType = new EnumType([
'name' => 'EnumType1',
'values' => [
'VALUE0' => 0,
'VALUE1' => 1,
'VALUE2' => 2
]
]);
$newEnumType = new EnumType([
'name' => 'EnumType1',
'values' => [
'VALUE0' => 0,
'VALUE2' => 1,
'VALUE3' => 2
]
]);
$oldSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $oldEnumType
]
])
]);
$newSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $newEnumType
]
])
]);
$this->assertEquals(
[
'type' => FindBreakingChanges::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM,
'description' => 'VALUE1 was removed from enum type EnumType1.'
],
FindBreakingChanges::findValuesRemovedFromEnums($oldSchema, $newSchema)[0]
);
}
} }