Fixed tests broken by recent changes to serialized error format

This commit is contained in:
vladar 2016-10-21 15:28:24 +07:00
parent c25a29213c
commit 6d7a4a4f34
7 changed files with 18 additions and 13 deletions

View File

@ -26,6 +26,7 @@ class Config
const REQUIRED = 65536;
const KEY_AS_NAME = 131072;
const MAYBE_THUNK = 262144;
const MAYBE_TYPE = 524288;
/**
* @var bool
@ -155,7 +156,11 @@ class Config
foreach ($value as $arrKey => $arrValue) {
if (is_array($def->definition)) {
Utils::invariant(is_array($arrValue), $err, $arrKey, Utils::getVariableType($arrValue));
if ($def->flags & self::MAYBE_TYPE) {
Utils::invariant(is_array($arrValue) || $arrValue instanceof Type, $err, $arrKey, Utils::getVariableType($arrValue));
} else {
Utils::invariant(is_array($arrValue), $err, $arrKey, Utils::getVariableType($arrValue));
}
if ($def->flags & self::KEY_AS_NAME) {
$arrValue += ['name' => $arrKey];

View File

@ -86,7 +86,7 @@ class ObjectType extends Type implements OutputType, CompositeType
'name' => Config::STRING | Config::REQUIRED,
'fields' => Config::arrayOf(
FieldDefinition::getDefinition(),
Config::KEY_AS_NAME | Config::MAYBE_THUNK
Config::KEY_AS_NAME | Config::MAYBE_THUNK | Config::MAYBE_TYPE
),
'description' => Config::STRING,
'interfaces' => Config::arrayOf(

View File

@ -404,7 +404,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase
$result = Executor::execute($schema, $docAst, $data);
$this->assertEquals($expected, $result->toArray());
$this->assertArraySubset($expected, $result->toArray());
}
/**

View File

@ -41,7 +41,7 @@ class ListsTest extends \PHPUnit_Framework_TestCase
$ast = Parser::parse('{ nest { test } }');
$result = Executor::execute($schema, $ast, $data);
$this->assertEquals($expected, $result->toArray());
$this->assertArraySubset($expected, $result->toArray());
}
// Describe: Execute: Handles list nullability

View File

@ -114,7 +114,7 @@ class MutationsTest extends \PHPUnit_Framework_TestCase
)
]
];
$this->assertEquals($expected, $mutationResult->toArray());
$this->assertArraySubset($expected, $mutationResult->toArray());
}
private function schema()

View File

@ -99,7 +99,7 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
)
]
];
$this->assertEquals($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
}
public function testNullsASynchronouslyReturnedObjectThatContainsANonNullableFieldThatThrowsSynchronously()
@ -123,7 +123,7 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
FormattedError::create($this->nonNullSyncError->getMessage(), [new SourceLocation(4, 11)])
]
];
$this->assertEquals($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
}
public function testNullsAComplexTreeOfNullableFieldsThatThrow()
@ -155,7 +155,7 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(6, 13)]),
]
];
$this->assertEquals($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
}
public function testNullsANullableFieldThatSynchronouslyReturnsNull()
@ -197,7 +197,7 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
FormattedError::create('Cannot return null for non-nullable field DataType.nonNullSync.', [new SourceLocation(4, 11)])
]
];
$this->assertEquals($expected, Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray());
}
public function test5()
@ -247,7 +247,7 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
FormattedError::create($this->nonNullSyncError->getMessage(), [new SourceLocation(2, 17)])
]
];
$this->assertEquals($expected, Executor::execute($this->schema, Parser::parse($doc), $this->throwingData)->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, Parser::parse($doc), $this->throwingData)->toArray());
}
public function testNullsTheTopLevelIfSyncNonNullableFieldReturnsNull()
@ -262,6 +262,6 @@ class NonNullTest extends \PHPUnit_Framework_TestCase
FormattedError::create('Cannot return null for non-nullable field DataType.nonNullSync.', [new SourceLocation(2, 17)]),
]
];
$this->assertEquals($expected, Executor::execute($this->schema, Parser::parse($doc), $this->nullingData)->toArray());
$this->assertArraySubset($expected, Executor::execute($this->schema, Parser::parse($doc), $this->nullingData)->toArray());
}
}

View File

@ -423,7 +423,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
]]
];
$this->assertEquals($expected, $result);
$this->assertArraySubset($expected, $result);
}
/**
@ -443,7 +443,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
third: simpleEnum(fromValue: "WRONG")
}';
$this->assertEquals(
$this->assertArraySubset(
[
'data' => ['first' => 'ONE', 'second' => 'TWO', 'third' => null],
'errors' => [[