Skip to content

Commit 2bd63d7

Browse files
authored
Allow PHP 8 and PHPUnit 9 (#11)
1 parent 9c5bf68 commit 2bd63d7

File tree

5 files changed

+138
-29
lines changed

5 files changed

+138
-29
lines changed

.travis.yml

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
sudo: false
1+
dist: xenial
2+
os: linux
3+
4+
language: php
25

36
git:
4-
depth: 1
7+
depth: 10
58

69
cache:
710
directories:
811
- $HOME/.composer
912

10-
language: php
11-
12-
php:
13-
- 5.6
14-
- 7.0
15-
- 7.1
16-
- 7.2
17-
- 7.3
18-
- 7.4snapshot
19-
2013
env:
2114
global:
22-
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-progress"
15+
- DEFAULT_COMPOSER_FLAGS="--optimize-autoloader --no-interaction --no-progress"
2316
- COMPOSER_FLAGS=""
2417

2518
stages:
19+
- Fast Test
2620
- Static code analysis
2721
- Test
2822

@@ -31,20 +25,13 @@ before_install:
3125
- phpenv config-rm xdebug.ini || return 0
3226

3327
# Composer: boost installation
34-
- composer global show -ND 2>&1 | grep "hirak/prestissimo" || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo
35-
36-
install:
37-
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
38-
- composer info -D | sort
39-
40-
script:
41-
- vendor/bin/phpunit
28+
- composer global show hirak/prestissimo -q || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo
4229

4330
jobs:
4431
include:
4532
-
4633
stage: Static code analysis
47-
php: 7.3
34+
php: 7.4
4835
install:
4936
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS
5037
- travis_retry composer update -d dev-tools $DEFAULT_COMPOSER_FLAGS
@@ -55,3 +42,32 @@ jobs:
5542
- dev-tools/vendor/bin/composer-require-checker check composer.json --config-file=.composer-require-checker.json || travis_terminate 1
5643
- dev-tools/vendor/bin/phpmd src,tests text phpmd.xml || travis_terminate 1
5744
- dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v || travis_terminate 1
45+
46+
- &STANDARD_TEST_JOB
47+
stage: Test
48+
php: 7.0
49+
install:
50+
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
51+
- composer info -D | sort
52+
script:
53+
- vendor/bin/phpunit
54+
-
55+
<<: *STANDARD_TEST_JOB
56+
php: 5.6
57+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
58+
-
59+
<<: *STANDARD_TEST_JOB
60+
php: 7.1
61+
-
62+
<<: *STANDARD_TEST_JOB
63+
php: 7.2
64+
-
65+
<<: *STANDARD_TEST_JOB
66+
php: 7.3
67+
-
68+
<<: *STANDARD_TEST_JOB
69+
stage: Fast Test
70+
php: 7.4
71+
-
72+
<<: *STANDARD_TEST_JOB
73+
php: nightly

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^5.5 || ^7.0",
14-
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0",
15-
"phpunitgoodpractices/polyfill": "^1.1"
13+
"php": "^5.5 || ^7.0 || ^8.0",
14+
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.0 || ^9.0",
15+
"phpunitgoodpractices/polyfill": "^1.4"
1616
},
1717
"require-dev": {
1818
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",

src/Constraint/IsIdenticalString.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class_alias(IsIdenticalStringForV5::class, IsIdenticalString::class);
1616
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '8.0.0') < 0) {
1717
class_alias(IsIdenticalStringForV7::class, IsIdenticalString::class);
18-
} else {
18+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0') < 0) {
1919
class_alias(IsIdenticalStringForV8::class, IsIdenticalString::class);
20+
} else {
21+
class_alias(IsIdenticalStringForV9::class, IsIdenticalString::class);
2022
}
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer / PHPUnit Constraint IsIdenticalString.
5+
*
6+
* (c) Dariusz Rumiński <dariusz.ruminski@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint;
13+
14+
use PHPUnit\Framework\Constraint\Constraint;
15+
use PHPUnit\Framework\Constraint\IsIdentical;
16+
use PHPUnit\Framework\ExpectationFailedException;
17+
18+
/**
19+
* @author Kuba Werłos <werlos@gmail.com>
20+
*
21+
* @internal
22+
*/
23+
final class IsIdenticalStringForV9 extends Constraint
24+
{
25+
/**
26+
* @var mixed
27+
*/
28+
private $value;
29+
30+
/**
31+
* @var IsIdentical
32+
*/
33+
private $isIdentical;
34+
35+
/**
36+
* @param mixed $value
37+
*/
38+
public function __construct($value)
39+
{
40+
$this->value = $value;
41+
$this->isIdentical = new IsIdentical($this->value);
42+
}
43+
44+
public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
45+
{
46+
try {
47+
return $this->isIdentical->evaluate($other, $description, $returnResult);
48+
} catch (ExpectationFailedException $exception) {
49+
$message = $exception->getMessage();
50+
51+
$additionalFailureDescription = $this->additionalFailureDescription($other);
52+
53+
if ($additionalFailureDescription) {
54+
$message .= "\n".$additionalFailureDescription;
55+
}
56+
57+
throw new ExpectationFailedException(
58+
$message,
59+
$exception->getComparisonFailure(),
60+
$exception
61+
);
62+
}
63+
}
64+
65+
public function toString(): string
66+
{
67+
return $this->isIdentical->toString();
68+
}
69+
70+
protected function additionalFailureDescription($other): string
71+
{
72+
if (
73+
$other === $this->value
74+
|| preg_replace('/(\r\n|\n\r|\r)/', "\n", $other) !== preg_replace('/(\r\n|\n\r|\r)/', "\n", $this->value)
75+
) {
76+
return '';
77+
}
78+
79+
return ' #Warning: Strings contain different line endings! Debug using remapping ["\r" => "R", "\n" => "N", "\t" => "T"]:'
80+
."\n"
81+
.' -'.str_replace(["\r", "\n", "\t"], ['R', 'N', 'T'], $other)
82+
."\n"
83+
.' +'.str_replace(["\r", "\n", "\t"], ['R', 'N', 'T'], $this->value);
84+
}
85+
}

tests/Constraint/IsIdenticalStringTest.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ public function testSameStringsConstraintFail()
2626
$this->expectException(
2727
'PHPUnit\Framework\ExpectationFailedException'
2828
);
29-
$this->expectExceptionMessageRegExp(
30-
'#^Failed asserting that two strings are identical\.[\n] \#Warning\: Strings contain different line endings\! Debug using remapping \["\\\\r" => "R", "\\\\n" => "N", "\\\\t" => "T"\]\:\n \-N\n \+RN$#'
31-
);
29+
if (\is_callable([$this, 'expectExceptionMessageMatches'])) {
30+
$this->expectExceptionMessageMatches(
31+
'#^Failed asserting that two strings are identical\.[\n] \#Warning\: Strings contain different line endings\! Debug using remapping \["\\\\r" => "R", "\\\\n" => "N", "\\\\t" => "T"\]\:\n \-N\n \+RN$#'
32+
);
33+
} else {
34+
$this->expectExceptionMessageRegExp(
35+
'#^Failed asserting that two strings are identical\.[\n] \#Warning\: Strings contain different line endings\! Debug using remapping \["\\\\r" => "R", "\\\\n" => "N", "\\\\t" => "T"\]\:\n \-N\n \+RN$#'
36+
);
37+
}
3238

3339
$constraint = new IsIdenticalString("\r\n");
3440
$constraint->evaluate("\n");

0 commit comments

Comments
 (0)