diff --git a/.composer-require-checker.json b/.composer-require-checker.json index afca844..4feaa18 100644 --- a/.composer-require-checker.json +++ b/.composer-require-checker.json @@ -4,6 +4,6 @@ "null", "true", "false", "static", "self", "parent", - "array", "string", "int", "float", "bool", "iterable", "callable", "void" + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "mixed" ] } diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8596b40..48852a6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none - run: composer update --no-progress - run: composer update --no-progress --working-dir=dev-tools diff --git a/composer.json b/composer.json index cdf4c5b..ed7c2c1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": "^7.0 || ^8.0", - "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.0 || ^9.0 || ^10.0" + "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.0 || ^9.0 || ^10.0 || ^11.0" }, "autoload": { "psr-4": { diff --git a/dev-tools/composer.json b/dev-tools/composer.json index 1c2f9c1..b6475f3 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -1,6 +1,6 @@ { "require": { - "php": "^8.1" + "php": "^8.2" }, "require-dev": { "ergebnis/composer-normalize": "*", diff --git a/src/Constraint/IsIdenticalString.php b/src/Constraint/IsIdenticalString.php index e5298e9..2651ba4 100644 --- a/src/Constraint/IsIdenticalString.php +++ b/src/Constraint/IsIdenticalString.php @@ -11,12 +11,16 @@ namespace PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint; -if (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0') < 0) { +use PHPUnit\Runner\Version; + +if (version_compare(Version::id(), '7.0.0') < 0) { class_alias(IsIdenticalStringForV5::class, IsIdenticalString::class); -} elseif (version_compare(\PHPUnit\Runner\Version::id(), '8.0.0') < 0) { +} elseif (version_compare(Version::id(), '8.0.0') < 0) { class_alias(IsIdenticalStringForV7::class, IsIdenticalString::class); -} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0') < 0) { +} elseif (version_compare(Version::id(), '9.0.0') < 0) { class_alias(IsIdenticalStringForV8::class, IsIdenticalString::class); -} else { +} elseif (version_compare(Version::id(), '11.0.0') < 0) { class_alias(IsIdenticalStringForV9::class, IsIdenticalString::class); +} else { + class_alias(IsIdenticalStringForV11::class, IsIdenticalString::class); } diff --git a/src/Constraint/IsIdenticalStringForV11.php b/src/Constraint/IsIdenticalStringForV11.php new file mode 100644 index 0000000..7ab9a95 --- /dev/null +++ b/src/Constraint/IsIdenticalStringForV11.php @@ -0,0 +1,71 @@ + + * + * 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; + +/** + * @internal + */ +final readonly class IsIdenticalStringForV11 extends Constraint +{ + private IsIdentical $isIdentical; + + public function __construct(private mixed $value) + { + $this->isIdentical = new IsIdentical($this->value); + } + + public function evaluate(mixed $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(mixed $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); + } +}