From 6f9bc8a0b5a496c19a784155305ed3fc1f4c5ad8 Mon Sep 17 00:00:00 2001 From: giansalex Date: Fri, 26 Jan 2018 13:58:15 -0500 Subject: [PATCH] up coverage --- .gitignore | 1 + src/Ubl/SchemaValidator.php | 33 +++++++++++++--------------- tests/Ubl/SchemaValidatorV20Test.php | 5 +++-- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index d6a2cc5..86d3550 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ +/build/ /vendor/ /composer.lock .DS_Store diff --git a/src/Ubl/SchemaValidator.php b/src/Ubl/SchemaValidator.php index 368a5be..c22aa75 100644 --- a/src/Ubl/SchemaValidator.php +++ b/src/Ubl/SchemaValidator.php @@ -85,33 +85,30 @@ private function getErrors() public function getError($error) { - $msg = ''; - switch ($error->level) { - case LIBXML_ERR_WARNING: - $msg .= 'Alerta'; - break; - case LIBXML_ERR_ERROR: - $msg .= 'Error'; - break; - case LIBXML_ERR_FATAL: - $msg .= 'Error Fatal'; - break; - } - $msg .= ' '.$error->code.': '.trim($error->message).' en la linea '.$error->line; + $msg = $error->code.': '.trim($error->message).' en la linea '.$error->line; return $msg; } private function getFilename($rootName) { - if ($this->version == '2.0') { - $name = $rootName == 'DespatchAdvice' ? 'UBL-DespatchAdvice-2.0' : 'UBLPE-'.$rootName.'-1.0'; - } else { - $name = 'UBL-'.$rootName.'-2.1'; - } + $name = $this->getName($rootName); $path = __DIR__.'/../xsd/'.$this->version.'/maindoc/'.$name.'.xsd'; return $path; } + + /** + * @param $rootName + * @return string + */ + private function getName($rootName) + { + if ($this->version == '2.0') { + return $rootName == 'DespatchAdvice' ? 'UBL-DespatchAdvice-2.0' : 'UBLPE-' . $rootName . '-1.0'; + } + + return 'UBL-' . $rootName . '-2.1'; + } } diff --git a/tests/Ubl/SchemaValidatorV20Test.php b/tests/Ubl/SchemaValidatorV20Test.php index 14694a0..a625bd5 100644 --- a/tests/Ubl/SchemaValidatorV20Test.php +++ b/tests/Ubl/SchemaValidatorV20Test.php @@ -51,8 +51,9 @@ public function testNotFoundSchema() public function testInvalidSchema() { - $content = file_get_contents(__DIR__.'/../Resources/error.xml'); - $result = $this->validator->validate($content); + $doc = new \DOMDocument(); + $doc->load(__DIR__.'/../Resources/error.xml'); + $result = $this->validator->validate($doc); $this->assertFalse($result); $this->assertNotEmpty($this->validator->getMessage());