Skip to content

Commit

Permalink
Version 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Sep 4, 2018
2 parents f3053a5 + 81ab965 commit 8fcbaf2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 2.0.2
- Fix bug when running on PHP >= 7.1 and warning was raised when call `DOMDocument::schemaValidateSource`
making impossible to obtain errors from `libxml_clear_errors` and throw a new `LibXmlException`
- Add a new test `SchemaValidatorTest::testValidateWithEmptySchema` to make sure that
a `LibXmlException` exception is raised

# Version 2.0.1
- Fix bug when using windows path (backslashs), it does not validate
- Add docblock to buildSchemas
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $schemas->create('http://example.org/schemas/x1', './local-schemas/x1.xsd');

// validateWithSchemas does not return boolean, it throws an exception
try {
$validator->validateWithSchemas($schemas));
$validator->validateWithSchemas($schemas);
} catch (\XmlSchemaValidator\SchemaValidatorException $ex) {
echo 'Found error: ' . $ex->getMessage();
}
Expand Down
3 changes: 3 additions & 0 deletions src/XmlSchemaValidator/LibXmlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static function throwFromLibXml()
*/
public static function useInternalErrors(callable $callable)
{
$previousErrorReporting = error_reporting();
error_reporting(0);
$previousLibXmlUseInternalErrors = libxml_use_internal_errors(true);
if ($previousLibXmlUseInternalErrors) {
libxml_clear_errors();
Expand All @@ -47,6 +49,7 @@ public static function useInternalErrors(callable $callable)
try {
static::throwFromLibXml();
} finally {
error_reporting($previousErrorReporting);
libxml_use_internal_errors($previousLibXmlUseInternalErrors);
}
return $return;
Expand Down
1 change: 1 addition & 0 deletions src/XmlSchemaValidator/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function getLastError(): string
*
* @param Schemas $schemas
* @return void
*
* @throws LibXmlException if schema validation fails
*/
public function validateWithSchemas(Schemas $schemas)
Expand Down
14 changes: 14 additions & 0 deletions tests/XmlSchemaValidatorTests/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,18 @@ public function testValidateWithSchemasUsingLocal()
$validator->validateWithSchemas($schemas);
$this->assertTrue(true, 'validateWithSchemas did not throw any exception');
}

public function testValidateWithEmptySchema()
{
$validator = $this->utilCreateValidator('books-valid.xml');
$schemas = new Schemas();
$schemas->create(
'http://test.org/schemas/books',
$this->utilAssetLocation('empty.xsd')
);

$this->expectException(SchemaValidatorException::class);
$this->expectExceptionMessage('Failed to parse the XML resource');
$validator->validateWithSchemas($schemas);
}
}
Empty file added tests/assets/empty.xsd
Empty file.

0 comments on commit 8fcbaf2

Please sign in to comment.