Browse Source

Basic tests for exception checking

rpm
J. King 3 years ago
parent
commit
3c8ee42666
  1. 2
      lib/REST.php
  2. 18
      tests/cases/TestArsse.php

2
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

18
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])],
];
}
}

Loading…
Cancel
Save