Skip to content

Commit

Permalink
Version 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Jul 17, 2018
2 parents 3d9a51c + 9f7c7f0 commit f3053a5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .phplint.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions src/XmlSchemaValidator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/XmlSchemaValidator/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/XmlSchemaValidator/Schemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions tests/XmlSchemaValidatorTests/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace XmlSchemaValidatorTests;

use XmlSchemaValidator\Schemas;
use XmlSchemaValidator\SchemaValidator;
use XmlSchemaValidator\SchemaValidatorException;

Expand Down Expand Up @@ -94,4 +95,25 @@ public function testValidateInvalidXmlSecondSchemas()
$this->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');
}
}

0 comments on commit f3053a5

Please sign in to comment.