From 3b28634447e4eb959ebef75c7e11351e6f68e7d0 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 21 Mar 2019 11:00:07 -0400 Subject: [PATCH] Verify even in exceptional cases --- tests/cases/REST/Fever/TestAPI.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/cases/REST/Fever/TestAPI.php b/tests/cases/REST/Fever/TestAPI.php index 8d7867a..89254bf 100644 --- a/tests/cases/REST/Fever/TestAPI.php +++ b/tests/cases/REST/Fever/TestAPI.php @@ -81,7 +81,7 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest { } /** @dataProvider provideAuthenticationRequests */ - public function testAuthenticateAUser(bool $httpRequired, bool $tokenEnforced, string $httpUser = null, array $dataPost, array $dataGet, ResponseInterface $exp) { + public function testAuthenticateAUserToken(bool $httpRequired, bool $tokenEnforced, string $httpUser = null, array $dataPost, array $dataGet, ResponseInterface $exp) { self::setConf([ 'userHTTPAuthRequired' => $httpRequired, 'userSessionEnforced' => $tokenEnforced, @@ -144,14 +144,17 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest { return $id ?? "RANDOM_TOKEN"; }); \Phake::when(Arsse::$db)->tokenCreate("john.doe@example.org", $this->anything(), $this->anything())->thenThrow(new UserException("doesNotExist")); - if ($exp instanceof \JKingWeb\Arsse\AbstractException) { - $this->assertException($exp); - API::userRegister($user, $password); - } else { - $this->assertSame($exp, API::userRegister($user, $password)); + try { + if ($exp instanceof \JKingWeb\Arsse\AbstractException) { + $this->assertException($exp); + API::userRegister($user, $password); + } else { + $this->assertSame($exp, API::userRegister($user, $password)); + } + } finally { + \Phake::verify(Arsse::$db)->tokenRevoke($user, "fever.login"); + \Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD"))); } - \Phake::verify(Arsse::$db)->tokenRevoke($user, "fever.login"); - \Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD"))); } public function providePasswordCreations() {