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 diff --git a/src/Assert.php b/src/Assert.php index b33a655..a1565a7 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; @@ -347,15 +348,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 +380,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(array $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..3afc0bc 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 */ @@ -278,7 +287,7 @@ public function testValidNCName(): void public function testInvalidQName(): void { $this->expectException(AssertionFailedException::class); - Assert::validQName('test'); + Assert::validQName('1test'); }