diff --git a/src/Error/Warning.php b/src/Error/Warning.php new file mode 100644 index 0000000..0d2e299 --- /dev/null +++ b/src/Error/Warning.php @@ -0,0 +1,24 @@ +assertEachCallableThrows([ + $this->assertWarnsOnce([ function() { return new ObjectType([ 'name' => '__ReservedName', @@ -53,6 +53,7 @@ class ValidationTest extends \PHPUnit_Framework_TestCase function() { return new UnionType([ 'name' => '__ReservedName', + 'types' => [new ObjectType(['name' => 'Test'])] ]); }, function() { @@ -268,6 +269,26 @@ class ValidationTest extends \PHPUnit_Framework_TestCase } } + private function assertWarnsOnce($closures, $expectedError) + { + $warned = false; + + foreach ($closures as $index => $factory) { + if (!$warned) { + try { + $factory(); + $this->fail('Expected exception not thrown for entry ' . $index); + } catch (\PHPUnit_Framework_Error_Warning $e) { + $warned = true; + $this->assertEquals($expectedError, $e->getMessage(), 'Error in callable #' . $index); + } + } else { + // Should not throw + $factory(); + } + } + } + private function schemaWithFieldType($type) { return new Schema([