From d4057fc18f6f228282601b94f740f61f837eb671 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 Sep 2022 14:15:23 +0200 Subject: [PATCH 1/5] Backport nullOr bugfix --- src/Assert.php | 20 ++++++++++++-------- tests/Assert/AssertTest.php | 9 +++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index b33a655..464087a 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -347,15 +347,19 @@ public static function __callStatic(string $name, array $arguments): void // Putting Webmozart first, since the most calls will be to their native assertions if (method_exists(Webmozart::class, $name)) { call_user_func_array([Webmozart::class, $name], $arguments); - } else if (method_exists(static::class, $name)) { + } elseif (method_exists(static::class, $name)) { call_user_func_array([static::class, $name], $arguments); - } else if (preg_match('/^nullOr(.*)$/i', $name, $matches)) { + } elseif (preg_match('/^nullOr(.*)$/i', $name, $matches)) { $method = lcfirst($matches[1]); - if (method_exists(static::class, $method)) { - call_user_func_array([static::class, 'nullOr'], [$method, $arguments]); + if (method_exists(Webmozart::class, $method)) { + call_user_func_array([static::class, 'nullOr'], [[Webmozart::class, $method], $arguments]); + } elseif (method_exists(static::class, $method)) { + call_user_func_array([static::class, 'nullOr'], [[static::class, $method], $arguments]); + } else { + throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $method)); } } else { - throw new BadMethodCallException(); + throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $name)); } } catch (InvalidArgumentException $e) { throw new $exception($e->getMessage()); @@ -375,14 +379,14 @@ public static function __callStatic(string $name, array $arguments): void /** * nullOr* for our custom assertions * - * @param string $method + * @param callable $method * @param array $arguments * @return void */ - private static function nullOr(string $method, array $arguments): void + private static function nullOr(callable $method, array $arguments): void { $value = reset($arguments); - ($value === null) || call_user_func_array([static::class, $method], $arguments); + ($value === null) || call_user_func_array($method, $arguments); } diff --git a/tests/Assert/AssertTest.php b/tests/Assert/AssertTest.php index 1f4f61a..3aff1c9 100644 --- a/tests/Assert/AssertTest.php +++ b/tests/Assert/AssertTest.php @@ -61,6 +61,15 @@ public function testUnknownAssertionRaisesBadMethodCallException(): void } + /** + */ + public function testUnknownNullOrAssertionRaisesBadMethodCallException(): void + { + $this->expectException(BadMethodCallException::class); + Assert::nullOrThisAssertionDoesNotExist('a', 'b', LogicException::class); + } + + /** * @doesNotPerformAssertions */ From 85d5a388f8ada517378506623d7c3df996b8c69c Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 Sep 2022 14:35:11 +0200 Subject: [PATCH 2/5] Fix missing use-statement --- src/Assert.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Assert.php b/src/Assert.php index 464087a..4e1807d 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -5,6 +5,7 @@ namespace SimpleSAML\Assert; use BadMethodCallException; +use DateTime; use DateTimeImmutable; use InvalidArgumentException; use Throwable; From d29fc7e69b5fb3d6df7ba80477c1ed23b7b19d86 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 Sep 2022 14:37:11 +0200 Subject: [PATCH 3/5] Fix PHP 7.4 compatibility --- src/Assert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Assert.php b/src/Assert.php index 4e1807d..a1565a7 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -384,7 +384,7 @@ public static function __callStatic(string $name, array $arguments): void * @param array $arguments * @return void */ - private static function nullOr(callable $method, array $arguments): void + private static function nullOr(array $method, array $arguments): void { $value = reset($arguments); ($value === null) || call_user_func_array($method, $arguments); From d1b43494997a8853645f3e3f4f6e0eed5a1ed103 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 6 Sep 2022 20:44:39 +0200 Subject: [PATCH 4/5] Fix invalidQName test --- tests/Assert/AssertTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Assert/AssertTest.php b/tests/Assert/AssertTest.php index 3aff1c9..3afc0bc 100644 --- a/tests/Assert/AssertTest.php +++ b/tests/Assert/AssertTest.php @@ -287,7 +287,7 @@ public function testValidNCName(): void public function testInvalidQName(): void { $this->expectException(AssertionFailedException::class); - Assert::validQName('test'); + Assert::validQName('1test'); } From 3d866a84bf13b770bdea5fb13c2521fbf0622177 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 Sep 2022 14:40:38 +0200 Subject: [PATCH 5/5] Upgrade security checker --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 84f0c6e..d428385 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -112,13 +112,13 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Security check for locked dependencies - uses: symfonycorp/security-checker-action@v2 + uses: symfonycorp/security-checker-action@v3 - name: Update Composer dependencies run: composer update --no-progress --prefer-dist --optimize-autoloader - name: Security check for updated dependencies - uses: symfonycorp/security-checker-action@v2 + uses: symfonycorp/security-checker-action@v3 sanity-check: name: Sanity checks