Skip to content

Commit b18dfd6

Browse files
author
Ben Roberts
committed
testFindsAllDangerousChanges
1 parent 533b8b8 commit b18dfd6

File tree

1 file changed

+116
-3
lines changed

1 file changed

+116
-3
lines changed

tests/Utils/FindBreakingChangesTest.php

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,8 @@ public function testDetectsEnumValueAdditions()
13271327
);
13281328
}
13291329

1330-
public function testDetectsAdditionsToUnionType() {
1330+
public function testDetectsAdditionsToUnionType()
1331+
{
13311332
$type1 = new ObjectType([
13321333
'name' => 'Type1',
13331334
'fields' => [
@@ -1379,10 +1380,122 @@ public function testDetectsAdditionsToUnionType() {
13791380

13801381
$this->assertEquals(
13811382
[
1382-
'type' => FindBreakingChanges::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
1383-
'description' => 'Type2 was added to union type UnionType1'
1383+
'type' => FindBreakingChanges::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
1384+
'description' => 'Type2 was added to union type UnionType1'
13841385
],
13851386
FindBreakingChanges::findTypesAddedToUnions($oldSchema, $newSchema)[0]
13861387
);
13871388
}
1389+
1390+
public function testFindsAllDangerousChanges()
1391+
{
1392+
$enumThatGainsAValueOld = new EnumType([
1393+
'name' => 'EnumType1',
1394+
'values' => [
1395+
'VALUE0' => 0,
1396+
'VALUE1' => 1,
1397+
]
1398+
]);
1399+
$enumThatGainsAValueNew = new EnumType([
1400+
'name' => 'EnumType1',
1401+
'values' => [
1402+
'VALUE0' => 0,
1403+
'VALUE1' => 1,
1404+
'VALUE2' => 2
1405+
]
1406+
]);
1407+
1408+
$oldType = new ObjectType([
1409+
'name' => 'Type1',
1410+
'fields' => [
1411+
'field1' => [
1412+
'type' => Type::string(),
1413+
'args' => [
1414+
'name' => [
1415+
'type' => Type::string(),
1416+
'defaultValue' => 'test'
1417+
]
1418+
]
1419+
]
1420+
]
1421+
]);
1422+
1423+
$newType = new ObjectType([
1424+
'name' => 'Type1',
1425+
'fields' => [
1426+
'field1' => [
1427+
'type' => Type::string(),
1428+
'args' => [
1429+
'name' => [
1430+
'type' => Type::string(),
1431+
'defaultValue' => 'Testertest'
1432+
]
1433+
]
1434+
]
1435+
]
1436+
]);
1437+
1438+
$typeInUnion1 = new ObjectType([
1439+
'name' => 'TypeInUnion1',
1440+
'fields' => [
1441+
'field1' => Type::string()
1442+
]
1443+
]);
1444+
1445+
$typeInUnion2 = new ObjectType([
1446+
'name' => 'TypeInUnion2',
1447+
'fields' => [
1448+
'field1' => Type::string()
1449+
]
1450+
]);
1451+
1452+
$unionTypeThatGainsATypeOld = new UnionType([
1453+
'name' => 'UnionType1',
1454+
'types' => [$typeInUnion1],
1455+
'resolveType' => function () {
1456+
}
1457+
]);
1458+
1459+
$unionTypeThatGainsATypeNew = new UnionType([
1460+
'name' => 'UnionType1',
1461+
'types' => [$typeInUnion1, $typeInUnion2],
1462+
'resolveType' => function () {
1463+
}
1464+
]);
1465+
1466+
$oldSchema = new Schema([
1467+
'query' => $this->queryType,
1468+
'types' => [
1469+
$oldType,
1470+
$enumThatGainsAValueOld,
1471+
$unionTypeThatGainsATypeOld
1472+
]
1473+
]);
1474+
1475+
$newSchema = new Schema([
1476+
'query' => $this->queryType,
1477+
'types' => [
1478+
$newType,
1479+
$enumThatGainsAValueNew,
1480+
$unionTypeThatGainsATypeNew
1481+
]
1482+
]);
1483+
1484+
$expectedDangerousChanges = [
1485+
[
1486+
'description' => 'Type1->field1 arg name has changed defaultValue',
1487+
'type' => FindBreakingChanges::DANGEROUS_CHANGE_ARG_DEFAULT_VALUE
1488+
],
1489+
[
1490+
'description' => 'VALUE2 was added to enum type EnumType1',
1491+
'type' => FindBreakingChanges::DANGEROUS_CHANGE_VALUE_ADDED_TO_ENUM
1492+
],
1493+
[
1494+
'type' => FindBreakingChanges::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
1495+
'description' => 'TypeInUnion2 was added to union type UnionType1',
1496+
]
1497+
];
1498+
1499+
$this->assertEquals($expectedDangerousChanges, FindBreakingChanges::findDangerousChanges($oldSchema, $newSchema));
1500+
}
13881501
}

0 commit comments

Comments
 (0)