diff --git a/.travis.yml b/.travis.yml index ba85c50..dff859a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,22 @@ -sudo: false +dist: xenial +os: linux + +language: php git: - depth: 1 + depth: 10 cache: directories: - $HOME/.composer -language: php - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4snapshot - env: global: - - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-progress" + - DEFAULT_COMPOSER_FLAGS="--optimize-autoloader --no-interaction --no-progress" - COMPOSER_FLAGS="" stages: + - Fast Test - Static code analysis - Test @@ -31,20 +25,13 @@ before_install: - phpenv config-rm xdebug.ini || return 0 # Composer: boost installation - - composer global show -ND 2>&1 | grep "hirak/prestissimo" || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo - -install: - - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS - - composer info -D | sort - -script: - - vendor/bin/phpunit + - composer global show hirak/prestissimo -q || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo 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 @@ -55,3 +42,32 @@ jobs: - 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/php-cs-fixer fix --diff --dry-run -v || travis_terminate 1 + + - &STANDARD_TEST_JOB + stage: Test + php: 7.0 + install: + - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS + - composer info -D | sort + script: + - vendor/bin/phpunit + - + <<: *STANDARD_TEST_JOB + php: 5.6 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" + - + <<: *STANDARD_TEST_JOB + php: 7.1 + - + <<: *STANDARD_TEST_JOB + php: 7.2 + - + <<: *STANDARD_TEST_JOB + php: 7.3 + - + <<: *STANDARD_TEST_JOB + stage: Fast Test + php: 7.4 + - + <<: *STANDARD_TEST_JOB + php: nightly diff --git a/composer.json b/composer.json index 2865f1d..23e0b9c 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ } ], "require": { - "php": "^5.5 || ^7.0", - "phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0 || ^8.0", - "phpunitgoodpractices/polyfill": "^1.1" + "php": "^5.5 || ^7.0 || ^8.0", + "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.0 || ^9.0", + "phpunitgoodpractices/polyfill": "^1.4" }, "require-dev": { "johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0", diff --git a/src/Constraint/IsIdenticalString.php b/src/Constraint/IsIdenticalString.php index b0460de..e5298e9 100644 --- a/src/Constraint/IsIdenticalString.php +++ b/src/Constraint/IsIdenticalString.php @@ -15,6 +15,8 @@ class_alias(IsIdenticalStringForV5::class, IsIdenticalString::class); } elseif (version_compare(\PHPUnit\Runner\Version::id(), '8.0.0') < 0) { class_alias(IsIdenticalStringForV7::class, IsIdenticalString::class); -} else { +} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0') < 0) { class_alias(IsIdenticalStringForV8::class, IsIdenticalString::class); +} else { + class_alias(IsIdenticalStringForV9::class, IsIdenticalString::class); } diff --git a/src/Constraint/IsIdenticalStringForV9.php b/src/Constraint/IsIdenticalStringForV9.php new file mode 100644 index 0000000..5058a73 --- /dev/null +++ b/src/Constraint/IsIdenticalStringForV9.php @@ -0,0 +1,85 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint; + +use PHPUnit\Framework\Constraint\Constraint; +use PHPUnit\Framework\Constraint\IsIdentical; +use PHPUnit\Framework\ExpectationFailedException; + +/** + * @author Kuba Werłos + * + * @internal + */ +final class IsIdenticalStringForV9 extends Constraint +{ + /** + * @var mixed + */ + private $value; + + /** + * @var IsIdentical + */ + private $isIdentical; + + /** + * @param mixed $value + */ + public function __construct($value) + { + $this->value = $value; + $this->isIdentical = new IsIdentical($this->value); + } + + public function evaluate($other, string $description = '', bool $returnResult = false): ?bool + { + try { + return $this->isIdentical->evaluate($other, $description, $returnResult); + } catch (ExpectationFailedException $exception) { + $message = $exception->getMessage(); + + $additionalFailureDescription = $this->additionalFailureDescription($other); + + if ($additionalFailureDescription) { + $message .= "\n".$additionalFailureDescription; + } + + throw new ExpectationFailedException( + $message, + $exception->getComparisonFailure(), + $exception + ); + } + } + + public function toString(): string + { + return $this->isIdentical->toString(); + } + + protected function additionalFailureDescription($other): string + { + if ( + $other === $this->value + || preg_replace('/(\r\n|\n\r|\r)/', "\n", $other) !== preg_replace('/(\r\n|\n\r|\r)/', "\n", $this->value) + ) { + return ''; + } + + return ' #Warning: Strings contain different line endings! Debug using remapping ["\r" => "R", "\n" => "N", "\t" => "T"]:' + ."\n" + .' -'.str_replace(["\r", "\n", "\t"], ['R', 'N', 'T'], $other) + ."\n" + .' +'.str_replace(["\r", "\n", "\t"], ['R', 'N', 'T'], $this->value); + } +} diff --git a/tests/Constraint/IsIdenticalStringTest.php b/tests/Constraint/IsIdenticalStringTest.php index 3d32423..5d743f6 100644 --- a/tests/Constraint/IsIdenticalStringTest.php +++ b/tests/Constraint/IsIdenticalStringTest.php @@ -26,9 +26,15 @@ public function testSameStringsConstraintFail() $this->expectException( 'PHPUnit\Framework\ExpectationFailedException' ); - $this->expectExceptionMessageRegExp( - '#^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$#' - ); + if (\is_callable([$this, 'expectExceptionMessageMatches'])) { + $this->expectExceptionMessageMatches( + '#^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$#' + ); + } else { + $this->expectExceptionMessageRegExp( + '#^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$#' + ); + } $constraint = new IsIdenticalString("\r\n"); $constraint->evaluate("\n");