From 54be5997d153d2cedc453840bf340c017b9f99c4 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 25 Mar 2019 15:03:41 -0400 Subject: [PATCH] CLI tests for password changing and clearing --- tests/cases/CLI/TestCLI.php | 49 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/cases/CLI/TestCLI.php b/tests/cases/CLI/TestCLI.php index f7f2a7c..9a2d622 100644 --- a/tests/cases/CLI/TestCLI.php +++ b/tests/cases/CLI/TestCLI.php @@ -221,28 +221,59 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserPasswordChanges */ public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output) { - // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead - Arsse::$user = $this->createMock(User::class); - Arsse::$user->method("passwordSet")->will($this->returnCallback(function($user, $pass = null) { + $passwordChange = function($user, $pass = null) { switch ($user) { case "jane.doe@example.com": throw new \JKingWeb\Arsse\User\Exception("doesNotExist"); case "john.doe@example.com": return is_null($pass) ? "random password" : $pass; } - })); + }; + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + Arsse::$user = $this->createMock(User::class); + Arsse::$user->method("passwordSet")->will($this->returnCallback($passwordChange)); + $fever = \Phake::mock(FeverUser::class); + \Phake::when($fever)->register->thenReturnCallback($passwordChange); + \Phake::when($this->cli)->getFever->thenReturn($fever); $this->assertConsole($this->cli, $cmd, $exitStatus, $output); } public function provideUserPasswordChanges() { return [ - ["arsse.php user set-pass john.doe@example.com", 0, "random password"], - ["arsse.php user set-pass john.doe@example.com superman", 0, ""], - ["arsse.php user set-pass jane.doe@example.com", 10402, ""], + ["arsse.php user set-pass john.doe@example.com", 0, "random password"], + ["arsse.php user set-pass john.doe@example.com superman", 0, ""], + ["arsse.php user set-pass jane.doe@example.com", 10402, ""], + ["arsse.php user set-pass john.doe@example.com --fever", 0, "random password"], + ["arsse.php user set-pass --fever john.doe@example.com superman", 0, ""], + ["arsse.php user set-pass jane.doe@example.com --fever", 10402, ""], ]; } - public function testChangeAFeverPassword() { - $this->markTestIncomplete(); + /** @dataProvider provideUserPasswordClearings */ + public function testClearAUserPassword(string $cmd, int $exitStatus, string $output) { + $passwordClear = function($user) { + switch ($user) { + case "jane.doe@example.com": + throw new \JKingWeb\Arsse\User\Exception("doesNotExist"); + case "john.doe@example.com": + return true; + } + }; + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + Arsse::$user = $this->createMock(User::class); + Arsse::$user->method("passwordUnet")->will($this->returnCallback($passwordChange)); + $fever = \Phake::mock(FeverUser::class); + \Phake::when($fever)->unregister->thenReturnCallback($passwordChange); + \Phake::when($this->cli)->getFever->thenReturn($fever); + $this->assertConsole($this->cli, $cmd, $exitStatus, $output); + } + + public function provideUserPasswordClearings() { + return [ + ["arsse.php user unset-pass john.doe@example.com", 0, ""], + ["arsse.php user unset-pass jane.doe@example.com", 10402, ""], + ["arsse.php user unset-pass john.doe@example.com --fever", 0, ""], + ["arsse.php user unset-pass jane.doe@example.com --fever", 10402, ""], + ]; } }