diff --git a/.phplint.yml b/.phplint.yml new file mode 100644 index 0000000..790809c --- /dev/null +++ b/.phplint.yml @@ -0,0 +1,11 @@ +# 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/.travis.yml b/.travis.yml index 6d82e29..f3c23fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,25 +4,35 @@ language: php php: - 7.0 - 7.1 + - 7.2 # This triggers builds to run on the new TravisCI infrastructure. # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ sudo: false +env: + - FULL_BUILD_PHP_VERSION="7.0" + before_script: - - travis_retry composer self-update - - travis_retry composer install --no-interaction --prefer-dist + - phpenv config-rm xdebug.ini + - travis_retry composer install --no-interaction --no-progress --prefer-dist script: - mkdir -p build/tests/ - - vendor/bin/parallel-lint src/ tests/ + - vendor/bin/phplint - vendor/bin/phpcs -sp src/ tests/ - vendor/bin/php-cs-fixer fix --using-cache=no --dry-run --verbose - - vendor/bin/phpunit --coverage-text --coverage-clover=build/tests/coverage.xml + - | + if [[ $TRAVIS_PHP_VERSION == $FULL_BUILD_PHP_VERSION ]]; then + php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-text --coverage-clover=build/tests/coverage.xml + else + vendor/bin/phpunit + fi + - vendor/bin/phpstan.phar --no-progress analyse --level max src/ tests/ after_script: - | - if [[ $TRAVIS_PHP_VERSION == '7.0' ]]; then + 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 05197f0..1cdb278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 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 - This version does not include `Locator` nor `DownloaderInterface` implementations. That functionality is actually outside the scope of this library and that is the reason diff --git a/composer.json b/composer.json index e0a6a4c..d908639 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,15 @@ ], "require": { "php": ">=7.0", - "ext-xml": "*" + "ext-dom": "*", + "ext-libxml": "*" }, "require-dev": { "phpunit/phpunit": "^6.2", - "jakub-onderka/php-parallel-lint": "^0.9", + "overtrue/phplint": "^1.0", "squizlabs/php_codesniffer": "^3.0", - "friendsofphp/php-cs-fixer": "^2.4" + "friendsofphp/php-cs-fixer": "^2.4", + "phpstan/phpstan-shim": "^0.9.1" }, "autoload": { "psr-4": { diff --git a/src/XmlSchemaValidator/Schema.php b/src/XmlSchemaValidator/Schema.php index 0d7ef2e..0ac4222 100644 --- a/src/XmlSchemaValidator/Schema.php +++ b/src/XmlSchemaValidator/Schema.php @@ -12,27 +12,17 @@ class Schema /** @var string */ private $location; - /** - * @param string $namespace - * @param string $location - */ public function __construct(string $namespace, string $location) { $this->namespace = $namespace; $this->location = $location; } - /** - * @return string - */ public function getNamespace(): string { return $this->namespace; } - /** - * @return string - */ public function getLocation(): string { return $this->location; diff --git a/src/XmlSchemaValidator/SchemaValidator.php b/src/XmlSchemaValidator/SchemaValidator.php index 84cccd9..a87a822 100644 --- a/src/XmlSchemaValidator/SchemaValidator.php +++ b/src/XmlSchemaValidator/SchemaValidator.php @@ -93,7 +93,7 @@ public function validateWithSchemas(Schemas $schemas) * Retrieve a list of namespaces based on the schemaLocation attributes * * @throws SchemaValidatorException if the content of schemaLocation is not an even number of uris - * @return Schemas + * @return Schemas|Schema[] */ public function buildSchemas(): Schemas { diff --git a/src/XmlSchemaValidator/Schemas.php b/src/XmlSchemaValidator/Schemas.php index d7c2199..aa42b85 100644 --- a/src/XmlSchemaValidator/Schemas.php +++ b/src/XmlSchemaValidator/Schemas.php @@ -22,7 +22,7 @@ public function getImporterXsd(): string foreach ($this->schemas as $schema) { $node = $xsd->createElementNS('http://www.w3.org/2001/XMLSchema', 'import'); $node->setAttribute('namespace', $schema->getNamespace()); - $node->setAttribute('schemaLocation', $schema->getLocation()); + $node->setAttribute('schemaLocation', str_replace('\\', '/', $schema->getLocation())); $xsd->documentElement->appendChild($node); } return $xsd->saveXML(); diff --git a/tests/XmlSchemaValidatorTests/SchemaValidatorTest.php b/tests/XmlSchemaValidatorTests/SchemaValidatorTest.php index 9b214b1..6e4305a 100644 --- a/tests/XmlSchemaValidatorTests/SchemaValidatorTest.php +++ b/tests/XmlSchemaValidatorTests/SchemaValidatorTest.php @@ -1,6 +1,7 @@ assertFalse($validator->validate()); $this->assertContains("The attribute 'serie' is required but missing", $validator->getLastError()); } + + public function testValidateWithSchemasUsingRemote() + { + $validator = $this->utilCreateValidator('books-valid.xml'); + $schemas = new Schemas(); + $schemas->create('http://test.org/schemas/books', 'http://localhost:8999/xsd/books.xsd'); + $validator->validateWithSchemas($schemas); + $this->assertTrue(true, 'validateWithSchemas did not throw any exception'); + } + + public function testValidateWithSchemasUsingLocal() + { + $validator = $this->utilCreateValidator('books-valid.xml'); + $schemas = new Schemas(); + $schemas->create( + 'http://test.org/schemas/books', + str_replace('/', '\\', dirname(__DIR__)) . '/public/xsd/books.xsd' // simulate windows path + ); + $validator->validateWithSchemas($schemas); + $this->assertTrue(true, 'validateWithSchemas did not throw any exception'); + } }