testDetectsNonNullFieldAddedToInputType

This commit is contained in:
Ben Roberts 2017-11-17 15:56:53 -05:00
parent cf4cccf4d6
commit dde2747918
2 changed files with 46 additions and 1 deletions

View File

@ -324,7 +324,7 @@ class FindBreakingChanges
foreach ($newTypeFieldsDef as $fieldName => $fieldDef) { foreach ($newTypeFieldsDef as $fieldName => $fieldDef) {
if (!isset($oldTypeFieldsDef[$fieldName]) && $fieldDef->getType() instanceof NonNull) { if (!isset($oldTypeFieldsDef[$fieldName]) && $fieldDef->getType() instanceof NonNull) {
$newTypeName = $newType->name; $newTypeName = $newType->name;
$breakingFieldChanges[] = ['type' => self::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED, 'description' => "A non-null field ${fieldName} on input type ${$newTypeName} was added"]; $breakingFieldChanges[] = ['type' => self::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED, 'description' => "A non-null field ${fieldName} on input type ${newTypeName} was added."];
} }
} }
} }

View File

@ -428,4 +428,49 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedFieldChanges, FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema)); $this->assertEquals($expectedFieldChanges, FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema));
} }
public function testDetectsNonNullFieldAddedToInputType()
{
$oldInputType = new InputObjectType([
'name' => 'InputType1',
'fields' => [
'field1' => Type::string()
]
]);
$newInputType = new InputObjectType([
'name' => 'InputType1',
'fields' => [
'field1' => Type::string(),
'requiredField' => Type::nonNull(Type::int()),
'optionalField' => Type::boolean()
]
]);
$oldSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $oldInputType
]
])
]);
$newSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $newInputType
]
])
]);
$this->assertEquals(
[
'type' => FindBreakingChanges::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED,
'description' => 'A non-null field requiredField on input type InputType1 was added.'
],
FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema)[0]
);
}
} }