From 48cc4ca7a80407a4a17ad37f718f19facedf4fc9 Mon Sep 17 00:00:00 2001 From: aWuttig Date: Mon, 9 Oct 2017 11:32:35 +0200 Subject: [PATCH 1/5] * [TASK] Adds php 6.4 as dep * [TASK] Fixes namespace for phpunit contstraint class --- composer.json | 6 +++- .../PHPUnit/Constraint/XSDValidation.php | 36 ++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 92deb03..8336237 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,14 @@ { "name": "Arnold Daniels", "email": "arnold@jasny.net" + }, + { + "name": "André Wuttig", + "email": "andr.wuttig@gmail.com" } ], "suggest": { - "phpunit/phpunit": "This package can only be used with PHPUnit" + "phpunit/phpunit": "~6.4" }, "autoload": { "psr-0": { diff --git a/src/Jasny/PHPUnit/Constraint/XSDValidation.php b/src/Jasny/PHPUnit/Constraint/XSDValidation.php index 38fdfa2..c808319 100644 --- a/src/Jasny/PHPUnit/Constraint/XSDValidation.php +++ b/src/Jasny/PHPUnit/Constraint/XSDValidation.php @@ -1,48 +1,50 @@ schema = $schema; if (!$this->schemaIsXml() && !file_exists($this->schema)) throw new \Exception("Schema {$this->schema} doesn't exist"); } - + /** * Check if schema contains a '<' character. - * + * * @return string */ protected function schemaIsXml() { return strpos($this->schema, '<') !== false; } - + /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. @@ -55,7 +57,7 @@ protected function schemaIsXml() protected function matches($other) { libxml_use_internal_errors(true); - + if ($other instanceof \SimpleXMLElement) { $dom = new \DOMDocument('1.0'); $dom->appendChild($dom->importNode(dom_import_simplexml($other), true)); @@ -67,10 +69,10 @@ protected function matches($other) $ret = $this->schemaIsXml() ? $dom->schemaValidateSource($this->schema) : $dom->schemaValidate($this->schema); if (!$ret) $this->errors = libxml_get_errors(); - + return $ret; } - + /** * Return the XML errors as additional failure description * @@ -80,14 +82,14 @@ protected function matches($other) protected function additionalFailureDescription($other) { $desc = ''; - + foreach ($this->errors as $error) { $desc .= " - " . trim($error->message) . "\n"; } - + return $desc; } - + /** * Returns the description of the failure * @@ -109,10 +111,10 @@ protected function failureDescription($other) } else { $xml = $other; } - + return $xml . ' ' . $this->toString(); } - + /** * Returns a string representation of the constraint. * From d4ed57323d3910d29d5696ddafeb1a9d315c0ec7 Mon Sep 17 00:00:00 2001 From: aWuttig Date: Mon, 9 Oct 2017 13:16:07 +0200 Subject: [PATCH 2/5] * [CLEANUP] PSR2 codestyle fix --- src/Jasny/PHPUnit/Constraint/XSDValidation.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Jasny/PHPUnit/Constraint/XSDValidation.php b/src/Jasny/PHPUnit/Constraint/XSDValidation.php index c808319..4e1d28a 100644 --- a/src/Jasny/PHPUnit/Constraint/XSDValidation.php +++ b/src/Jasny/PHPUnit/Constraint/XSDValidation.php @@ -22,17 +22,21 @@ class XSDValidation extends Constraint /** - * Class constructor + * XSDValidation constructor. * * @param string $schema filename or source + * @throws \Exception */ public function __construct($schema) { - if (method_exists(get_parent_class(), '__construct')) parent::__construct(); + if (method_exists(get_parent_class(), '__construct')) { + parent::__construct(); + } $this->schema = $schema; - if (!$this->schemaIsXml() && !file_exists($this->schema)) + if (!$this->schemaIsXml() && !file_exists($this->schema)) { throw new \Exception("Schema {$this->schema} doesn't exist"); + } } /** @@ -68,7 +72,9 @@ protected function matches($other) } $ret = $this->schemaIsXml() ? $dom->schemaValidateSource($this->schema) : $dom->schemaValidate($this->schema); - if (!$ret) $this->errors = libxml_get_errors(); + if (!$ret) { + $this->errors = libxml_get_errors(); + } return $ret; } From dcdecc6b8f95024289e754e2a75d6a48f20d9d98 Mon Sep 17 00:00:00 2001 From: aWuttig Date: Mon, 9 Oct 2017 15:06:36 +0200 Subject: [PATCH 3/5] * [TASK] changes vendor name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8336237..cda4640 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jasny/phpunit-xsdvalidation", + "name": "portrino/phpunit-xsdvalidation", "description": "XSD schema validation constraint for PHPUnit", "keywords": ["phpunit", "xml", "xsd"], "license": "MIT", From 71096870bad1e7b7d8b1de3f7067fe541e5b7d17 Mon Sep 17 00:00:00 2001 From: joe-pritchard Date: Wed, 10 Oct 2018 10:01:13 +0100 Subject: [PATCH 4/5] Don't call DomDocument load statically --- src/Jasny/PHPUnit/Constraint/XSDValidation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jasny/PHPUnit/Constraint/XSDValidation.php b/src/Jasny/PHPUnit/Constraint/XSDValidation.php index 4e1d28a..d468c4f 100644 --- a/src/Jasny/PHPUnit/Constraint/XSDValidation.php +++ b/src/Jasny/PHPUnit/Constraint/XSDValidation.php @@ -68,7 +68,7 @@ protected function matches($other) } elseif ($other instanceof \DOMDocument) { $dom = $other; } else { - $dom = \DOMDocument::load($other); + $dom = (new \DOMDocument)->load($other); } $ret = $this->schemaIsXml() ? $dom->schemaValidateSource($this->schema) : $dom->schemaValidate($this->schema); From c9e5d685fedb957d584b2a94ca1c4fecd39721f4 Mon Sep 17 00:00:00 2001 From: Joe Pritchard Date: Wed, 19 Dec 2018 10:59:54 +0000 Subject: [PATCH 5/5] dom load returns a boolean, need to new up dom and then call load without catching the ret value --- src/Jasny/PHPUnit/Constraint/XSDValidation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Jasny/PHPUnit/Constraint/XSDValidation.php b/src/Jasny/PHPUnit/Constraint/XSDValidation.php index d468c4f..886c49b 100644 --- a/src/Jasny/PHPUnit/Constraint/XSDValidation.php +++ b/src/Jasny/PHPUnit/Constraint/XSDValidation.php @@ -68,7 +68,8 @@ protected function matches($other) } elseif ($other instanceof \DOMDocument) { $dom = $other; } else { - $dom = (new \DOMDocument)->load($other); + $dom = new \DOMDocument('1.0'); + $dom->load($other); } $ret = $this->schemaIsXml() ? $dom->schemaValidateSource($this->schema) : $dom->schemaValidate($this->schema);