Skip to content

Commit 5269893

Browse files
authored
PHP8 (#11)
1 parent 92e0ca8 commit 5269893

10 files changed

+40
-30
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/dev-tools/ export-ignore
22
/tests/ export-ignore
33
/.* export-ignore
4-
/phpmd.xml export-ignore
54
/phpunit.xml.dist export-ignore

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ php:
1515
- 7.1
1616
- 7.2
1717
- 7.3
18-
- 7.4snapshot
18+
- 7.4
19+
- nightly
1920

2021
env:
2122
global:
@@ -44,14 +45,13 @@ jobs:
4445
include:
4546
-
4647
stage: Static code analysis
47-
php: 7.3
48+
php: 7.4
4849
install:
4950
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS
5051
- travis_retry composer update -d dev-tools $DEFAULT_COMPOSER_FLAGS
5152
- composer info -d dev-tools -D | sort
5253
script:
5354
- composer validate --strict || travis_terminate 1
5455
- composer normalize -d ./dev-tools ./../composer.json --dry-run || travis_terminate 1
55-
- dev-tools/vendor/bin/composer-require-checker check composer.json --config-file=.composer-require-checker.json || travis_terminate 1
56-
- dev-tools/vendor/bin/phpmd src,tests text phpmd.xml || travis_terminate 1
56+
- dev-tools/vendor/bin/phpmd src,tests text ./dev-tools/phpmd.xml || travis_terminate 1
5757
- dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v || travis_terminate 1

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# PHP-CS-Fixer/phpunit-constraint-xmlmatchesxsd
2+
3+
This version is for [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) only! Do not use it!
4+
5+
We hope to see this assert to be provided by PHPUnit itself,
6+
please help out if you can to make this happen.
7+
8+
For questions visit us @ https://gitter.im/PHP-CS-Fixer/Lobby

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
}
1414
],
1515
"require": {
16-
"php": "^5.5 || ^7.0",
16+
"php": "^5.5 || ^7.0 || ^8.0",
1717
"ext-dom": "*",
1818
"ext-libxml": "*",
19-
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0",
20-
"phpunitgoodpractices/polyfill": "^1.1"
19+
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0 || ^9.0"
2120
},
2221
"conflict": {
2322
"hhvm": "*"

dev-tools/composer.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"require": {
3-
"php": "^7.3"
3+
"php": "^7.3 || ^8.0"
44
},
55
"conflict": {
66
"hhvm": "*"
77
},
88
"require-dev": {
9-
"friendsofphp/php-cs-fixer": "^2.14",
10-
"localheinz/composer-normalize": "^1.1",
11-
"maglnet/composer-require-checker": "^2.0",
9+
"friendsofphp/php-cs-fixer": "^2.15",
10+
"ergebnis/composer-normalize": "^2.5.1",
1211
"mi-schi/phpmd-extension": "^4.3",
1312
"phpmd/phpmd": "^2.6"
1413
},
File renamed without changes.

src/Constraint/XmlMatchesXsdForV5.php

-3
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ protected function matches($other)
9898
private function stringMatches($other)
9999
{
100100
$internalErrors = libxml_use_internal_errors(true);
101-
$disableEntities = libxml_disable_entity_loader(true);
102101
libxml_clear_errors();
103102

104103
$dom = new \DOMDocument();
105104
$dom->preserveWhiteSpace = false;
106105
$dom->validateOnParse = true;
107106

108107
if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
109-
libxml_disable_entity_loader($disableEntities);
110108
$this->setXMLConstraintErrors();
111109
libxml_clear_errors();
112110
libxml_use_internal_errors($internalErrors);
@@ -116,7 +114,6 @@ private function stringMatches($other)
116114

117115
$dom->normalizeDocument();
118116

119-
libxml_disable_entity_loader($disableEntities);
120117
libxml_clear_errors();
121118

122119
if (false === $result = @$dom->schemaValidateSource($this->xsd)) {

src/Constraint/XmlMatchesXsdForV7.php

-3
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ protected function matches($other): bool
9494
private function stringMatches($other)
9595
{
9696
$internalErrors = libxml_use_internal_errors(true);
97-
$disableEntities = libxml_disable_entity_loader(true);
9897
libxml_clear_errors();
9998

10099
$dom = new \DOMDocument();
101100
$dom->preserveWhiteSpace = false;
102101
$dom->validateOnParse = true;
103102

104103
if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
105-
libxml_disable_entity_loader($disableEntities);
106104
$this->setXMLConstraintErrors();
107105
libxml_clear_errors();
108106
libxml_use_internal_errors($internalErrors);
@@ -112,7 +110,6 @@ private function stringMatches($other)
112110

113111
$dom->normalizeDocument();
114112

115-
libxml_disable_entity_loader($disableEntities);
116113
libxml_clear_errors();
117114

118115
if (false === $result = @$dom->schemaValidateSource($this->xsd)) {

src/Constraint/XmlMatchesXsdForV8.php

-3
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ protected function matches($other): bool
9292
private function stringMatches($other)
9393
{
9494
$internalErrors = libxml_use_internal_errors(true);
95-
$disableEntities = libxml_disable_entity_loader(true);
9695
libxml_clear_errors();
9796

9897
$dom = new \DOMDocument();
9998
$dom->preserveWhiteSpace = false;
10099
$dom->validateOnParse = true;
101100

102101
if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
103-
libxml_disable_entity_loader($disableEntities);
104102
$this->setXMLConstraintErrors();
105103
libxml_clear_errors();
106104
libxml_use_internal_errors($internalErrors);
@@ -110,7 +108,6 @@ private function stringMatches($other)
110108

111109
$dom->normalizeDocument();
112110

113-
libxml_disable_entity_loader($disableEntities);
114111
libxml_clear_errors();
115112

116113
if (false === $result = @$dom->schemaValidateSource($this->xsd)) {

tests/Constraint/XmlMatchesXsdTest.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ public function testAssertXMLMatchesXSD()
3939
}
4040

4141
$constraint->evaluate($content); // should not throw an exception
42-
$this->assertTrue($constraint->evaluate($content, '', true));
42+
static::assertTrue($constraint->evaluate($content, '', true));
4343
}
4444

4545
public function testXMLValidConstraintBasics()
4646
{
4747
$constraint = new XmlMatchesXsd('');
48-
$this->assertSame(1, $constraint->count());
49-
$this->assertSame('matches XSD', $constraint->toString());
48+
static::assertSame(1, $constraint->count());
49+
static::assertSame('matches XSD', $constraint->toString());
5050
}
5151

5252
public function testXMLValidConstraintFalse()
5353
{
5454
$this->expectException(
5555
'PHPUnit\Framework\ExpectationFailedException'
5656
);
57-
$this->expectExceptionMessageRegExp(
57+
$this->expectExceptionMessageRegex(
5858
'#^Failed asserting that boolean\# matches XSD\.$#'
5959
);
6060

@@ -67,7 +67,7 @@ public function testXMLValidConstraintInt()
6767
$this->expectException(
6868
'PHPUnit\Framework\ExpectationFailedException'
6969
);
70-
$this->expectExceptionMessageRegExp(
70+
$this->expectExceptionMessageRegex(
7171
'#^Failed asserting that integer\#1 matches XSD\.$#'
7272
);
7373

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

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

@@ -106,7 +106,7 @@ public function testXMLValidConstraintNull()
106106
$this->expectException(
107107
'PHPUnit\Framework\ExpectationFailedException'
108108
);
109-
$this->expectExceptionMessageRegExp(
109+
$this->expectExceptionMessageRegex(
110110
'#^Failed asserting that null matches XSD\.$#'
111111
);
112112

@@ -119,7 +119,7 @@ public function testXMLValidConstraintObject()
119119
$this->expectException(
120120
'PHPUnit\Framework\ExpectationFailedException'
121121
);
122-
$this->expectExceptionMessageRegExp(
122+
$this->expectExceptionMessageRegex(
123123
'#^Failed asserting that stdClass\# matches XSD\.$#'
124124
);
125125

@@ -142,4 +142,18 @@ private function getAssetsDir()
142142
{
143143
return __DIR__.'/../Fixtures/XmlMatchesXsdTest/';
144144
}
145+
146+
/**
147+
* @param string $pattern
148+
*/
149+
private function expectExceptionMessageRegex($pattern)
150+
{
151+
if (method_exists($this, 'expectExceptionMessageRegExp')) {
152+
$this->expectExceptionMessageRegExp($pattern);
153+
} elseif (method_exists($this, 'expectDeprecationMessageMatches')) {
154+
$this->expectDeprecationMessageMatches($pattern);
155+
} else {
156+
throw new \RuntimeException('Unknown how to match against exception message.');
157+
}
158+
}
145159
}

0 commit comments

Comments
 (0)