From 3c8ee42666db7f9ef403b3814bc79b5889b2abbb Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 4 Jul 2021 13:22:08 -0400 Subject: [PATCH] Basic tests for exception checking --- lib/REST.php | 2 +- tests/cases/TestArsse.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/REST.php b/lib/REST.php index d8dce62..f7818e5 100644 --- a/lib/REST.php +++ b/lib/REST.php @@ -86,7 +86,7 @@ class REST { // create a request object if not provided $req = $req ?? ServerRequestFactory::fromGlobals(); // find the API to handle - [$api, $target, $class] = $this->apiMatch($req->getRequestTarget(), $this->apis); + [, $target, $class] = $this->apiMatch($req->getRequestTarget(), $this->apis); // authenticate the request pre-emptively $req = $this->authenticateRequest($req); // modify the request to have an uppercase method and a stripped target diff --git a/tests/cases/TestArsse.php b/tests/cases/TestArsse.php index 2173db8..f7e4e8e 100644 --- a/tests/cases/TestArsse.php +++ b/tests/cases/TestArsse.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase; +use JKingWeb\Arsse\Exception; use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Conf; use JKingWeb\Arsse\Lang; @@ -47,4 +48,21 @@ class TestArsse extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertInstanceOf(Database::class, Arsse::$db); $this->assertInstanceOf(User::class, Arsse::$user); } + + /** @dataProvider provideExtensionChecks */ + public function testCheckForExtensions(array $ext, $exp): void { + if ($exp instanceof \Exception) { + $this->assertException($exp); + Arsse::checkExtensions(...$ext); + } else { + $this->assertNull(Arsse::checkExtensions(...$ext)); + } + } + + public function provideExtensionChecks(): iterable { + return [ + [["pcre"], null], + [["foo", "bar", "baz"], new Exception("extMissing", ['first' => "foo", 'total' => 3])], + ]; + } }