diff --git a/.gitattributes b/.gitattributes
index 0a5793a..d268aad 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,18 +2,18 @@
* text=auto
# Do not put this files on a distribution package (by .gitignore)
-/vendor export-ignore
-/build export-ignore
-/composer.lock export-ignore
+/vendor export-ignore
+/composer.lock export-ignore
# Do not put this files on a distribution package
-/.coveralls.yml export-ignore
-/.gitattributes export-ignore
-/.gitignore export-ignore
-/.php_cs.dist export-ignore
-/.scrutinizer.yml export-ignore
-/.travis.yml export-ignore
-/tests/ export-ignore
-/phpcs.xml.dist export-ignore
-/phpdox.xml.dist export-ignore
-/phpunit.xml.dist export-ignore
+/build/ export-ignore
+/tests/ export-ignore
+/.gitattributes export-ignore
+/.gitignore export-ignore
+/.php_cs.dist export-ignore
+/.scrutinizer.yml export-ignore
+/.travis.yml export-ignore
+/phpcs.xml.dist export-ignore
+/phpdox.xml.dist export-ignore
+/phpunit.xml.dist export-ignore
+/psalm.xml export-ignore
diff --git a/.gitignore b/.gitignore
index 8b471f1..946faf0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
# do not include this files on git
/vendor
-/build
/composer.lock
diff --git a/.php_cs.dist b/.php_cs.dist
index 91f063b..c11fe64 100644
--- a/.php_cs.dist
+++ b/.php_cs.dist
@@ -4,11 +4,13 @@ return PhpCsFixer\Config::create()
->setCacheFile(__DIR__.'/build/.php_cs.cache')
->setRules([
'@PSR2' => true,
- 'psr0' => false, // do not enforce psr-0, it rewrites 'namespace Test\' to 'namespace tests\'
+ '@PHP70Migration' => true,
+ // '@PHP70Migration:risky' => true,
// symfony
+ 'class_attributes_separation' => true,
'whitespace_after_comma_in_array' => true,
'no_empty_statement' => true,
- 'no_extra_consecutive_blank_lines' => true,
+ 'no_extra_blank_lines' => true,
'function_typehint_space' => true,
'no_alias_functions' => true,
'trailing_comma_in_multiline_array' => true,
@@ -24,11 +26,14 @@ return PhpCsFixer\Config::create()
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
+ 'yoda_style' => ['equal' => true, 'identical' => true, 'less_and_greater' => null],
+ 'standardize_not_equals' => true,
// contrib
'concat_space' => ['spacing' => 'one'],
'not_operator_with_successor_space' => true,
- 'no_blank_lines_before_namespace' => true,
+ 'single_blank_line_before_namespace' => true,
'linebreak_after_opening_tag' => true,
+ 'blank_line_after_opening_tag' => true,
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
])
diff --git a/.phplint.yml b/.phplint.yml
deleted file mode 100644
index 790809c..0000000
--- a/.phplint.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# config file for phplint
-# see https://github.com/overtrue/phplint
-
-path: ./
-cache: build/phplint.cache
-jobs: 10
-extensions:
- - php
-exclude:
- - vendor
- - build
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index d7d57ac..58a68ff 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,15 +1,19 @@
filter:
- excluded_paths:
- - 'tests/*'
- - 'vendor/*'
+ excluded_paths:
+ - 'tests/'
+ - 'vendor/'
-checks:
+build:
+ dependencies:
+ override:
+ - composer self-update --no-interaction --no-progress
+ - composer install --no-interaction
+ nodes:
php:
- code_rating: true
- duplication: true
-
-tools:
- php_code_sniffer:
- config:
- standard: "PSR2"
- external_code_coverage: true
+ tests:
+ override:
+ - php-scrutinizer-run --enable-security-analysis
+ - command: vendor/bin/phpunit --testdox --coverage-clover=coverage.clover
+ coverage:
+ file: coverage.clover
+ format: clover
diff --git a/.travis.yml b/.travis.yml
index 7b696c2..2cd038d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,42 +1,21 @@
language: php
-# php compatibility
-php:
- - 7.0
- - 7.1
- - 7.2
- - 7.3
-
-# This triggers builds to run on the new TravisCI infrastructure.
-# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
-sudo: false
+dist: xenial
-env:
- - FULL_BUILD_PHP_VERSION="7.3"
+# php compatibility
+php: ["7.0", "7.1", "7.2", "7.3", "7.4"]
before_script:
- - phpenv config-rm xdebug.ini
+ - phpenv config-rm xdebug.ini || true
- travis_retry composer install --no-interaction --no-progress --prefer-dist
script:
- - mkdir -p build/tests/
- - vendor/bin/phplint
- vendor/bin/phpcs -sp src/ tests/
- vendor/bin/php-cs-fixer fix --using-cache=no --dry-run --verbose
- - |
- if [[ $TRAVIS_PHP_VERSION == $FULL_BUILD_PHP_VERSION ]]; then
- php -dzend_extension=xdebug.so vendor/bin/phpunit --testdox --verbose --coverage-text --coverage-clover=build/tests/coverage.xml
- vendor/bin/phpstan.phar analyse --no-progress --level max src/ tests/
- else
- vendor/bin/phpunit --testdox --verbose
- fi
-
-after_script:
- - |
- if [[ $TRAVIS_PHP_VERSION == $FULL_BUILD_PHP_VERSION ]]; then
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/tests/coverage.xml
- fi
+ - vendor/bin/phpunit --testdox --verbose
+ - vendor/bin/phpstan analyse --no-progress --level max src/ tests/
+ - vendor/bin/psalm --no-progress
notifications:
- email: false
+ email:
+ if: branch = master
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4eb2191..17ad8c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,22 +1,40 @@
-# Version 2.1.0
+# CHANGELOG
+
+Notice: This library follows [SEMVER 2.0.0](https://semver.org/spec/v2.0.0.html) convention.
+
+## Version 2.1.1 2020-01-08
+
+- Improve testing, 100% code coverage, each test class uses cover related class.
+- Improve Travis-CI, do not create code coverage.
+- Improve Scrutinizer-CI, create code coverage.
+- Change development dependence from `phpstan/phpstan-shim` to `phpstan/phpstan`.
+- Remove development dependence `overtrue/phplint`.
+- Remove SensioLabs Insight.
+- Update documentation, licence, changelog, etc..
+
+## Version 2.1.0
+
- Allow create a `SchemaValidator` instance using `DOMDocument`
- Run PHPUnit 7 on PHP >= 7.1
- Run phpstan 0.10/0.11 on PHP >= 7.1
-# Version 2.0.2
+## 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
+## Version 2.0.1
+
- Fix bug when using windows path (backslashs), it does not validate
- Add docblock to buildSchemas
- Improve building, add phpstan
- Use phplint instead of php-parallel-lint
- Update dependencies using composer-require-checker
-# Version 2.0.0
+## Version 2.0.0
+
- This version does not include `Locator` nor `DownloaderInterface` implementations.
That functionality is actually outside the scope of this library and that is the reason
why it was removed. A new library was created to implement this, take a look in
@@ -37,24 +55,29 @@
- Tests: Move files served by php built-in web server to from assets to public
# Version 1.1.4
+
- Fix implementation of libxml use internal errors on `SchemaValidator::validate`
- When creating the dom document avoid warnings (fix using the correct constant)
- Avoid using versions `@stable` in `composer.json`
- Install scrutinizer/ocular only on travis and PHP 7.1
-# Version 1.1.3
+## Version 1.1.3
+
- Fix test were fialing on php 7.0 and 7.1
- class PHPUnit_Framework_TestCase is deprecated
- wait for 0.5 seconds after run the php server
-# Version 1.1.2
+## Version 1.1.2
+
- Fix project name in README.md
- Add composer.json tag xmlschema
-# Version 1.1.1
+## Version 1.1.1
+
- Remove typo on .travis.yml
-# Version 1.1.0
+## Version 1.1.0
+
- This change does not introduce any break with previous versions but add a new interface and objects
to perform the download
- Library
@@ -83,7 +106,8 @@
- Fix badges
- Drop coveralls
-# Version 1.0.0
+## Version 1.0.0
+
- Follow recommendations from sensiolabs
- Project does not depends on zip extension
- Include SensioLabs Insight
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 50d6e72..0eb1e74 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -73,11 +73,11 @@ If any of these do not pass, it will result in a complete build failure.
Before you can run these, be sure to `composer install` or `composer update`.
```shell
-vendor/bin/phplint
vendor/bin/phpcs -sp src/ tests/
vendor/bin/php-cs-fixer fix -v --dry-run
-vendor/bin/phpunit --coverage-text
-vendor/bin/phpstan.phar analyse --level max src/ tests/
+vendor/bin/phpunit --testdox
+vendor/bin/phpstan analyse --level max src/ tests/
+vendor/bin/psalm
```
## web server instance while running tests
diff --git a/LICENSE b/LICENSE
index 2d4ecaa..a74d70b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2016 - 2019 Carlos C Soto
+Copyright (c) 2016 - 2020 Carlos C Soto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index aea078a..9d61588 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# eclipxe13/XmlSchemaValidator
+# eclipxe/XmlSchemaValidator
[![Source Code][badge-source]][source]
[![Latest Version][badge-release]][release]
@@ -80,7 +80,7 @@ and don't forget to take a look in the [TODO][] and [CHANGELOG][] files.
## Copyright and License
-The eclipxe13/XmlSchemaValidator library is copyright © [Carlos C Soto](https://eclipxe.com.mx/)
+The `eclipxe/XmlSchemaValidator` library is copyright © [Carlos C Soto](https://eclipxe.com.mx/)
and licensed for use under the MIT License (MIT). Please see [LICENSE][] for more information.
[contributing]: https://github.com/eclipxe13/XmlSchemaValidator/blob/master/CONTRIBUTING.md
@@ -92,15 +92,13 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
[license]: https://github.com/eclipxe13/XmlSchemaValidator/blob/master/LICENSE
[build]: https://travis-ci.org/eclipxe13/XmlSchemaValidator?branch=master
[quality]: https://scrutinizer-ci.com/g/eclipxe13/XmlSchemaValidator/
-[sensiolabs]: https://insight.sensiolabs.com/projects/597c21ca-414b-446d-809d-7f940c3ca0a2
[coverage]: https://scrutinizer-ci.com/g/eclipxe13/XmlSchemaValidator/code-structure/master
[downloads]: https://packagist.org/packages/eclipxe/xmlschemavalidator
-[badge-source]: http://img.shields.io/badge/source-eclipxe13/XmlSchemaValidator-blue.svg?style=flat-square
+[badge-source]: https://img.shields.io/badge/source-eclipxe13/XmlSchemaValidator-blue.svg?style=flat-square
[badge-release]: https://img.shields.io/github/release/eclipxe13/XmlSchemaValidator.svg?style=flat-square
-[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
+[badge-license]: https://img.shields.io/github/license/eclipxe13/XmlSchemaValidator.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/eclipxe13/XmlSchemaValidator/master.svg?style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/XmlSchemaValidator/master.svg?style=flat-square
-[badge-sensiolabs]: https://insight.sensiolabs.com/projects/597c21ca-414b-446d-809d-7f940c3ca0a2/mini.png
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/XmlSchemaValidator/master.svg?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/xmlschemavalidator.svg?style=flat-square
diff --git a/TODO.md b/TODO.md
index 07d18bf..fabc7f0 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,4 +1,4 @@
-# eclipxe13/xmlschemavalidator To Do
+# eclipxe/xmlschemavalidator To Do
- [ ] Document usage examples
diff --git a/build/.gitignore b/build/.gitignore
new file mode 100644
index 0000000..d6b7ef3
--- /dev/null
+++ b/build/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/composer.json b/composer.json
index 7dc249d..843e32d 100644
--- a/composer.json
+++ b/composer.json
@@ -17,10 +17,10 @@
},
"require-dev": {
"phpunit/phpunit": "^6.2|^7.3",
- "overtrue/phplint": "^1.0",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.4",
- "phpstan/phpstan-shim": "^0.9|^0.10|^0.11"
+ "phpstan/phpstan": "^0.9|^0.10|^0.11",
+ "vimeo/psalm": "^3.8"
},
"autoload": {
"psr-4": {
@@ -33,11 +33,6 @@
}
},
"scripts": {
- "dev:clean": [
- "rm -rf build/",
- "find . -type f -name .phpunit.result.cache -delete",
- "mkdir -p build/"
- ],
"dev:build": ["@dev:fix-style", "@dev:test"],
"dev:check-style": [
"vendor/bin/php-cs-fixer fix --dry-run --verbose",
@@ -48,20 +43,20 @@
"vendor/bin/phpcbf --colors -sp src/ tests/"
],
"dev:test": [
- "vendor/bin/phplint",
+ "@dev:check-style",
"vendor/bin/phpunit --testdox --verbose --stop-on-failure",
- "vendor/bin/phpstan analyse --no-progress --level max src/ tests/"
+ "vendor/bin/phpstan analyse --no-progress --level max src/ tests/",
+ "vendor/bin/psalm --no-progress"
],
"dev:coverage": [
"@php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-text --coverage-html build/coverage/html/"
]
},
"scripts-descriptions": {
- "dev:clean": "DEV: recreate build directory, remove any .phpunit.result.cache files",
"dev:build": "DEV: run dev:fix-style dev:tests and dev:docs, run before pull request",
"dev:check-style": "DEV: search for code style errors using php-cs-fixer and phpcs",
"dev:fix-style": "DEV: fix code style errors using php-cs-fixer and phpcbf",
- "dev:test": "DEV: run phplint, phpunit and phpstan",
+ "dev:test": "DEV: dev:check-style, phpunit and phpstan",
"dev:coverage": "DEV: run phpunit with xdebug and storage coverage in build/coverage/html/"
}
}
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..408036f
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/XmlSchemaValidator/LibXmlException.php b/src/XmlSchemaValidator/LibXmlException.php
index 56c583a..8065b30 100644
--- a/src/XmlSchemaValidator/LibXmlException.php
+++ b/src/XmlSchemaValidator/LibXmlException.php
@@ -1,14 +1,16 @@
*/
public function buildSchemas(): Schemas
{
diff --git a/src/XmlSchemaValidator/SchemaValidatorException.php b/src/XmlSchemaValidator/SchemaValidatorException.php
index 4f7795f..c435fe9 100644
--- a/src/XmlSchemaValidator/SchemaValidatorException.php
+++ b/src/XmlSchemaValidator/SchemaValidatorException.php
@@ -1,4 +1,5 @@
*/
private $schemas = [];
/**
@@ -19,11 +20,13 @@ public function getImporterXsd(): string
{
$xsd = new \DOMDocument('1.0', 'utf-8');
$xsd->loadXML('');
+ /** @var \DOMElement $document */
+ $document = $xsd->documentElement;
foreach ($this->schemas as $schema) {
$node = $xsd->createElementNS('http://www.w3.org/2001/XMLSchema', 'import');
$node->setAttribute('namespace', $schema->getNamespace());
$node->setAttribute('schemaLocation', str_replace('\\', '/', $schema->getLocation()));
- $xsd->documentElement->appendChild($node);
+ $document->appendChild($node);
}
return $xsd->saveXML();
}
@@ -55,6 +58,7 @@ public function insert(Schema $schema): Schema
/**
* Remove a schema
* @param string $namespace
+ * @return void
*/
public function remove(string $namespace)
{
@@ -63,7 +67,7 @@ public function remove(string $namespace)
/**
* Return the complete collection of schemas as an associative array
- * @return Schema[]
+ * @return array
*/
public function all(): array
{
@@ -97,6 +101,7 @@ public function count()
return count($this->schemas);
}
+ /** @return \Traversable */
public function getIterator()
{
return new \ArrayIterator($this->schemas);
diff --git a/tests/XmlSchemaValidatorTests/LibXmlExceptionTest.php b/tests/XmlSchemaValidatorTests/LibXmlExceptionTest.php
new file mode 100644
index 0000000..1c537a5
--- /dev/null
+++ b/tests/XmlSchemaValidatorTests/LibXmlExceptionTest.php
@@ -0,0 +1,73 @@
+assertNull(LibXmlException::createFromLibXml());
+ }
+
+ public function testCallUseInternalErrorsCatchOnlyTheError()
+ {
+ // setup to use internal errors and disable error reporting
+ libxml_use_internal_errors(true);
+ error_reporting(0);
+ // create an error
+ $document = new \DOMDocument();
+ $document->loadXML('');
+ // run the code that create the LibXmlException
+ /** @var LibXmlException|null $foundException */
+ $foundException = null;
+ try {
+ LibXmlException::useInternalErrors(
+ function () {
+ $document = new \DOMDocument();
+ $document->loadXML('invalid xml');
+ }
+ );
+ } catch (LibXmlException $exception) {
+ $foundException = $exception;
+ }
+ if (null === $foundException) {
+ $this->fail('The LibXmlException was not thrown');
+ return;
+ }
+ $chain = [];
+ // assertions over the created LibXmlException
+ for ($previous = $foundException; null !== $previous; $previous = $previous->getPrevious()) {
+ $chain[] = $previous->getMessage();
+ }
+ $this->assertStringContainsString('Start tag expected', $foundException->getMessage());
+ $this->assertCount(1, $chain, 'It should only exists 1 error');
+ }
+
+ public function testCallUseInternalErrorsRestoreGlobalSettings()
+ {
+ // setup global environment
+ $libxmlUseInternalErrors = false;
+ $errorReportingLevel = E_ERROR;
+ libxml_use_internal_errors($libxmlUseInternalErrors);
+ error_reporting($errorReportingLevel);
+ LibXmlException::useInternalErrors(function () {
+ });
+ $this->assertSame($libxmlUseInternalErrors, libxml_use_internal_errors());
+ $this->assertSame($errorReportingLevel, error_reporting());
+ }
+
+ public function testCallUseInternalErrorsReturnValue()
+ {
+ $returnedValue = LibXmlException::useInternalErrors(
+ function (): string {
+ $document = new \DOMDocument();
+ $document->loadXML('');
+ return $document->saveXML();
+ }
+ );
+ $this->assertXmlStringEqualsXmlString('', $returnedValue);
+ }
+}
diff --git a/tests/XmlSchemaValidatorTests/SchemaTest.php b/tests/XmlSchemaValidatorTests/SchemaTest.php
index f1534e6..409934e 100644
--- a/tests/XmlSchemaValidatorTests/SchemaTest.php
+++ b/tests/XmlSchemaValidatorTests/SchemaTest.php
@@ -1,9 +1,11 @@
expectException(SchemaValidatorException::class);
- $this->expectExceptionMessage("Malformed XML Document: Start tag expected, '<' not found");
- new SchemaValidator(' this is not a valid xml ');
- $this->assertFalse(libxml_use_internal_errors());
+ try {
+ new SchemaValidator(' this is not a valid xml ');
+ } catch (SchemaValidatorException $exception) {
+ unset($exception);
+ }
+ $this->assertSame(E_NOTICE, error_reporting());
+ $this->assertSame(false, libxml_use_internal_errors());
}
public function testValidateWithNoSchema()
diff --git a/tests/XmlSchemaValidatorTests/SchemasTest.php b/tests/XmlSchemaValidatorTests/SchemasTest.php
index 9494ef4..041d1cf 100644
--- a/tests/XmlSchemaValidatorTests/SchemasTest.php
+++ b/tests/XmlSchemaValidatorTests/SchemasTest.php
@@ -1,10 +1,12 @@