testFindDangerousArgChanges

This commit is contained in:
Ben Roberts 2017-11-21 11:50:11 -05:00
parent 3c0ed787ba
commit c4ae03454a
2 changed files with 64 additions and 4 deletions

View File

@ -171,16 +171,19 @@ class FindBreakingChanges
];
} else {
$isSafe = self::isChangeSafeForInputObjectFieldOrFieldArg($oldArgDef->getType(), $newArgDef->getType());
$oldArgType = $oldArgDef->getType();
$oldArgName = $oldArgDef->name;
if (!$isSafe) {
$oldArgType = $oldArgDef->getType();
$newArgType = $newArgDef->getType();
$oldArgName = $oldArgDef->name;
$breakingChanges[] = [
'type' => self::BREAKING_CHANGE_ARG_CHANGED,
'description' => "${oldTypeName}->${fieldName} arg ${oldArgName} has changed type from ${oldArgType} to ${newArgType}."
];
} elseif ($oldArgDef->defaultValueExists() && $oldArgDef->defaultValue !== $newArgDef->defaultValue) {
$dangerousChanges[] = []; // TODO
$dangerousChanges[] = [
'type' => FindBreakingChanges::DANGEROUS_CHANGE_ARG_DEFAULT_VALUE,
'description' => "${oldTypeName}->${fieldName} arg ${oldArgName} has changed defaultValue"
];
}
}
// Check if a non-null arg was added to the field

View File

@ -22,7 +22,7 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->queryType = new ObjectType([
'name' => 'Type1',
'name' => 'Query',
'fields' => [
'field1' => [
'type' => Type::string()
@ -1228,4 +1228,61 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedBreakingChanges, FindBreakingChanges::findBreakingChanges($oldSchema, $newSchema));
}
// findDangerousChanges tests below here
public function testFindDangerousArgChanges()
{
$oldType = new ObjectType([
'name' => 'Type1',
'fields' => [
'field1' => [
'type' => Type::string(),
'args' => [
'name' => [
'type' => Type::string(),
'defaultValue' => 'test'
]
]
]
]
]);
$newType = new ObjectType([
'name' => 'Type1',
'fields' => [
'field1' => [
'type' => Type::string(),
'args' => [
'name' => [
'type' => Type::string(),
'defaultValue' => 'Testertest'
]
]
]
]
]);
$oldSchema = new Schema([
'query' => $this->queryType,
'types' => [
$oldType
]
]);
$newSchema = new Schema([
'query' => $this->queryType,
'types' => [
$newType
]
]);
$this->assertEquals(
[
'type' => FindBreakingChanges::DANGEROUS_CHANGE_ARG_DEFAULT_VALUE,
'description' => 'Type1->field1 arg name has changed defaultValue'
],
FindBreakingChanges::findArgChanges($oldSchema, $newSchema)['dangerousChanges'][0]
);
}
}