findTypesThatChangedKind test

This commit is contained in:
Ben Roberts 2017-11-17 13:04:01 -05:00
parent d9ce567cc8
commit b2b5d6f080
2 changed files with 48 additions and 1 deletions

View File

@ -116,7 +116,7 @@ class FindBreakingChanges
$newTypeKindName = self::typeKindName($newTypeDefinition);
$breakingChanges[] = [
'type' => self::BREAKING_CHANGE_TYPE_CHANGED,
'description' => "${$typeName} changed from ${oldTypeKindName} to ${newTypeKindName}."
'description' => "${typeName} changed from ${oldTypeKindName} to ${newTypeKindName}."
];
}
}

View File

@ -5,8 +5,10 @@
namespace GraphQL\Tests\Utils;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\UnionType;
use GraphQL\Type\Schema;
use GraphQL\Utils\FindBreakingChanges;
@ -64,4 +66,49 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
$this->assertEquals([], FindBreakingChanges::findRemovedTypes($oldSchema, $oldSchema));
}
public function testShouldDetectTypeChanges()
{
$objectType = new ObjectType([
'name' => 'ObjectType',
'fields' => [
'field1' => ['type' => Type::string()],
]
]);
$interfaceType = new InterfaceType([
'name' => 'Type1',
'fields' => [
'field1' => ['type' => Type::string()]
]
]);
$unionType = new UnionType([
'name' => 'Type1',
'types' => [new ObjectType(['name' => 'blah'])],
]);
$oldSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $interfaceType
]
])
]);
$newSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $unionType
]
])
]);
$this->assertEquals(
['type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_CHANGED, 'description' => 'Type1 changed from an Interface type to a Union type.'],
FindBreakingChanges::findTypesThatChangedKind($oldSchema, $newSchema)[0]
);
}
}