Skip to content

Commit

Permalink
PHP8 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum authored Oct 12, 2020
1 parent 92e0ca8 commit 5269893
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/dev-tools/ export-ignore
/tests/ export-ignore
/.* export-ignore
/phpmd.xml export-ignore
/phpunit.xml.dist export-ignore
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4
- nightly

env:
global:
Expand Down Expand Up @@ -44,14 +45,13 @@ 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
- composer info -d dev-tools -D | sort
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
7 changes: 3 additions & 4 deletions dev-tools/composer.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions src/Constraint/XmlMatchesXsdForV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ 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();
$dom->preserveWhiteSpace = false;
$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);
Expand All @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions src/Constraint/XmlMatchesXsdForV7.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ 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();
$dom->preserveWhiteSpace = false;
$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);
Expand All @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions src/Constraint/XmlMatchesXsdForV8.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ 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();
$dom->preserveWhiteSpace = false;
$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);
Expand All @@ -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)) {
Expand Down
32 changes: 23 additions & 9 deletions tests/Constraint/XmlMatchesXsdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ 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()
{
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that boolean\# matches XSD\.$#'
);

Expand All @@ -67,7 +67,7 @@ public function testXMLValidConstraintInt()
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that integer\#1 matches XSD\.$#'
);

Expand All @@ -80,7 +80,7 @@ public function testXMLValidConstraintInvalidXML()
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that <a></b> matches XSD.[\n]\[error \d{1,}\](?s).*\.$#'
);

Expand All @@ -93,7 +93,7 @@ public function testXMLValidConstraintNotMatchingXML()
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that <a></a> matches XSD.[\n]\[error \d{1,}\](?s).*\.$#'
);

Expand All @@ -106,7 +106,7 @@ public function testXMLValidConstraintNull()
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that null matches XSD\.$#'
);

Expand All @@ -119,7 +119,7 @@ public function testXMLValidConstraintObject()
$this->expectException(
'PHPUnit\Framework\ExpectationFailedException'
);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'#^Failed asserting that stdClass\# matches XSD\.$#'
);

Expand All @@ -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.');
}
}
}

0 comments on commit 5269893

Please sign in to comment.