diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..8492546 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,11 @@ +{ + "branches": ["master"], + "tagFormat": "${version}", + "plugins": [ + ["@semantic-release/commit-analyzer", { + "preset": "conventionalcommits", + "presetConfig": {} + }], + "@semantic-release/github", + "@semantic-release/release-notes-generator"] +} \ No newline at end of file diff --git a/composer.json b/composer.json index 6aeef61..e83632f 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ "minimum-stability": "RC", "require": { - "php": "^7.4 | ^8.0", - "ext-dom": "*", - "codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0" + "php": "^8.2 || ^8.3 || ^8.4", + "phpunit/phpunit": "^11.5 || ^12.0", + "ext-dom": "*" }, "autoload":{ "classmap": ["src/"] diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c7dfed4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 9 + paths: + - tests/ + - src/ \ No newline at end of file diff --git a/src/Codeception/Util/Shared/Asserts.php b/src/Codeception/Util/Shared/Asserts.php index eef1846..3e647ef 100644 --- a/src/Codeception/Util/Shared/Asserts.php +++ b/src/Codeception/Util/Shared/Asserts.php @@ -4,16 +4,19 @@ namespace Codeception\Util\Shared; -use Codeception\PHPUnit\TestCase; -use PHPUnit\Framework\Assert as PHPUnitAssert; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint; use PHPUnit\Framework\Constraint\LogicalNot; +use ReflectionClass; trait Asserts { use InheritedAsserts; - protected function assert(array $arguments, bool $not = false) + /** + * @param array{0: string} $arguments + */ + protected function assert(array $arguments, bool $not = false): void { $not = $not ? 'Not' : ''; $method = ucfirst(array_shift($arguments)); @@ -27,10 +30,21 @@ protected function assert(array $arguments, bool $not = false) $not = ''; } - call_user_func_array([PHPUnitAssert::class, 'assert' . $not . $method], $arguments); + $fullMethod = "assert{$not}{$method}"; + + $rc = new ReflectionClass(Assert::class); + if ($rc->hasMethod($fullMethod) && $rc->getMethod($fullMethod)->isStatic()) { + $rc->getMethod($fullMethod)->invokeArgs(null, $arguments); + } else { + throw new \RuntimeException("Method Assert::{$fullMethod} does not exist"); + } } - protected function assertNot($arguments) + /** + * @param array{0: string} $arguments + * @return void + */ + protected function assertNot(array $arguments): void { $this->assert($arguments, true); } @@ -38,9 +52,9 @@ protected function assertNot($arguments) /** * Asserts that a file does not exist. */ - protected function assertFileNotExists(string $filename, string $message = '') + protected function assertFileNotExists(string $filename, string $message = ''): void { - TestCase::assertFileDoesNotExist($filename, $message); + Assert::assertFileDoesNotExist($filename, $message); } /** @@ -49,56 +63,49 @@ protected function assertFileNotExists(string $filename, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertGreaterOrEquals($expected, $actual, string $message = '') + protected function assertGreaterOrEquals($expected, $actual, string $message = ''): void { - TestCase::assertGreaterThanOrEqual($expected, $actual, $message); + Assert::assertGreaterThanOrEqual($expected, $actual, $message); } /** * Asserts that a variable is empty. - * - * @param mixed $actual */ - protected function assertIsEmpty($actual, string $message = '') + protected function assertIsEmpty(mixed $actual, string $message = ''): void { - TestCase::assertEmpty($actual, $message); + Assert::assertEmpty($actual, $message); } /** * Asserts that a value is smaller than or equal to another value. - * - * @param mixed $expected - * @param mixed $actual */ - protected function assertLessOrEquals($expected, $actual, string $message = '') + protected function assertLessOrEquals(mixed $expected, mixed $actual, string $message = ''): void { - TestCase::assertLessThanOrEqual($expected, $actual, $message); + Assert::assertLessThanOrEqual($expected, $actual, $message); } /** * Asserts that a string does not match a given regular expression. */ - protected function assertNotRegExp(string $pattern, string $string, string $message = '') + protected function assertNotRegExp(string $pattern, string $string, string $message = ''): void { - TestCase::assertDoesNotMatchRegularExpression($pattern, $string, $message); + Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message); } /** * Asserts that a string matches a given regular expression. */ - protected function assertRegExp(string $pattern, string $string, string $message = '') + protected function assertRegExp(string $pattern, string $string, string $message = ''): void { - TestCase::assertMatchesRegularExpression($pattern, $string, $message); + Assert::assertMatchesRegularExpression($pattern, $string, $message); } /** * Evaluates a PHPUnit\Framework\Constraint matcher object. - * - * @param mixed $value */ - protected function assertThatItsNot($value, PHPUnitConstraint $constraint, string $message = '') + protected function assertThatItsNot(mixed $value, PHPUnitConstraint $constraint, string $message = ''): void { $constraint = new LogicalNot($constraint); - TestCase::assertThat($value, $constraint, $message); + Assert::assertThat($value, $constraint, $message); } } diff --git a/src/Codeception/Util/Shared/InheritedAsserts.php b/src/Codeception/Util/Shared/InheritedAsserts.php index f67c4f5..7f2fd8f 100644 --- a/src/Codeception/Util/Shared/InheritedAsserts.php +++ b/src/Codeception/Util/Shared/InheritedAsserts.php @@ -4,122 +4,108 @@ namespace Codeception\Util\Shared; -use Codeception\PHPUnit\TestCase; +use ArrayAccess; use PHPUnit\Framework\Assert; use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint; use PHPUnit\Framework\Constraint\LogicalNot; use PHPUnit\Framework\Constraint\StringMatchesFormatDescription; +use ReflectionClass; trait InheritedAsserts { /** * Asserts that an array has a specified key. - * - * @param int|string $key - * @param array|\ArrayAccess $array + * @param array|ArrayAccess $array */ - protected function assertArrayHasKey($key, $array, string $message = '') + protected function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void { Assert::assertArrayHasKey($key, $array, $message); } /** * Asserts that an array does not have a specified key. - * - * @param int|string $key - * @param array|\ArrayAccess $array + * @param array|ArrayAccess $array */ - protected function assertArrayNotHasKey($key, $array, string $message = '') + protected function assertArrayNotHasKey(int|string $key, array|\ArrayAccess $array, string $message = ''): void { Assert::assertArrayNotHasKey($key, $array, $message); } /** * Asserts that a class has a specified attribute. + * @param class-string $className */ - protected function assertClassHasAttribute(string $attributeName, string $className, string $message = '') + protected function assertClassHasAttribute(string $attributeName, string $className, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); - - if (method_exists(Assert::class, 'assertClassHasAttribute')) { - Assert::assertClassHasAttribute($attributeName, $className, $message); - } else { - Assert::assertTrue(property_exists($className, $attributeName), $message); - } + Assert::assertTrue(property_exists($className, $attributeName), $message); } /** * Asserts that a class has a specified static attribute. + * @param class-string $className */ - protected function assertClassHasStaticAttribute(string $attributeName, string $className, string $message = '') + protected function assertClassHasStaticAttribute(string $attributeName, string $className, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); - if (method_exists(Assert::class, 'assertClassHasStaticAttribute')) { - Assert::assertClassHasStaticAttribute($attributeName, $className, $message); - } else { - Assert::assertTrue(self::hasStaticAttribute($attributeName, $className), $message); - } + Assert::assertTrue($this->hasStaticAttribute($attributeName, $className), $message); } /** * Asserts that a class does not have a specified attribute. + * @param class-string $className */ - protected function assertClassNotHasAttribute(string $attributeName, string $className, string $message = '') + protected function assertClassNotHasAttribute(string $attributeName, string $className, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); - - if (method_exists(Assert::class, 'assertClassNotHasAttribute')) { - Assert::assertClassNotHasAttribute($attributeName, $className, $message); - } else { - Assert::assertFalse(property_exists($className, $attributeName), $message); - } + Assert::assertFalse(property_exists($className, $attributeName), $message); } /** * Asserts that a class does not have a specified static attribute. + * @param class-string $className */ - protected function assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = '') + protected function assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); - - if (method_exists(Assert::class, 'assertClassNotHasStaticAttribute')) { - Assert::assertClassNotHasStaticAttribute($attributeName, $className, $message); - } else { - Assert::assertFalse(self::hasStaticAttribute($attributeName, $className), $message); - } + Assert::assertFalse($this->hasStaticAttribute($attributeName, $className), $message); } /** * Asserts that a haystack contains a needle. * - * @param mixed $needle + * @param iterable $haystack */ - protected function assertContains($needle, iterable $haystack, string $message = '') + protected function assertContains(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertContains($needle, $haystack, $message); } /** - * @param mixed $needle + * @param iterable $haystack */ - protected function assertContainsEquals($needle, iterable $haystack, string $message = '') + protected function assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertContainsEquals($needle, $haystack, $message); } /** * Asserts that a haystack contains only values of a given type. + * @param 'array'|'bool'|'boolean'|'callable'|'double'|'float'|'int'|'integer'|'iterable'|'null'|'numeric'|'object'|'real'|'resource'|'resource (closed)'|'scalar'|'string' $type + * @param iterable $haystack */ - protected function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = '') + protected function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { Assert::assertContainsOnly($type, $haystack, $isNativeType, $message); } /** * Asserts that a haystack contains only instances of a given class name. + * @param class-string $className + * @param iterable $haystack */ - protected function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = '') + protected function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void { Assert::assertContainsOnlyInstancesOf($className, $haystack, $message); } @@ -127,9 +113,9 @@ protected function assertContainsOnlyInstancesOf(string $className, iterable $ha /** * Asserts the number of elements of an array, Countable or Traversable. * - * @param \Countable|iterable $haystack + * @param \Countable|iterable $haystack */ - protected function assertCount(int $expectedCount, $haystack, string $message = '') + protected function assertCount(int $expectedCount, \Countable|iterable $haystack, string $message = ''): void { Assert::assertCount($expectedCount, $haystack, $message); } @@ -137,7 +123,7 @@ protected function assertCount(int $expectedCount, $haystack, string $message = /** * Asserts that a directory does not exist. */ - protected function assertDirectoryDoesNotExist(string $directory, string $message = '') + protected function assertDirectoryDoesNotExist(string $directory, string $message = ''): void { Assert::assertDirectoryDoesNotExist($directory, $message); } @@ -145,7 +131,7 @@ protected function assertDirectoryDoesNotExist(string $directory, string $messag /** * Asserts that a directory exists. */ - protected function assertDirectoryExists(string $directory, string $message = '') + protected function assertDirectoryExists(string $directory, string $message = ''): void { Assert::assertDirectoryExists($directory, $message); } @@ -153,7 +139,7 @@ protected function assertDirectoryExists(string $directory, string $message = '' /** * Asserts that a directory exists and is not readable. */ - protected function assertDirectoryIsNotReadable(string $directory, string $message = '') + protected function assertDirectoryIsNotReadable(string $directory, string $message = ''): void { Assert::assertDirectoryIsNotReadable($directory, $message); } @@ -161,7 +147,7 @@ protected function assertDirectoryIsNotReadable(string $directory, string $messa /** * Asserts that a directory exists and is not writable. */ - protected function assertDirectoryIsNotWritable(string $directory, string $message = '') + protected function assertDirectoryIsNotWritable(string $directory, string $message = ''): void { Assert::assertDirectoryIsNotWritable($directory, $message); } @@ -169,7 +155,7 @@ protected function assertDirectoryIsNotWritable(string $directory, string $messa /** * Asserts that a directory exists and is readable. */ - protected function assertDirectoryIsReadable(string $directory, string $message = '') + protected function assertDirectoryIsReadable(string $directory, string $message = ''): void { Assert::assertDirectoryIsReadable($directory, $message); } @@ -177,7 +163,7 @@ protected function assertDirectoryIsReadable(string $directory, string $message /** * Asserts that a directory exists and is writable. */ - protected function assertDirectoryIsWritable(string $directory, string $message = '') + protected function assertDirectoryIsWritable(string $directory, string $message = ''): void { Assert::assertDirectoryIsWritable($directory, $message); } @@ -185,9 +171,9 @@ protected function assertDirectoryIsWritable(string $directory, string $message /** * Asserts that a string does not match a given regular expression. */ - protected function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = '') + protected function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void { - TestCase::assertDoesNotMatchRegularExpression($pattern, $string, $message); + Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message); } /** @@ -197,7 +183,7 @@ protected function assertDoesNotMatchRegularExpression(string $pattern, string $ * * @phpstan-assert empty $actual */ - protected function assertEmpty($actual, string $message = '') + protected function assertEmpty($actual, string $message = ''): void { Assert::assertEmpty($actual, $message); } @@ -208,7 +194,7 @@ protected function assertEmpty($actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertEquals($expected, $actual, string $message = '') + protected function assertEquals($expected, $actual, string $message = ''): void { Assert::assertEquals($expected, $actual, $message); } @@ -219,9 +205,9 @@ protected function assertEquals($expected, $actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertEqualsCanonicalizing($expected, $actual, string $message = '') + protected function assertEqualsCanonicalizing($expected, $actual, string $message = ''): void { - TestCase::assertEqualsCanonicalizing($expected, $actual, $message); + Assert::assertEqualsCanonicalizing($expected, $actual, $message); } /** @@ -230,9 +216,9 @@ protected function assertEqualsCanonicalizing($expected, $actual, string $messag * @param mixed $expected * @param mixed $actual */ - protected function assertEqualsIgnoringCase($expected, $actual, string $message = '') + protected function assertEqualsIgnoringCase($expected, $actual, string $message = ''): void { - TestCase::assertEqualsIgnoringCase($expected, $actual, $message); + Assert::assertEqualsIgnoringCase($expected, $actual, $message); } /** @@ -241,9 +227,9 @@ protected function assertEqualsIgnoringCase($expected, $actual, string $message * @param mixed $expected * @param mixed $actual */ - protected function assertEqualsWithDelta($expected, $actual, float $delta, string $message = '') + protected function assertEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void { - TestCase::assertEqualsWithDelta($expected, $actual, $delta, $message); + Assert::assertEqualsWithDelta($expected, $actual, $delta, $message); } /** @@ -253,7 +239,7 @@ protected function assertEqualsWithDelta($expected, $actual, float $delta, strin * * @phpstan-assert false $condition */ - protected function assertFalse($condition, string $message = '') + protected function assertFalse($condition, string $message = ''): void { Assert::assertFalse($condition, $message); } @@ -261,15 +247,15 @@ protected function assertFalse($condition, string $message = '') /** * Asserts that a file does not exist. */ - protected function assertFileDoesNotExist(string $filename, string $message = '') + protected function assertFileDoesNotExist(string $filename, string $message = ''): void { - TestCase::assertFileDoesNotExist($filename, $message); + Assert::assertFileDoesNotExist($filename, $message); } /** * Asserts that the contents of one file is equal to the contents of another file. */ - protected function assertFileEquals(string $expected, string $actual, string $message = '') + protected function assertFileEquals(string $expected, string $actual, string $message = ''): void { Assert::assertFileEquals($expected, $actual, $message); } @@ -277,7 +263,7 @@ protected function assertFileEquals(string $expected, string $actual, string $me /** * Asserts that the contents of one file is equal to the contents of another file (canonicalizing). */ - protected function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = '') + protected function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { Assert::assertFileEqualsCanonicalizing($expected, $actual, $message); } @@ -285,7 +271,7 @@ protected function assertFileEqualsCanonicalizing(string $expected, string $actu /** * Asserts that the contents of one file is equal to the contents of another file (ignoring case). */ - protected function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = '') + protected function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { Assert::assertFileEqualsIgnoringCase($expected, $actual, $message); } @@ -293,7 +279,7 @@ protected function assertFileEqualsIgnoringCase(string $expected, string $actual /** * Asserts that a file exists. */ - protected function assertFileExists(string $filename, string $message = '') + protected function assertFileExists(string $filename, string $message = ''): void { Assert::assertFileExists($filename, $message); } @@ -301,7 +287,7 @@ protected function assertFileExists(string $filename, string $message = '') /** * Asserts that a file exists and is not readable. */ - protected function assertFileIsNotReadable(string $file, string $message = '') + protected function assertFileIsNotReadable(string $file, string $message = ''): void { Assert::assertFileIsNotReadable($file, $message); } @@ -309,7 +295,7 @@ protected function assertFileIsNotReadable(string $file, string $message = '') /** * Asserts that a file exists and is not writable. */ - protected function assertFileIsNotWritable(string $file, string $message = '') + protected function assertFileIsNotWritable(string $file, string $message = ''): void { Assert::assertFileIsNotWritable($file, $message); } @@ -317,7 +303,7 @@ protected function assertFileIsNotWritable(string $file, string $message = '') /** * Asserts that a file exists and is readable. */ - protected function assertFileIsReadable(string $file, string $message = '') + protected function assertFileIsReadable(string $file, string $message = ''): void { Assert::assertFileIsReadable($file, $message); } @@ -325,7 +311,7 @@ protected function assertFileIsReadable(string $file, string $message = '') /** * Asserts that a file exists and is writable. */ - protected function assertFileIsWritable(string $file, string $message = '') + protected function assertFileIsWritable(string $file, string $message = ''): void { Assert::assertFileIsWritable($file, $message); } @@ -333,7 +319,7 @@ protected function assertFileIsWritable(string $file, string $message = '') /** * Asserts that the contents of one file is not equal to the contents of another file. */ - protected function assertFileNotEquals(string $expected, string $actual, string $message = '') + protected function assertFileNotEquals(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEquals($expected, $actual, $message); } @@ -341,7 +327,7 @@ protected function assertFileNotEquals(string $expected, string $actual, string /** * Asserts that the contents of one file is not equal to the contents of another file (canonicalizing). */ - protected function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = '') + protected function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEqualsCanonicalizing($expected, $actual, $message); } @@ -349,7 +335,7 @@ protected function assertFileNotEqualsCanonicalizing(string $expected, string $a /** * Asserts that the contents of one file is not equal to the contents of another file (ignoring case). */ - protected function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = '') + protected function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEqualsIgnoringCase($expected, $actual, $message); } @@ -359,7 +345,7 @@ protected function assertFileNotEqualsIgnoringCase(string $expected, string $act * * @param mixed $actual */ - protected function assertFinite($actual, string $message = '') + protected function assertFinite($actual, string $message = ''): void { Assert::assertFinite($actual, $message); } @@ -370,7 +356,7 @@ protected function assertFinite($actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertGreaterThan($expected, $actual, string $message = '') + protected function assertGreaterThan($expected, $actual, string $message = ''): void { Assert::assertGreaterThan($expected, $actual, $message); } @@ -381,7 +367,7 @@ protected function assertGreaterThan($expected, $actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertGreaterThanOrEqual($expected, $actual, string $message = '') + protected function assertGreaterThanOrEqual($expected, $actual, string $message = ''): void { Assert::assertGreaterThanOrEqual($expected, $actual, $message); } @@ -391,7 +377,7 @@ protected function assertGreaterThanOrEqual($expected, $actual, string $message * * @param mixed $actual */ - protected function assertInfinite($actual, string $message = '') + protected function assertInfinite($actual, string $message = ''): void { Assert::assertInfinite($actual, $message); } @@ -406,7 +392,7 @@ protected function assertInfinite($actual, string $message = '') * * @phpstan-assert =ExpectedType $actual */ - protected function assertInstanceOf(string $expected, $actual, string $message = '') + protected function assertInstanceOf(string $expected, $actual, string $message = ''): void { Assert::assertInstanceOf($expected, $actual, $message); } @@ -418,9 +404,9 @@ protected function assertInstanceOf(string $expected, $actual, string $message = * * @phpstan-assert array $actual */ - protected function assertIsArray($actual, string $message = '') + protected function assertIsArray($actual, string $message = ''): void { - TestCase::assertIsArray($actual, $message); + Assert::assertIsArray($actual, $message); } /** @@ -430,9 +416,9 @@ protected function assertIsArray($actual, string $message = '') * * @phpstan-assert bool $actual */ - protected function assertIsBool($actual, string $message = '') + protected function assertIsBool($actual, string $message = ''): void { - TestCase::assertIsBool($actual, $message); + Assert::assertIsBool($actual, $message); } /** @@ -442,9 +428,9 @@ protected function assertIsBool($actual, string $message = '') * * @phpstan-assert callable $actual */ - protected function assertIsCallable($actual, string $message = '') + protected function assertIsCallable($actual, string $message = ''): void { - TestCase::assertIsCallable($actual, $message); + Assert::assertIsCallable($actual, $message); } /** @@ -454,9 +440,9 @@ protected function assertIsCallable($actual, string $message = '') * * @phpstan-assert resource $actual */ - protected function assertIsClosedResource($actual, string $message = '') + protected function assertIsClosedResource($actual, string $message = ''): void { - TestCase::assertIsClosedResource($actual, $message); + Assert::assertIsClosedResource($actual, $message); } /** @@ -466,9 +452,9 @@ protected function assertIsClosedResource($actual, string $message = '') * * @phpstan-assert float $actual */ - protected function assertIsFloat($actual, string $message = '') + protected function assertIsFloat($actual, string $message = ''): void { - TestCase::assertIsFloat($actual, $message); + Assert::assertIsFloat($actual, $message); } /** @@ -478,9 +464,9 @@ protected function assertIsFloat($actual, string $message = '') * * @phpstan-assert int $actual */ - protected function assertIsInt($actual, string $message = '') + protected function assertIsInt($actual, string $message = ''): void { - TestCase::assertIsInt($actual, $message); + Assert::assertIsInt($actual, $message); } /** @@ -490,9 +476,9 @@ protected function assertIsInt($actual, string $message = '') * * @phpstan-assert iterable $actual */ - protected function assertIsIterable($actual, string $message = '') + protected function assertIsIterable($actual, string $message = ''): void { - TestCase::assertIsIterable($actual, $message); + Assert::assertIsIterable($actual, $message); } /** @@ -502,9 +488,9 @@ protected function assertIsIterable($actual, string $message = '') * * @phpstan-assert !array $actual */ - protected function assertIsNotArray($actual, string $message = '') + protected function assertIsNotArray($actual, string $message = ''): void { - TestCase::assertIsNotArray($actual, $message); + Assert::assertIsNotArray($actual, $message); } /** @@ -514,9 +500,9 @@ protected function assertIsNotArray($actual, string $message = '') * * @phpstan-assert !bool $actual */ - protected function assertIsNotBool($actual, string $message = '') + protected function assertIsNotBool($actual, string $message = ''): void { - TestCase::assertIsNotBool($actual, $message); + Assert::assertIsNotBool($actual, $message); } /** @@ -526,9 +512,9 @@ protected function assertIsNotBool($actual, string $message = '') * * @phpstan-assert !callable $actual */ - protected function assertIsNotCallable($actual, string $message = '') + protected function assertIsNotCallable($actual, string $message = ''): void { - TestCase::assertIsNotCallable($actual, $message); + Assert::assertIsNotCallable($actual, $message); } /** @@ -538,9 +524,9 @@ protected function assertIsNotCallable($actual, string $message = '') * * @phpstan-assert !resource $actual */ - protected function assertIsNotClosedResource($actual, string $message = '') + protected function assertIsNotClosedResource($actual, string $message = ''): void { - TestCase::assertIsNotClosedResource($actual, $message); + Assert::assertIsNotClosedResource($actual, $message); } /** @@ -550,9 +536,9 @@ protected function assertIsNotClosedResource($actual, string $message = '') * * @phpstan-assert !float $actual */ - protected function assertIsNotFloat($actual, string $message = '') + protected function assertIsNotFloat($actual, string $message = ''): void { - TestCase::assertIsNotFloat($actual, $message); + Assert::assertIsNotFloat($actual, $message); } /** @@ -562,9 +548,9 @@ protected function assertIsNotFloat($actual, string $message = '') * * @phpstan-assert !int $actual */ - protected function assertIsNotInt($actual, string $message = '') + protected function assertIsNotInt($actual, string $message = ''): void { - TestCase::assertIsNotInt($actual, $message); + Assert::assertIsNotInt($actual, $message); } /** @@ -574,9 +560,9 @@ protected function assertIsNotInt($actual, string $message = '') * * @phpstan-assert !iterable $actual */ - protected function assertIsNotIterable($actual, string $message = '') + protected function assertIsNotIterable($actual, string $message = ''): void { - TestCase::assertIsNotIterable($actual, $message); + Assert::assertIsNotIterable($actual, $message); } /** @@ -586,9 +572,9 @@ protected function assertIsNotIterable($actual, string $message = '') * * @phpstan-assert !numeric $actual */ - protected function assertIsNotNumeric($actual, string $message = '') + protected function assertIsNotNumeric($actual, string $message = ''): void { - TestCase::assertIsNotNumeric($actual, $message); + Assert::assertIsNotNumeric($actual, $message); } /** @@ -598,17 +584,17 @@ protected function assertIsNotNumeric($actual, string $message = '') * * @phpstan-assert !object $actual */ - protected function assertIsNotObject($actual, string $message = '') + protected function assertIsNotObject($actual, string $message = ''): void { - TestCase::assertIsNotObject($actual, $message); + Assert::assertIsNotObject($actual, $message); } /** * Asserts that a file/dir exists and is not readable. */ - protected function assertIsNotReadable(string $filename, string $message = '') + protected function assertIsNotReadable(string $filename, string $message = ''): void { - TestCase::assertIsNotReadable($filename, $message); + Assert::assertIsNotReadable($filename, $message); } /** @@ -618,9 +604,9 @@ protected function assertIsNotReadable(string $filename, string $message = '') * * @phpstan-assert !resource $actual */ - protected function assertIsNotResource($actual, string $message = '') + protected function assertIsNotResource($actual, string $message = ''): void { - TestCase::assertIsNotResource($actual, $message); + Assert::assertIsNotResource($actual, $message); } /** @@ -630,9 +616,9 @@ protected function assertIsNotResource($actual, string $message = '') * * @psalm-assert !scalar $actual */ - protected function assertIsNotScalar($actual, string $message = '') + protected function assertIsNotScalar($actual, string $message = ''): void { - TestCase::assertIsNotScalar($actual, $message); + Assert::assertIsNotScalar($actual, $message); } /** @@ -642,17 +628,17 @@ protected function assertIsNotScalar($actual, string $message = '') * * @phpstan-assert !string $actual */ - protected function assertIsNotString($actual, string $message = '') + protected function assertIsNotString($actual, string $message = ''): void { - TestCase::assertIsNotString($actual, $message); + Assert::assertIsNotString($actual, $message); } /** * Asserts that a file/dir exists and is not writable. */ - protected function assertIsNotWritable(string $filename, string $message = '') + protected function assertIsNotWritable(string $filename, string $message = ''): void { - TestCase::assertIsNotWritable($filename, $message); + Assert::assertIsNotWritable($filename, $message); } /** @@ -662,9 +648,9 @@ protected function assertIsNotWritable(string $filename, string $message = '') * * @phpstan-assert numeric $actual */ - protected function assertIsNumeric($actual, string $message = '') + protected function assertIsNumeric($actual, string $message = ''): void { - TestCase::assertIsNumeric($actual, $message); + Assert::assertIsNumeric($actual, $message); } /** @@ -674,17 +660,17 @@ protected function assertIsNumeric($actual, string $message = '') * * @phpstan-assert object $actual */ - protected function assertIsObject($actual, string $message = '') + protected function assertIsObject($actual, string $message = ''): void { - TestCase::assertIsObject($actual, $message); + Assert::assertIsObject($actual, $message); } /** * Asserts that a file/dir is readable. */ - protected function assertIsReadable(string $filename, string $message = '') + protected function assertIsReadable(string $filename, string $message = ''): void { - TestCase::assertIsReadable($filename, $message); + Assert::assertIsReadable($filename, $message); } /** @@ -694,9 +680,9 @@ protected function assertIsReadable(string $filename, string $message = '') * * @phpstan-assert resource $actual */ - protected function assertIsResource($actual, string $message = '') + protected function assertIsResource($actual, string $message = ''): void { - TestCase::assertIsResource($actual, $message); + Assert::assertIsResource($actual, $message); } /** @@ -706,9 +692,9 @@ protected function assertIsResource($actual, string $message = '') * * @phpstan-assert scalar $actual */ - protected function assertIsScalar($actual, string $message = '') + protected function assertIsScalar($actual, string $message = ''): void { - TestCase::assertIsScalar($actual, $message); + Assert::assertIsScalar($actual, $message); } /** @@ -718,23 +704,23 @@ protected function assertIsScalar($actual, string $message = '') * * @phpstan-assert string $actual */ - protected function assertIsString($actual, string $message = '') + protected function assertIsString($actual, string $message = ''): void { - TestCase::assertIsString($actual, $message); + Assert::assertIsString($actual, $message); } /** * Asserts that a file/dir exists and is writable. */ - protected function assertIsWritable(string $filename, string $message = '') + protected function assertIsWritable(string $filename, string $message = ''): void { - TestCase::assertIsWritable($filename, $message); + Assert::assertIsWritable($filename, $message); } /** * Asserts that a string is a valid JSON string. */ - protected function assertJson(string $actualJson, string $message = '') + protected function assertJson(string $actualJson, string $message = ''): void { Assert::assertJson($actualJson, $message); } @@ -742,7 +728,7 @@ protected function assertJson(string $actualJson, string $message = '') /** * Asserts that two JSON files are equal. */ - protected function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = '') + protected function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertJsonFileEqualsJsonFile($expectedFile, $actualFile, $message); } @@ -750,7 +736,7 @@ protected function assertJsonFileEqualsJsonFile(string $expectedFile, string $ac /** * Asserts that two JSON files are not equal. */ - protected function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = '') + protected function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertJsonFileNotEqualsJsonFile($expectedFile, $actualFile, $message); } @@ -758,7 +744,7 @@ protected function assertJsonFileNotEqualsJsonFile(string $expectedFile, string /** * Asserts that the generated JSON encoded object and the content of the given file are equal. */ - protected function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = '') + protected function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { Assert::assertJsonStringEqualsJsonFile($expectedFile, $actualJson, $message); } @@ -766,7 +752,7 @@ protected function assertJsonStringEqualsJsonFile(string $expectedFile, string $ /** * Asserts that two given JSON encoded objects or arrays are equal. */ - protected function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = '') + protected function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { Assert::assertJsonStringEqualsJsonString($expectedJson, $actualJson, $message); } @@ -774,7 +760,7 @@ protected function assertJsonStringEqualsJsonString(string $expectedJson, string /** * Asserts that the generated JSON encoded object and the content of the given file are not equal. */ - protected function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = '') + protected function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { Assert::assertJsonStringNotEqualsJsonFile($expectedFile, $actualJson, $message); } @@ -782,7 +768,7 @@ protected function assertJsonStringNotEqualsJsonFile(string $expectedFile, strin /** * Asserts that two given JSON encoded objects or arrays are not equal. */ - protected function assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = '') + protected function assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { Assert::assertJsonStringNotEqualsJsonString($expectedJson, $actualJson, $message); } @@ -793,7 +779,7 @@ protected function assertJsonStringNotEqualsJsonString(string $expectedJson, str * @param mixed $expected * @param mixed $actual */ - protected function assertLessThan($expected, $actual, string $message = '') + protected function assertLessThan($expected, $actual, string $message = ''): void { Assert::assertLessThan($expected, $actual, $message); } @@ -804,7 +790,7 @@ protected function assertLessThan($expected, $actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertLessThanOrEqual($expected, $actual, string $message = '') + protected function assertLessThanOrEqual($expected, $actual, string $message = ''): void { Assert::assertLessThanOrEqual($expected, $actual, $message); } @@ -812,9 +798,9 @@ protected function assertLessThanOrEqual($expected, $actual, string $message = ' /** * Asserts that a string matches a given regular expression. */ - protected function assertMatchesRegularExpression(string $pattern, string $string, string $message = '') + protected function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void { - TestCase::assertMatchesRegularExpression($pattern, $string, $message); + Assert::assertMatchesRegularExpression($pattern, $string, $message); } /** @@ -822,7 +808,7 @@ protected function assertMatchesRegularExpression(string $pattern, string $strin * * @param mixed $actual */ - protected function assertNan($actual, string $message = '') + protected function assertNan($actual, string $message = ''): void { Assert::assertNan($actual, $message); } @@ -830,22 +816,19 @@ protected function assertNan($actual, string $message = '') /** * Asserts that a haystack does not contain a needle. * - * @param mixed $needle + * @param iterable $haystack */ - protected function assertNotContains($needle, iterable $haystack, string $message = '') + protected function assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertNotContains($needle, $haystack, $message); } - protected function assertNotContainsEquals($needle, iterable $haystack, string $message = '') - { - Assert::assertNotContainsEquals($needle, $haystack, $message); - } - /** * Asserts that a haystack does not contain only values of a given type. + * @param 'array'|'bool'|'boolean'|'callable'|'double'|'float'|'int'|'integer'|'iterable'|'null'|'numeric'|'object'|'real'|'resource'|'resource (closed)'|'scalar'|'string' $type + * @param iterable $haystack */ - protected function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = '') + protected function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { Assert::assertNotContainsOnly($type, $haystack, $isNativeType, $message); } @@ -853,9 +836,9 @@ protected function assertNotContainsOnly(string $type, iterable $haystack, ?bool /** * Asserts the number of elements of an array, Countable or Traversable. * - * @param \Countable|iterable $haystack + * @param \Countable|iterable $haystack */ - protected function assertNotCount(int $expectedCount, $haystack, string $message = '') + protected function assertNotCount(int $expectedCount, \Countable|iterable $haystack, string $message = ''): void { Assert::assertNotCount($expectedCount, $haystack, $message); } @@ -867,7 +850,7 @@ protected function assertNotCount(int $expectedCount, $haystack, string $message * * @phpstan-assert !empty $actual */ - protected function assertNotEmpty($actual, string $message = '') + protected function assertNotEmpty($actual, string $message = ''): void { Assert::assertNotEmpty($actual, $message); } @@ -878,9 +861,9 @@ protected function assertNotEmpty($actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertNotEquals($expected, $actual, string $message = '') + protected function assertNotEquals($expected, $actual, string $message = ''): void { - TestCase::assertNotEquals($expected, $actual, $message); + Assert::assertNotEquals($expected, $actual, $message); } /** @@ -889,9 +872,9 @@ protected function assertNotEquals($expected, $actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertNotEqualsCanonicalizing($expected, $actual, string $message = '') + protected function assertNotEqualsCanonicalizing($expected, $actual, string $message = ''): void { - TestCase::assertNotEqualsCanonicalizing($expected, $actual, $message); + Assert::assertNotEqualsCanonicalizing($expected, $actual, $message); } /** @@ -900,9 +883,9 @@ protected function assertNotEqualsCanonicalizing($expected, $actual, string $mes * @param mixed $expected * @param mixed $actual */ - protected function assertNotEqualsIgnoringCase($expected, $actual, string $message = '') + protected function assertNotEqualsIgnoringCase($expected, $actual, string $message = ''): void { - TestCase::assertNotEqualsIgnoringCase($expected, $actual, $message); + Assert::assertNotEqualsIgnoringCase($expected, $actual, $message); } /** @@ -911,9 +894,9 @@ protected function assertNotEqualsIgnoringCase($expected, $actual, string $messa * @param mixed $expected * @param mixed $actual */ - protected function assertNotEqualsWithDelta($expected, $actual, float $delta, string $message = '') + protected function assertNotEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void { - TestCase::assertNotEqualsWithDelta($expected, $actual, $delta, $message); + Assert::assertNotEqualsWithDelta($expected, $actual, $delta, $message); } /** @@ -923,7 +906,7 @@ protected function assertNotEqualsWithDelta($expected, $actual, float $delta, st * * @phpstan-assert !false $condition */ - protected function assertNotFalse($condition, string $message = '') + protected function assertNotFalse($condition, string $message = ''): void { Assert::assertNotFalse($condition, $message); } @@ -938,7 +921,7 @@ protected function assertNotFalse($condition, string $message = '') * * @phpstan-assert !ExpectedType $actual */ - protected function assertNotInstanceOf(string $expected, $actual, string $message = '') + protected function assertNotInstanceOf(string $expected, $actual, string $message = ''): void { Assert::assertNotInstanceOf($expected, $actual, $message); } @@ -950,7 +933,7 @@ protected function assertNotInstanceOf(string $expected, $actual, string $messag * * @phpstan-assert !null $actual */ - protected function assertNotNull($actual, string $message = '') + protected function assertNotNull($actual, string $message = ''): void { Assert::assertNotNull($actual, $message); } @@ -961,7 +944,7 @@ protected function assertNotNull($actual, string $message = '') * @param mixed $expected * @param mixed $actual */ - protected function assertNotSame($expected, $actual, string $message = '') + protected function assertNotSame($expected, $actual, string $message = ''): void { Assert::assertNotSame($expected, $actual, $message); } @@ -969,10 +952,10 @@ protected function assertNotSame($expected, $actual, string $message = '') /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) is not the same. * - * @param \Countable|iterable $expected - * @param \Countable|iterable $actual + * @param \Countable|iterable $expected + * @param \Countable|iterable $actual */ - protected function assertNotSameSize($expected, $actual, string $message = '') + protected function assertNotSameSize(\Countable|iterable $expected, \Countable|iterable $actual, string $message = ''): void { Assert::assertNotSameSize($expected, $actual, $message); } @@ -984,7 +967,7 @@ protected function assertNotSameSize($expected, $actual, string $message = '') * * @phpstan-assert !true $condition */ - protected function assertNotTrue($condition, string $message = '') + protected function assertNotTrue($condition, string $message = ''): void { Assert::assertNotTrue($condition, $message); } @@ -996,7 +979,7 @@ protected function assertNotTrue($condition, string $message = '') * * @phpstan-assert null $actual */ - protected function assertNull($actual, string $message = '') + protected function assertNull($actual, string $message = ''): void { Assert::assertNull($actual, $message); } @@ -1004,7 +987,7 @@ protected function assertNull($actual, string $message = '') /** * Asserts that an object has a specified attribute. */ - protected function assertObjectHasAttribute(string $attributeName, object $object, string $message = '') + protected function assertObjectHasAttribute(string $attributeName, object $object, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); @@ -1018,7 +1001,7 @@ protected function assertObjectHasAttribute(string $attributeName, object $objec /** * Asserts that an object does not have a specified attribute. */ - protected function assertObjectNotHasAttribute(string $attributeName, object $object, string $message = '') + protected function assertObjectNotHasAttribute(string $attributeName, object $object, string $message = ''): void { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 10', E_USER_DEPRECATED); @@ -1037,56 +1020,56 @@ protected function assertObjectNotHasAttribute(string $attributeName, object $ob * @template ExpectedType * * @param ExpectedType $expected - * @param mixed $actual * * @phpstan-assert =ExpectedType $actual */ - protected function assertSame($expected, $actual, string $message = '') + protected function assertSame(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertSame($expected, $actual, $message); } /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) is the same. - * - * @param \Countable|iterable $expected - * @param \Countable|iterable $actual + * @param \Countable|iterable $expected + * @param \Countable|iterable $actual */ - protected function assertSameSize($expected, $actual, string $message = '') + protected function assertSameSize(\Countable|iterable $expected, \Countable|iterable $actual, string $message = ''): void { Assert::assertSameSize($expected, $actual, $message); } - protected function assertStringContainsString(string $needle, string $haystack, string $message = '') + protected function assertStringContainsString(string $needle, string $haystack, string $message = ''): void { - TestCase::assertStringContainsString($needle, $haystack, $message); + Assert::assertStringContainsString($needle, $haystack, $message); } - protected function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = '') + protected function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { - TestCase::assertStringContainsStringIgnoringCase($needle, $haystack, $message); + Assert::assertStringContainsStringIgnoringCase($needle, $haystack, $message); } /** * Asserts that a string ends not with a given suffix. + * @param non-empty-string $suffix */ - protected function assertStringEndsNotWith(string $suffix, string $string, string $message = '') + protected function assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void { - TestCase::assertStringEndsNotWith($suffix, $string, $message); + Assert::assertStringEndsNotWith($suffix, $string, $message); } /** * Asserts that a string ends with a given suffix. + * @param non-empty-string $suffix */ - protected function assertStringEndsWith(string $suffix, string $string, string $message = '') + protected function assertStringEndsWith(string $suffix, string $string, string $message = ''): void { - TestCase::assertStringEndsWith($suffix, $string, $message); + Assert::assertStringEndsWith($suffix, $string, $message); } /** * Asserts that the contents of a string is equal to the contents of a file. */ - protected function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = '') + protected function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFile($expectedFile, $actualString, $message); } @@ -1094,7 +1077,7 @@ protected function assertStringEqualsFile(string $expectedFile, string $actualSt /** * Asserts that the contents of a string is equal to the contents of a file (canonicalizing). */ - protected function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = '') + protected function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFileCanonicalizing($expectedFile, $actualString, $message); } @@ -1102,7 +1085,7 @@ protected function assertStringEqualsFileCanonicalizing(string $expectedFile, st /** * Asserts that the contents of a string is equal to the contents of a file (ignoring case). */ - protected function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = '') + protected function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFileIgnoringCase($expectedFile, $actualString, $message); } @@ -1110,7 +1093,7 @@ protected function assertStringEqualsFileIgnoringCase(string $expectedFile, stri /** * Asserts that a string matches a given format string. */ - protected function assertStringMatchesFormat(string $format, string $string, string $message = '') + protected function assertStringMatchesFormat(string $format, string $string, string $message = ''): void { Assert::assertStringMatchesFormat($format, $string, $message); } @@ -1118,25 +1101,25 @@ protected function assertStringMatchesFormat(string $format, string $string, str /** * Asserts that a string matches a given format file. */ - protected function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = '') + protected function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void { Assert::assertStringMatchesFormatFile($formatFile, $string, $message); } - protected function assertStringNotContainsString(string $needle, string $haystack, string $message = '') + protected function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void { - TestCase::assertStringNotContainsString($needle, $haystack, $message); + Assert::assertStringNotContainsString($needle, $haystack, $message); } - protected function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = '') + protected function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { - TestCase::assertStringNotContainsStringIgnoringCase($needle, $haystack, $message); + Assert::assertStringNotContainsStringIgnoringCase($needle, $haystack, $message); } /** * Asserts that the contents of a string is not equal to the contents of a file. */ - protected function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = '') + protected function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFile($expectedFile, $actualString, $message); } @@ -1144,7 +1127,7 @@ protected function assertStringNotEqualsFile(string $expectedFile, string $actua /** * Asserts that the contents of a string is not equal to the contents of a file (canonicalizing). */ - protected function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = '') + protected function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFileCanonicalizing($expectedFile, $actualString, $message); } @@ -1152,7 +1135,7 @@ protected function assertStringNotEqualsFileCanonicalizing(string $expectedFile, /** * Asserts that the contents of a string is not equal to the contents of a file (ignoring case). */ - protected function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = '') + protected function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFileIgnoringCase($expectedFile, $actualString, $message); } @@ -1163,14 +1146,8 @@ protected function assertStringNotEqualsFileIgnoringCase(string $expectedFile, s protected function assertStringNotMatchesFormat(string $format, string $string, string $message = '') { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 12', E_USER_DEPRECATED); - - if (method_exists(Assert::class, 'assertStringNotMatchesFormat')) { - Assert::assertStringNotMatchesFormat($format, $string, $message); - } else { - $constraint = new LogicalNot(new StringMatchesFormatDescription($format)); - - Assert::assertThat($string, $constraint, $message); - } + $constraint = new LogicalNot(new StringMatchesFormatDescription($format)); + Assert::assertThat($string, $constraint, $message); } /** @@ -1179,34 +1156,29 @@ protected function assertStringNotMatchesFormat(string $format, string $string, protected function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = '') { trigger_error(__FUNCTION__ . ' was removed from PHPUnit since PHPUnit 12', E_USER_DEPRECATED); - - if (method_exists(Assert::class, 'assertStringNotMatchesFormatFile')) { - Assert::assertStringNotMatchesFormatFile($formatFile, $string, $message); - } else { - Assert::assertFileExists($formatFile); - - $constraint = new LogicalNot( - new StringMatchesFormatDescription( - file_get_contents($formatFile) - ) - ); - - Assert::assertThat($string, $constraint, $message); - } + Assert::assertFileExists($formatFile); + $constraint = new LogicalNot( + new StringMatchesFormatDescription( + file_get_contents($formatFile) + ) + ); + Assert::assertThat($string, $constraint, $message); } /** * Asserts that a string starts not with a given prefix. + * @param non-empty-string $prefix */ - protected function assertStringStartsNotWith(string $prefix, string $string, string $message = '') + protected function assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void { Assert::assertStringStartsNotWith($prefix, $string, $message); } /** * Asserts that a string starts with a given prefix. + * @param non-empty-string $prefix */ - protected function assertStringStartsWith(string $prefix, string $string, string $message = '') + protected function assertStringStartsWith(string $prefix, string $string, string $message = ''): void { Assert::assertStringStartsWith($prefix, $string, $message); } @@ -1216,7 +1188,7 @@ protected function assertStringStartsWith(string $prefix, string $string, string * * @param mixed $value */ - protected function assertThat($value, PHPUnitConstraint $constraint, string $message = '') + protected function assertThat($value, PHPUnitConstraint $constraint, string $message = ''): void { Assert::assertThat($value, $constraint, $message); } @@ -1228,7 +1200,7 @@ protected function assertThat($value, PHPUnitConstraint $constraint, string $mes * * @phpstan-assert true $condition */ - protected function assertTrue($condition, string $message = '') + protected function assertTrue($condition, string $message = ''): void { Assert::assertTrue($condition, $message); } @@ -1236,7 +1208,7 @@ protected function assertTrue($condition, string $message = '') /** * Asserts that two XML files are equal. */ - protected function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = '') + protected function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertXmlFileEqualsXmlFile($expectedFile, $actualFile, $message); } @@ -1244,29 +1216,42 @@ protected function assertXmlFileEqualsXmlFile(string $expectedFile, string $actu /** * Asserts that two XML files are not equal. */ - protected function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = '') + protected function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertXmlFileNotEqualsXmlFile($expectedFile, $actualFile, $message); } /** * Asserts that two XML documents are equal. - * - * @param \DOMDocument|string $actualXml */ - protected function assertXmlStringEqualsXmlFile(string $expectedFile, $actualXml, string $message = '') + protected function assertXmlStringEqualsXmlFile(string $expectedFile, \DOMDocument|string $actualXml, string $message = ''): void { + if ($actualXml instanceof \DOMDocument) { + $actualXml = $actualXml->saveXML(); + if ($actualXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } Assert::assertXmlStringEqualsXmlFile($expectedFile, $actualXml, $message); } /** * Asserts that two XML documents are equal. - * - * @param \DOMDocument|string $expectedXml - * @param \DOMDocument|string $actualXml */ - protected function assertXmlStringEqualsXmlString($expectedXml, $actualXml, string $message = '') + protected function assertXmlStringEqualsXmlString(\DOMDocument|string $expectedXml, \DOMDocument|string $actualXml, string $message = ''): void { + if ($actualXml instanceof \DOMDocument) { + $actualXml = $actualXml->saveXML(); + if ($actualXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } + if ($expectedXml instanceof \DOMDocument) { + $expectedXml = $expectedXml->saveXML(); + if ($expectedXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } Assert::assertXmlStringEqualsXmlString($expectedXml, $actualXml, $message); } @@ -1275,8 +1260,14 @@ protected function assertXmlStringEqualsXmlString($expectedXml, $actualXml, stri * * @param \DOMDocument|string $actualXml */ - protected function assertXmlStringNotEqualsXmlFile(string $expectedFile, $actualXml, string $message = '') + protected function assertXmlStringNotEqualsXmlFile(string $expectedFile, $actualXml, string $message = ''): void { + if ($actualXml instanceof \DOMDocument) { + $actualXml = $actualXml->saveXML(); + if ($actualXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } Assert::assertXmlStringNotEqualsXmlFile($expectedFile, $actualXml, $message); } @@ -1286,15 +1277,27 @@ protected function assertXmlStringNotEqualsXmlFile(string $expectedFile, $actual * @param \DOMDocument|string $expectedXml * @param \DOMDocument|string $actualXml */ - protected function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, string $message = '') + protected function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, string $message = ''): void { + if ($actualXml instanceof \DOMDocument) { + $actualXml = $actualXml->saveXML(); + if ($actualXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } + if ($expectedXml instanceof \DOMDocument) { + $expectedXml = $expectedXml->saveXML(); + if ($expectedXml === false) { + throw new \RuntimeException('Failed to transform XML document to string'); + } + } Assert::assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message); } /** * Fails a test with the given message. */ - protected function fail(string $message = '') + protected function fail(string $message = ''): never { Assert::fail($message); } @@ -1302,7 +1305,7 @@ protected function fail(string $message = '') /** * Mark the test as incomplete. */ - protected function markTestIncomplete(string $message = '') + protected function markTestIncomplete(string $message = ''): never { Assert::markTestIncomplete($message); } @@ -1310,7 +1313,7 @@ protected function markTestIncomplete(string $message = '') /** * Mark the test as skipped. */ - protected function markTestSkipped(string $message = '') + protected function markTestSkipped(string $message = ''): never { Assert::markTestSkipped($message); } diff --git a/tests/PhpStanAssertContainer.php b/tests/PhpStanAssertContainer.php new file mode 100644 index 0000000..bd18554 --- /dev/null +++ b/tests/PhpStanAssertContainer.php @@ -0,0 +1,11 @@ +