diff --git a/src/Assert.php b/src/Assert.php index 49c3698..1770008 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -6,7 +6,7 @@ use BadMethodCallException; // Requires ext-spl use DateTime; // Requires ext-date -use DateTimeImmutable; // Request ext-date +use DateTimeImmutable; // Requires ext-date use InvalidArgumentException; // Requires ext-spl use Throwable; use Webmozart\Assert\Assert as Webmozart; @@ -219,8 +219,8 @@ * @method static void allContains(iterable $value, string $subString, string $message = '', class-string $exception = '') * @method static void nullOrNotContains(string|null $value, string $subString, string $message = '', class-string $exception = '') * @method static void allNotContains(iterable $value, string $subString, string $message = '', class-string $exception = '') - * @method static void nullOrWhitespaceOnly(string|null $value, string $message = '', class-string $exception = '') - * @method static void allWhitespaceOnly(iterable $value, string $message = '', class-string $exception = '') + * @method static void nullOrNotWhitespaceOnly(string|null $value, string $message = '', class-string $exception = '') + * @method static void allNotWhitespaceOnly(iterable $value, string $message = '', class-string $exception = '') * @method static void nullOrStartsWith(string|null $value, string $prefix, string $message = '', class-string $exception = '') * @method static void allStartsWith(iterable $value, string $prefix, string $message = '', class-string $exception = '') * @method static void nullOrNotStartsWith(string|null $value, string $prefix, string $message = '', class-string $exception = '') @@ -315,7 +315,7 @@ final class Assert /** * @param string $name - * @param array $arguments + * @param array $arguments */ public static function __callStatic(string $name, array $arguments): void { @@ -367,7 +367,7 @@ public static function __callStatic(string $name, array $arguments): void * Handle nullOr* for either Webmozart or for our custom assertions * * @param callable $method - * @param array $arguments + * @param array $arguments * @return void */ private static function nullOr(callable $method, array $arguments): void @@ -381,7 +381,7 @@ private static function nullOr(callable $method, array $arguments): void * all* for our custom assertions * * @param callable $method - * @param array $arguments + * @param array $arguments * @return void */ private static function all(callable $method, array $arguments): void @@ -402,6 +402,10 @@ private static function all(callable $method, array $arguments): void */ protected static function valueToString(mixed $value): string { + if (is_resource($value)) { + return 'resource'; + } + if (null === $value) { return 'null'; } @@ -430,10 +434,6 @@ protected static function valueToString(mixed $value): string return $value::class; } - if (is_resource($value)) { - return 'resource'; - } - if (is_string($value)) { return '"' . $value . '"'; } diff --git a/src/CustomAssertionTrait.php b/src/CustomAssertionTrait.php index d593887..d4a7f8d 100644 --- a/src/CustomAssertionTrait.php +++ b/src/CustomAssertionTrait.php @@ -17,6 +17,37 @@ /** * @package simplesamlphp/assert + * + * @method static void validDuration(mixed $value, string $message = '', class-string $exception = '') + * @method static void stringPlausibleBase64(mixed $value, string $message = '', class-string $exception = '') + * @method static void validDateTime(mixed $value, string $message = '', class-string $exception = '') + * @method static void validDateTimeZulu(mixed $value, string $message = '', class-string $exception = '') + * @method static void notInArray(mixed $value, array $values, string $message = '', class-string $exception = '') + * @method static void validURN(mixed $value, string $message = '', class-string $exception = '') + * @method static void validURI(mixed $value, string $message = '', class-string $exception = '') + * @method static void validURL(mixed $value, string $message = '', class-string $exception = '') + * @method static void validNCName(mixed $value, string $message = '', class-string $exception = '') + * @method static void validQName(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidDuration(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrStringPlausibleBase64(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidDateTime(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidDateTimeZulu(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrNotInArray(mixed $value, array $values, string $message = '', class-string $exception = '') + * @method static void nullOrValidURN(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidURI(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidURL(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidNCName(mixed $value, string $message = '', class-string $exception = '') + * @method static void nullOrValidQName(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidDuration(mixed $value, string $message = '', class-string $exception = '') + * @method static void allStringPlausibleBase64(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidDateTime(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidDateTimeZulu(mixed $value, string $message = '', class-string $exception = '') + * @method static void allNotInArray(mixed $value, array $values, string $message = '', class-string $exception = '') + * @method static void allValidURN(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidURI(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidURL(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidNCName(mixed $value, string $message = '', class-string $exception = '') + * @method static void allValidQName(mixed $value, string $message = '', class-string $exception = '') */ trait CustomAssertionTrait { @@ -144,7 +175,7 @@ private static function validDateTimeZulu(string $value, string $message = ''): /** * @param mixed $value - * @param array $values + * @param array $values * @param string $message */ private static function notInArray($value, array $values, string $message = ''): void diff --git a/tests/Assert/AssertTest.php b/tests/Assert/AssertTest.php index 953d7dd..d78c678 100644 --- a/tests/Assert/AssertTest.php +++ b/tests/Assert/AssertTest.php @@ -14,8 +14,8 @@ use SimpleSAML\Test\Utils\TestClass; use stdClass; -use function getcwd; use function opendir; +use function sys_get_temp_dir; /** * Class \SimpleSAML\Assert\Assert @@ -57,6 +57,7 @@ public function testAssertionFailingWithCustomExceptionThrowsCustomException(): public function testUnknownAssertionRaisesBadMethodCallException(): void { $this->expectException(BadMethodCallException::class); + // @phpstan-ignore-next-line Assert::thisAssertionDoesNotExist('a', 'b', LogicException::class); } @@ -66,6 +67,7 @@ public function testUnknownAssertionRaisesBadMethodCallException(): void public function testUnknownNullOrAssertionRaisesBadMethodCallException(): void { $this->expectException(BadMethodCallException::class); + // @phpstan-ignore-next-line Assert::nullOrThisAssertionDoesNotExist('a', 'b', LogicException::class); } @@ -75,6 +77,7 @@ public function testUnknownNullOrAssertionRaisesBadMethodCallException(): void public function testUnknownAllAssertionRaisesBadMethodCallException(): void { $this->expectException(BadMethodCallException::class); + // @phpstan-ignore-next-line Assert::allThisAssertionDoesNotExist('a', 'b', LogicException::class); } @@ -127,7 +130,7 @@ public function testValueToString(mixed $value, string $expected): void /** - * @return array + * @return array */ public static function provideValue(): array { @@ -137,7 +140,7 @@ public static function provideValue(): array $otherObject = new stdClass(); - $resource = opendir(getcwd()); + $resource = opendir(sys_get_temp_dir()); return [ 'null' => [null, 'null'], diff --git a/tests/Assert/Base64Test.php b/tests/Assert/Base64Test.php index d758f30..f3a42e9 100644 --- a/tests/Assert/Base64Test.php +++ b/tests/Assert/Base64Test.php @@ -35,7 +35,7 @@ public function testStringPlausibleBase64(bool $shouldPass, string $name): void /** - * @return array + * @return array */ public static function provideBase64(): array { diff --git a/tests/Assert/DateTimeTest.php b/tests/Assert/DateTimeTest.php index 7d139bf..fa40a5c 100644 --- a/tests/Assert/DateTimeTest.php +++ b/tests/Assert/DateTimeTest.php @@ -52,7 +52,7 @@ public function testValidDateTimeZulu(bool $shouldPass, string $timestamp): void /** - * @return array + * @return array */ public static function provideDateTime(): array { @@ -68,7 +68,7 @@ public static function provideDateTime(): array /** - * @return array + * @return array */ public static function provideDateTimeZulu(): array { diff --git a/tests/Assert/DurationTest.php b/tests/Assert/DurationTest.php index f8966a5..61a7f25 100644 --- a/tests/Assert/DurationTest.php +++ b/tests/Assert/DurationTest.php @@ -35,7 +35,7 @@ public function testValidDuration(bool $shouldPass, string $duration): void /** - * @return array + * @return array */ public static function provideDuration(): array { diff --git a/tests/Assert/NCNameTest.php b/tests/Assert/NCNameTest.php index c59de75..9e9dc19 100644 --- a/tests/Assert/NCNameTest.php +++ b/tests/Assert/NCNameTest.php @@ -35,7 +35,7 @@ public function testValidNCName(bool $shouldPass, string $name): void /** - * @return array + * @return array */ public static function provideNCName(): array { diff --git a/tests/Assert/NotInArrayTest.php b/tests/Assert/NotInArrayTest.php index 394f578..e90da9d 100644 --- a/tests/Assert/NotInArrayTest.php +++ b/tests/Assert/NotInArrayTest.php @@ -22,7 +22,7 @@ final class NotInArrayTest extends TestCase * @dataProvider provideNotInArray * @param boolean $shouldPass * @param mixed $item - * @param array $arr + * @param array $arr */ public function testnotInArray(bool $shouldPass, $item, array $arr): void { @@ -36,7 +36,7 @@ public function testnotInArray(bool $shouldPass, $item, array $arr): void /** - * @return array + * @return array */ public static function provideNotInArray(): array { diff --git a/tests/Assert/QNameTest.php b/tests/Assert/QNameTest.php index 24ba015..b60d660 100644 --- a/tests/Assert/QNameTest.php +++ b/tests/Assert/QNameTest.php @@ -35,7 +35,7 @@ public function testValidQName(bool $shouldPass, string $name): void /** - * @return array + * @return array */ public static function provideQName(): array { diff --git a/tests/Assert/URITest.php b/tests/Assert/URITest.php index 9f5ba6c..92d5cb2 100644 --- a/tests/Assert/URITest.php +++ b/tests/Assert/URITest.php @@ -69,7 +69,7 @@ public function testValidURN(bool $shouldPass, string $urn): void /** - * @return array + * @return array */ public static function provideURI(): array { @@ -84,7 +84,7 @@ public static function provideURI(): array /** - * @return array + * @return array */ public static function provideURL(): array { @@ -99,7 +99,7 @@ public static function provideURL(): array /** - * @return array + * @return array */ public static function provideURN(): array {