From 565e7dd700b69f8316b7216d1a0a6852e20ea085 Mon Sep 17 00:00:00 2001 From: Erayd Date: Thu, 2 Mar 2017 21:34:46 +1300 Subject: [PATCH 01/16] Add test coverage for coercion API --- tests/Constraints/CoerciveTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Constraints/CoerciveTest.php b/tests/Constraints/CoerciveTest.php index cb5c5518..36c0cf6b 100644 --- a/tests/Constraints/CoerciveTest.php +++ b/tests/Constraints/CoerciveTest.php @@ -116,6 +116,15 @@ public function testInvalidCoerceCasesUsingAssoc($input, $schema, $errors = arra $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true)); } + public function testCoerceAPI() + { + $input = json_decode('{"propertyOne": "10"}'); + $schema = json_decode('{"properties":{"propertyOne":{"type":"number"}}}'); + $v = new Validator(); + $v->coerce($input, $schema); + $this->assertEquals('{"propertyOne":10}', json_encode($input)); + } + public function getValidCoerceTests() { return array( From 566a77cb127db17dccb5bf3141db14ae390f8128 Mon Sep 17 00:00:00 2001 From: Erayd Date: Thu, 2 Mar 2017 21:58:13 +1300 Subject: [PATCH 02/16] Complete test coverage for SchemaStorage --- tests/SchemaStorageTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index c3388bf4..d60fe5b0 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -254,4 +254,18 @@ private function getInvalidSchema() ) ); } + + public function testGetUriRetriever() + { + $s = new SchemaStorage(); + $s->addSchema('http://json-schema.org/draft-04/schema#'); + $this->assertInstanceOf('\JsonSchema\Uri\UriRetriever', $s->getUriRetriever()); + } + + public function testGetUriResolver() + { + $s = new SchemaStorage(); + $s->addSchema('http://json-schema.org/draft-04/schema#'); + $this->assertInstanceOf('\JsonSchema\Uri\UriResolver', $s->getUriResolver()); + } } From f9f11a4007d496fe3fa1749b5a8333f7c273a318 Mon Sep 17 00:00:00 2001 From: Erayd Date: Fri, 3 Mar 2017 13:55:00 +1300 Subject: [PATCH 03/16] Add test coverage for ObjectIterator --- tests/Iterators/ObjectIteratorTest.php | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/Iterators/ObjectIteratorTest.php diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php new file mode 100644 index 00000000..703df833 --- /dev/null +++ b/tests/Iterators/ObjectIteratorTest.php @@ -0,0 +1,89 @@ +testObject = (object) array( + 'subOne' => (object) array( + 'propertyOne' => 'valueOne', + 'propertyTwo' => 'valueTwo', + 'propertyThree' => 'valueThree' + ), + 'subTwo' => (object) array( + 'propertyFour' => 'valueFour', + 'subThree' => (object) array( + 'propertyFive' => 'valueFive', + 'propertySix' => 'valueSix' + ) + ), + 'propertySeven' => 'valueSeven' + ); + } + + public function testCreate() + { + $i = new ObjectIterator($this->testObject); + + $this->assertInstanceOf('\JsonSchema\Iterator\ObjectIterator', $i); + } + + public function testInitialState() + { + $i = new ObjectIterator($this->testObject); + + $this->assertEquals($this->testObject, $i->current()); + } + + public function testCount() + { + $i = new ObjectIterator($this->testObject); + + $this->assertEquals(4, $i->count()); + } + + public function testKey() + { + $i = new ObjectIterator($this->testObject); + + while ($i->key() != 2) { + $i->next(); + } + + $this->assertEquals($this->testObject->subTwo->subThree, $i->current()); + } + + public function testAlwaysObjects() + { + $i= new ObjectIterator($this->testObject); + + foreach ($i as $item) { + $this->assertInstanceOf('\StdClass', $item); + } + } + + public function testReachesAllProperties() + { + $i = new ObjectIterator($this->testObject); + + $count = 0; + foreach ($i as $item) { + $count += count(get_object_vars($item)); + } + + $this->assertEquals(10, $count); + } +} From dd772f372d4526a44eb24aa3926213fd944057f4 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 12:41:42 +1300 Subject: [PATCH 04/16] Add tests for ConstraintError --- tests/ConstraintErrorTest.php | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/ConstraintErrorTest.php diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php new file mode 100644 index 00000000..d4220c48 --- /dev/null +++ b/tests/ConstraintErrorTest.php @@ -0,0 +1,38 @@ +assertEquals('Failed to match all schemas', $e->getMessage()); + } + + public function testGetInvalidMessage() + { + $e = ConstraintError::ALL_OF(); + + // set value to something silly + $r = new \ReflectionClass('\MabeEnum\Enum'); + $v = $r->getProperty('value'); + $v->setAccessible(true); + $v->setValue($e, 'notARealErrorName'); + + $this->setExpectedException( + '\JsonSchema\Exception\InvalidArgumentException', + 'Missing error message for notARealErrorName' + ); + $e->getMessage(); + } +} From 1453fd3957e29981965bf9bcce4a284fe96f588c Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 12:53:45 +1300 Subject: [PATCH 05/16] Add exception test for JsonPointer --- tests/Entity/JsonPointerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index 6a5ff4bf..65859895 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -109,4 +109,13 @@ public function testJsonPointerWithPropertyPaths() $this->assertEquals(array('~definitions/general', '%custom%'), $modified->getPropertyPaths()); $this->assertEquals('#/~0definitions~1general/%25custom%25', $modified->getPropertyPathAsString()); } + + public function testCreateWithInvalidValue() + { + $this->setExpectedException( + '\JsonSchema\Exception\InvalidArgumentException', + 'Ref value must be a string' + ); + new JsonPointer(null); + } } From b1ba94375c1d17b772f33512e6b07b57fe126fd8 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 13:07:49 +1300 Subject: [PATCH 06/16] MabeEnum\Enum appears to use singletons - add testing const --- src/JsonSchema/ConstraintError.php | 2 ++ tests/ConstraintErrorTest.php | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/JsonSchema/ConstraintError.php b/src/JsonSchema/ConstraintError.php index d7b73346..b9c702b6 100644 --- a/src/JsonSchema/ConstraintError.php +++ b/src/JsonSchema/ConstraintError.php @@ -31,6 +31,7 @@ class ConstraintError extends \MabeEnum\Enum const MAXIMUM = 'maximum'; const MIN_ITEMS = 'minItems'; const MINIMUM = 'minimum'; + const MISSING_ERROR = 'missingError'; const MISSING_MAXIMUM = 'missingMaximum'; const MISSING_MINIMUM = 'missingMinimum'; const MAX_ITEMS = 'maxItems'; @@ -81,6 +82,7 @@ public function getMessage() self::MINIMUM => 'Must have a minimum value greater than or equal to %d', self::MISSING_MAXIMUM => 'Use of exclusiveMaximum requires presence of maximum', self::MISSING_MINIMUM => 'Use of exclusiveMinimum requires presence of minimum', + /*self::MISSING_ERROR => 'Used for tests; this error is deliberately commented out',*/ self::MULTIPLE_OF => 'Must be a multiple of %d', self::NOT => 'Matched a schema which it should not', self::ONE_OF => 'Failed to match exactly one schema', diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index d4220c48..5efb7b66 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -21,17 +21,11 @@ public function testGetValidMessage() public function testGetInvalidMessage() { - $e = ConstraintError::ALL_OF(); - - // set value to something silly - $r = new \ReflectionClass('\MabeEnum\Enum'); - $v = $r->getProperty('value'); - $v->setAccessible(true); - $v->setValue($e, 'notARealErrorName'); + $e = ConstraintError::MISSING_ERROR(); $this->setExpectedException( '\JsonSchema\Exception\InvalidArgumentException', - 'Missing error message for notARealErrorName' + 'Missing error message for missingError' ); $e->getMessage(); } From f6cfcc7bc225709a214c087274ecaa337669f348 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 15:23:03 +1300 Subject: [PATCH 07/16] Don't check this line for coverage mbstring is on all test platforms, so this line will never be reached. --- src/JsonSchema/Constraints/StringConstraint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index 4790a040..babd5c41 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -55,6 +55,6 @@ private function strlen($string) return mb_strlen($string, mb_detect_encoding($string)); } - return strlen($string); + return strlen($string); // @codeCoverageIgnore because mbstring is present on all test platforms } } From 001a0bab3c6954cca3fa30591573f7c4cfbb6767 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 15:32:54 +1300 Subject: [PATCH 08/16] Add test for TypeConstraint::validateTypeNameWording() --- tests/Constraints/TypeTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index df8d6dd1..4e21edac 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -92,4 +92,18 @@ private function assertTypeConstraintError($expected, TypeConstraint $actual) $this->assertEquals($expected, $actualMessage); // first equal for the diff $this->assertSame($expected, $actualMessage); // the same for the strictness } + + public function testValidateTypeNameWording() + { + $t = new TypeConstraint(); + $r = new \ReflectionObject($t); + $m = $r->getMethod('validateTypeNameWording'); + $m->setAccessible(true); + + $this->setExpectedException( + '\UnexpectedValueException', + "No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]" + ); + $m->invoke($t, 'notAValidTypeName'); + } } From 1fdb514568a10a8112d674aa7e1849f3334e5504 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 15:49:58 +1300 Subject: [PATCH 09/16] Add test for exception on TypeConstraint::validateType() --- tests/Constraints/TypeTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 4e21edac..24138478 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -106,4 +106,17 @@ public function testValidateTypeNameWording() ); $m->invoke($t, 'notAValidTypeName'); } + + public function testValidateTypeException() + { + $t = new TypeConstraint(); + $data = new \StdClass(); + $schema = json_decode('{"type": "notAValidTypeName"}'); + + $this->setExpectedException( + 'JsonSchema\Exception\InvalidArgumentException', + 'object is an invalid type for notAValidTypeName' + ); + $t->check($data, $schema); + } } From e1190b53ec2061250e133e8bb1f4c8456dda62d3 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 16:08:15 +1300 Subject: [PATCH 10/16] PHPunit doesn't like an explanation with its @codeCoverageIgnore... --- src/JsonSchema/Constraints/StringConstraint.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index babd5c41..b3bdfbf7 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -55,6 +55,7 @@ private function strlen($string) return mb_strlen($string, mb_detect_encoding($string)); } - return strlen($string); // @codeCoverageIgnore because mbstring is present on all test platforms + // mbstring is present on all test platforms, so strlen() can be ignored for coverage + return strlen($string); // @codeCoverageIgnore } } From d176ccb469b95d5de1951a703537861cce74ea76 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 18:15:33 +1300 Subject: [PATCH 11/16] Add various tests for UriRetriever --- tests/Uri/UriRetrieverTest.php | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 01df161b..f5db5ca1 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -328,4 +328,88 @@ public function testRetrieveSchemaFromPackage() // check that the schema was loaded & processed correctly $this->assertEquals('454f423bd7edddf0bc77af4130ed9161', md5(json_encode($schema))); } + + public function testJsonSchemaOrgMediaTypeHack() + { + $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); + $retriever = new UriRetriever(); + + $this->assertTrue($retriever->confirmMediaType($mock, 'http://json-schema.org/')); + } + + public function testSchemaCache() + { + $retriever = new UriRetriever(); + $reflector = new \ReflectionObject($retriever); + + // inject a schema cache value + $schemaCache = $reflector->getProperty('schemaCache'); + $schemaCache->setAccessible(true); + $schemaCache->setValue($retriever, array('local://test/uri' => 'testSchemaValue')); + + // retrieve from schema cache + $loadSchema = $reflector->getMethod('loadSchema'); + $loadSchema->setAccessible(true); + $this->assertEquals( + 'testSchemaValue', + $loadSchema->invoke($retriever, 'local://test/uri') + ); + } + + public function testLoadSchemaJSONDecodingException() + { + $retriever = new UriRetriever(); + + $this->setExpectedException( + 'JsonSchema\Exception\JsonDecodingException', + 'JSON syntax is malformed' + ); + $schema = $retriever->retrieve('package://tests/fixtures/bad-syntax.json'); + } + + public function testGenerateURI() + { + $retriever = new UriRetriever(); + $components = array( + 'scheme' => 'scheme', + 'authority' => 'authority', + 'path' => '/path', + 'query' => '?query', + 'fragment' => '#fragment' + ); + $this->assertEquals('scheme://authority/path?query#fragment', $retriever->generate($components)); + } + + public function testResolveHTTP() + { + $retriever = new UriRetriever(); + $this->assertEquals( + 'http://example.com/schema', + $retriever->resolve('http://example.com/schema') + ); + } + + public function combinedURITests() + { + return array( + array('blue', 'http://example.com/red', 'http://example.com/blue'), + array('blue', 'http://example.com/', 'http://example.com/blue'), + ); + } + + /** + * @dataProvider combinedURITests + */ + public function testResolveCombinedURI($uri, $baseURI, $combinedURI) + { + $retriever = new UriRetriever(); + $this->assertEquals($combinedURI, $retriever->resolve($uri, $baseURI)); + } + + public function testIsValidURI() + { + $retriever = new UriRetriever(); + $this->assertTrue($retriever->isValid('http://example.com/schema')); + } } From 7ae6a673f4cafb1b91cb239f139cb0705c8e9242 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 18:57:37 +1300 Subject: [PATCH 12/16] Add tests for FileGetContents --- .../Uri/Retrievers/FileGetContents.php | 6 +- tests/Uri/Retrievers/FileGetContentsTest.php | 79 +++++++++++++++---- 2 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/JsonSchema/Uri/Retrievers/FileGetContents.php b/src/JsonSchema/Uri/Retrievers/FileGetContents.php index 7f0c399a..7019814f 100644 --- a/src/JsonSchema/Uri/Retrievers/FileGetContents.php +++ b/src/JsonSchema/Uri/Retrievers/FileGetContents.php @@ -50,8 +50,10 @@ public function retrieve($uri) $this->messageBody = $response; if (!empty($http_response_header)) { - $this->fetchContentType($http_response_header); - } else { + // $http_response_header cannot be tested, because it's defined in the method's local scope + // See http://php.net/manual/en/reserved.variables.httpresponseheader.php for more info. + $this->fetchContentType($http_response_header); // @codeCoverageIgnore + } else { // @codeCoverageIgnore // Could be a "file://" url or something else - fake up the response $this->contentType = null; } diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 7b67facb..d9b06263 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -1,27 +1,74 @@ retrieve(__DIR__ . '/Fixture/missing.json'); + /** + * @expectedException \JsonSchema\Exception\ResourceNotFoundException + */ + public function testFetchMissingFile() + { + $res = new FileGetContents(); + $res->retrieve(__DIR__ . '/Fixture/missing.json'); + } + + public function testFetchFile() + { + $res = new FileGetContents(); + $result = $res->retrieve(__DIR__ . '/../Fixture/child.json'); + $this->assertNotEmpty($result); + } + + public function testFalseReturn() + { + $res = new FileGetContents(); + + $this->setExpectedException( + '\JsonSchema\Exception\ResourceNotFoundException', + 'JSON schema not found at http://example.com/false' + ); + $res->retrieve('http://example.com/false'); + } + + public function testFetchDirectory() + { + $res = new FileGetContents(); + + $this->setExpectedException( + '\JsonSchema\Exception\ResourceNotFoundException', + 'JSON schema not found at file:///this/is/a/directory/' + ); + $res->retrieve('file:///this/is/a/directory/'); + } + + public function testContentType() + { + $res = new FileGetContents(); + + $reflector = new \ReflectionObject($res); + $fetchContentType = $reflector->getMethod('fetchContentType'); + $fetchContentType->setAccessible(true); + + $this->assertTrue($fetchContentType->invoke($res, array('Content-Type: application/json'))); + $this->assertFalse($fetchContentType->invoke($res, array('X-Some-Header: whateverValue'))); + } } +} - public function testFetchFile() +namespace JsonSchema\Uri\Retrievers +{ + function file_get_contents($uri) { - $res = new FileGetContents(); - $result = $res->retrieve(__DIR__ . '/../Fixture/child.json'); - $this->assertNotEmpty($result); + switch ($uri) { + case 'http://example.com/false': return false; + case 'file:///this/is/a/directory/': return ''; + default: return \file_get_contents($uri); + } } } From d23c81415c37d111eb5db28ca2d0ebfaabf3e70e Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 19:32:21 +1300 Subject: [PATCH 13/16] Add tests for JsonSchema\Uri\Retrievers\Curl --- src/JsonSchema/Uri/Retrievers/Curl.php | 4 ++ tests/Uri/Retrievers/CurlTest.php | 57 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/Uri/Retrievers/CurlTest.php diff --git a/src/JsonSchema/Uri/Retrievers/Curl.php b/src/JsonSchema/Uri/Retrievers/Curl.php index a4125aa6..fdc28d31 100644 --- a/src/JsonSchema/Uri/Retrievers/Curl.php +++ b/src/JsonSchema/Uri/Retrievers/Curl.php @@ -20,6 +20,8 @@ class Curl extends AbstractRetriever { protected $messageBody; + // Cannot test this, because curl_init is present on all test platforms plus mock + // @codeCoverageIgnoreStart public function __construct() { if (!function_exists('curl_init')) { @@ -27,6 +29,8 @@ public function __construct() } } + // @codeCoverageIgnoreEnd + /** * {@inheritdoc} * diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php new file mode 100644 index 00000000..f833b590 --- /dev/null +++ b/tests/Uri/Retrievers/CurlTest.php @@ -0,0 +1,57 @@ +retrieve(realpath(__DIR__ . '/../../fixtures/foobar.json')); + } + + public function testRetrieveNonexistantFile() + { + $c = new Curl(); + + $this->setExpectedException( + '\JsonSchema\Exception\ResourceNotFoundException', + 'JSON schema not found' + ); + $c->retrieve(__DIR__ . '/notARealFile'); + } + + public function testNoContentType() + { + $c = new Curl(); + $c->retrieve(realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json'); + } + } +} + +namespace JsonSchema\Uri\Retrievers +{ + function curl_exec($curl) + { + $uri = curl_getinfo($curl, \CURLINFO_EFFECTIVE_URL); + + if ($uri === realpath(__DIR__ . '/../../fixtures/foobar.json')) { + // return file with headers + $headers = implode("\n", array( + 'Content-Type: application/json' + )); + + return sprintf("%s\r\n\r\n%s", $headers, file_get_contents($uri)); + } elseif ($uri === realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json') { + // return file without headers + $uri = realpath(__DIR__ . '/../../fixtures/foobar.json'); + + return "\r\n\r\n" . file_get_contents($uri); + } + + // fallback to real curl_exec + return \curl_exec($curl); + } +} From e9af0d2fe7b7b3590be68c8de84740c9a836dce3 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 19:32:49 +1300 Subject: [PATCH 14/16] Add missing bad-syntax test file --- tests/fixtures/bad-syntax.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/fixtures/bad-syntax.json diff --git a/tests/fixtures/bad-syntax.json b/tests/fixtures/bad-syntax.json new file mode 100644 index 00000000..98232c64 --- /dev/null +++ b/tests/fixtures/bad-syntax.json @@ -0,0 +1 @@ +{ From 3a2c34552ea8575a30a23e71730c892ab134dc88 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 20:53:32 +1300 Subject: [PATCH 15/16] Restrict ignore to the exception line only --- src/JsonSchema/Uri/Retrievers/Curl.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/JsonSchema/Uri/Retrievers/Curl.php b/src/JsonSchema/Uri/Retrievers/Curl.php index fdc28d31..c4b36910 100644 --- a/src/JsonSchema/Uri/Retrievers/Curl.php +++ b/src/JsonSchema/Uri/Retrievers/Curl.php @@ -20,17 +20,14 @@ class Curl extends AbstractRetriever { protected $messageBody; - // Cannot test this, because curl_init is present on all test platforms plus mock - // @codeCoverageIgnoreStart public function __construct() { if (!function_exists('curl_init')) { - throw new \RuntimeException('cURL not installed'); + // Cannot test this, because curl_init is present on all test platforms plus mock + throw new \RuntimeException('cURL not installed'); // @codeCoverageIgnore } } - // @codeCoverageIgnoreEnd - /** * {@inheritdoc} * From 983b624fce903df0e8759a89dd7abb4c3cde48a4 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 8 Mar 2017 20:57:56 +1300 Subject: [PATCH 16/16] Fix exception scope --- src/JsonSchema/Uri/Retrievers/Curl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Uri/Retrievers/Curl.php b/src/JsonSchema/Uri/Retrievers/Curl.php index c4b36910..81c86037 100644 --- a/src/JsonSchema/Uri/Retrievers/Curl.php +++ b/src/JsonSchema/Uri/Retrievers/Curl.php @@ -9,6 +9,7 @@ namespace JsonSchema\Uri\Retrievers; +use JsonSchema\Exception\RuntimeException; use JsonSchema\Validator; /** @@ -24,7 +25,7 @@ public function __construct() { if (!function_exists('curl_init')) { // Cannot test this, because curl_init is present on all test platforms plus mock - throw new \RuntimeException('cURL not installed'); // @codeCoverageIgnore + throw new RuntimeException('cURL not installed'); // @codeCoverageIgnore } }