mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
testFindDangerousArgChanges
This commit is contained in:
parent
3c0ed787ba
commit
c4ae03454a
@ -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
|
||||
|
@ -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]
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user