diff --git a/.gitattributes b/.gitattributes index 385679d..64f9589 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ /dev-tools/ export-ignore /tests/ export-ignore /.* export-ignore -/phpmd.xml export-ignore /phpunit.xml.dist export-ignore diff --git a/.travis.yml b/.travis.yml index ba85c50..a096263 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,8 @@ php: - 7.1 - 7.2 - 7.3 - - 7.4snapshot + - 7.4 + - nightly env: global: @@ -44,7 +45,7 @@ jobs: include: - stage: Static code analysis - php: 7.3 + php: 7.4 install: - travis_retry composer update $DEFAULT_COMPOSER_FLAGS - travis_retry composer update -d dev-tools $DEFAULT_COMPOSER_FLAGS @@ -52,6 +53,5 @@ jobs: script: - composer validate --strict || travis_terminate 1 - composer normalize -d ./dev-tools ./../composer.json --dry-run || travis_terminate 1 - - dev-tools/vendor/bin/composer-require-checker check composer.json --config-file=.composer-require-checker.json || travis_terminate 1 - - dev-tools/vendor/bin/phpmd src,tests text phpmd.xml || travis_terminate 1 + - dev-tools/vendor/bin/phpmd src,tests text ./dev-tools/phpmd.xml || travis_terminate 1 - dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v || travis_terminate 1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..a469cd4 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# PHP-CS-Fixer/phpunit-constraint-xmlmatchesxsd + +This version is for [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) only! Do not use it! + +We hope to see this assert to be provided by PHPUnit itself, +please help out if you can to make this happen. + +For questions visit us @ https://gitter.im/PHP-CS-Fixer/Lobby diff --git a/composer.json b/composer.json index 02b05ad..b0b86d4 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,10 @@ } ], "require": { - "php": "^5.5 || ^7.0", + "php": "^5.5 || ^7.0 || ^8.0", "ext-dom": "*", "ext-libxml": "*", - "phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0", - "phpunitgoodpractices/polyfill": "^1.1" + "phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0 || ^9.0" }, "conflict": { "hhvm": "*" diff --git a/dev-tools/composer.json b/dev-tools/composer.json index c12a204..b3edbb0 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -1,14 +1,13 @@ { "require": { - "php": "^7.3" + "php": "^7.3 || ^8.0" }, "conflict": { "hhvm": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "localheinz/composer-normalize": "^1.1", - "maglnet/composer-require-checker": "^2.0", + "friendsofphp/php-cs-fixer": "^2.15", + "ergebnis/composer-normalize": "^2.5.1", "mi-schi/phpmd-extension": "^4.3", "phpmd/phpmd": "^2.6" }, diff --git a/phpmd.xml b/dev-tools/phpmd.xml similarity index 100% rename from phpmd.xml rename to dev-tools/phpmd.xml diff --git a/src/Constraint/XmlMatchesXsdForV5.php b/src/Constraint/XmlMatchesXsdForV5.php index 5853942..b2be1b9 100644 --- a/src/Constraint/XmlMatchesXsdForV5.php +++ b/src/Constraint/XmlMatchesXsdForV5.php @@ -98,7 +98,6 @@ protected function matches($other) private function stringMatches($other) { $internalErrors = libxml_use_internal_errors(true); - $disableEntities = libxml_disable_entity_loader(true); libxml_clear_errors(); $dom = new \DOMDocument(); @@ -106,7 +105,6 @@ private function stringMatches($other) $dom->validateOnParse = true; if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - libxml_disable_entity_loader($disableEntities); $this->setXMLConstraintErrors(); libxml_clear_errors(); libxml_use_internal_errors($internalErrors); @@ -116,7 +114,6 @@ private function stringMatches($other) $dom->normalizeDocument(); - libxml_disable_entity_loader($disableEntities); libxml_clear_errors(); if (false === $result = @$dom->schemaValidateSource($this->xsd)) { diff --git a/src/Constraint/XmlMatchesXsdForV7.php b/src/Constraint/XmlMatchesXsdForV7.php index 23f8587..822e656 100644 --- a/src/Constraint/XmlMatchesXsdForV7.php +++ b/src/Constraint/XmlMatchesXsdForV7.php @@ -94,7 +94,6 @@ protected function matches($other): bool private function stringMatches($other) { $internalErrors = libxml_use_internal_errors(true); - $disableEntities = libxml_disable_entity_loader(true); libxml_clear_errors(); $dom = new \DOMDocument(); @@ -102,7 +101,6 @@ private function stringMatches($other) $dom->validateOnParse = true; if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - libxml_disable_entity_loader($disableEntities); $this->setXMLConstraintErrors(); libxml_clear_errors(); libxml_use_internal_errors($internalErrors); @@ -112,7 +110,6 @@ private function stringMatches($other) $dom->normalizeDocument(); - libxml_disable_entity_loader($disableEntities); libxml_clear_errors(); if (false === $result = @$dom->schemaValidateSource($this->xsd)) { diff --git a/src/Constraint/XmlMatchesXsdForV8.php b/src/Constraint/XmlMatchesXsdForV8.php index 6e1b906..fac5ba8 100644 --- a/src/Constraint/XmlMatchesXsdForV8.php +++ b/src/Constraint/XmlMatchesXsdForV8.php @@ -92,7 +92,6 @@ protected function matches($other): bool private function stringMatches($other) { $internalErrors = libxml_use_internal_errors(true); - $disableEntities = libxml_disable_entity_loader(true); libxml_clear_errors(); $dom = new \DOMDocument(); @@ -100,7 +99,6 @@ private function stringMatches($other) $dom->validateOnParse = true; if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - libxml_disable_entity_loader($disableEntities); $this->setXMLConstraintErrors(); libxml_clear_errors(); libxml_use_internal_errors($internalErrors); @@ -110,7 +108,6 @@ private function stringMatches($other) $dom->normalizeDocument(); - libxml_disable_entity_loader($disableEntities); libxml_clear_errors(); if (false === $result = @$dom->schemaValidateSource($this->xsd)) { diff --git a/tests/Constraint/XmlMatchesXsdTest.php b/tests/Constraint/XmlMatchesXsdTest.php index ce8e1ec..23ca9be 100644 --- a/tests/Constraint/XmlMatchesXsdTest.php +++ b/tests/Constraint/XmlMatchesXsdTest.php @@ -39,14 +39,14 @@ public function testAssertXMLMatchesXSD() } $constraint->evaluate($content); // should not throw an exception - $this->assertTrue($constraint->evaluate($content, '', true)); + static::assertTrue($constraint->evaluate($content, '', true)); } public function testXMLValidConstraintBasics() { $constraint = new XmlMatchesXsd(''); - $this->assertSame(1, $constraint->count()); - $this->assertSame('matches XSD', $constraint->toString()); + static::assertSame(1, $constraint->count()); + static::assertSame('matches XSD', $constraint->toString()); } public function testXMLValidConstraintFalse() @@ -54,7 +54,7 @@ public function testXMLValidConstraintFalse() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that boolean\# matches XSD\.$#' ); @@ -67,7 +67,7 @@ public function testXMLValidConstraintInt() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that integer\#1 matches XSD\.$#' ); @@ -80,7 +80,7 @@ public function testXMLValidConstraintInvalidXML() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that matches XSD.[\n]\[error \d{1,}\](?s).*\.$#' ); @@ -93,7 +93,7 @@ public function testXMLValidConstraintNotMatchingXML() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that matches XSD.[\n]\[error \d{1,}\](?s).*\.$#' ); @@ -106,7 +106,7 @@ public function testXMLValidConstraintNull() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that null matches XSD\.$#' ); @@ -119,7 +119,7 @@ public function testXMLValidConstraintObject() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( + $this->expectExceptionMessageRegex( '#^Failed asserting that stdClass\# matches XSD\.$#' ); @@ -142,4 +142,18 @@ private function getAssetsDir() { return __DIR__.'/../Fixtures/XmlMatchesXsdTest/'; } + + /** + * @param string $pattern + */ + private function expectExceptionMessageRegex($pattern) + { + if (method_exists($this, 'expectExceptionMessageRegExp')) { + $this->expectExceptionMessageRegExp($pattern); + } elseif (method_exists($this, 'expectDeprecationMessageMatches')) { + $this->expectDeprecationMessageMatches($pattern); + } else { + throw new \RuntimeException('Unknown how to match against exception message.'); + } + } }