From c5484ae6f95f5df846826cdcbc95b178bf006f6a Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 4 Jul 2017 00:28:17 +0700 Subject: [PATCH] Convert error to warning for non-compliant usage of __ in names --- src/Error/Warning.php | 24 ++++++++++++++++++++++++ src/Utils.php | 6 ++++-- tests/Type/ValidationTest.php | 23 ++++++++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/Error/Warning.php 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([