mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Convert user manager tests to Phake
This commit is contained in:
parent
9d92c1661d
commit
72dd21686e
2 changed files with 166 additions and 172 deletions
|
@ -19,15 +19,15 @@ class Arsse {
|
||||||
"iconv", // required by PicoFeed only
|
"iconv", // required by PicoFeed only
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var Factory */
|
/** @var Factory|\Phake\IMock */
|
||||||
public static $obj;
|
public static $obj;
|
||||||
/** @var Lang */
|
/** @var Lang|\Phake\IMock */
|
||||||
public static $lang;
|
public static $lang;
|
||||||
/** @var Conf */
|
/** @var Conf|\Phake\IMock */
|
||||||
public static $conf;
|
public static $conf;
|
||||||
/** @var Database */
|
/** @var Database|\Phake\IMock */
|
||||||
public static $db;
|
public static $db;
|
||||||
/** @var User */
|
/** @var User|\Phake\IMock */
|
||||||
public static $user;
|
public static $user;
|
||||||
|
|
||||||
/** @codeCoverageIgnore */
|
/** @codeCoverageIgnore */
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstruct(): void {
|
public function testConstruct(): void {
|
||||||
$this->assertInstanceOf(User::class, new User($this->drv->get()));
|
$this->assertInstanceOf(User::class, new User($this->drv));
|
||||||
$this->assertInstanceOf(User::class, new User);
|
$this->assertInstanceOf(User::class, new User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,71 +89,71 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function testListUsers(): void {
|
public function testListUsers(): void {
|
||||||
$exp = ["john.doe@example.com", "jane.doe@example.com"];
|
$exp = ["john.doe@example.com", "jane.doe@example.com"];
|
||||||
$this->drv->userList->returns(["john.doe@example.com", "jane.doe@example.com"]);
|
\Phake::when($this->drv)->userList->thenReturn(["john.doe@example.com", "jane.doe@example.com"]);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($exp, $u->list());
|
$this->assertSame($exp, $u->list());
|
||||||
$this->drv->userList->calledWith();
|
\Phake::verify($this->drv)->userList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLookUpAUserByNumber(): void {
|
public function testLookUpAUserByNumber(): void {
|
||||||
$exp = "john.doe@example.com";
|
$exp = "john.doe@example.com";
|
||||||
$this->dbMock->userLookup->returns($exp);
|
\Phake::when(Arsse::$db)->userLookup->thenReturn($exp);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($exp, $u->lookup(2112));
|
$this->assertSame($exp, $u->lookup(2112));
|
||||||
$this->dbMock->userLookup->calledWith(2112);
|
\Phake::verify(Arsse::$db)->userLookup(2112);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddAUser(): void {
|
public function testAddAUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userAdd->returns($pass);
|
\Phake::when($this->drv)->userAdd->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($pass, $u->add($user, $pass));
|
$this->assertSame($pass, $u->add($user, $pass));
|
||||||
$this->drv->userAdd->calledWith($user, $pass);
|
\Phake::verify($this->drv)->userAdd($user, $pass);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddAUserWeDoNotKnow(): void {
|
public function testAddAUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userAdd->returns($pass);
|
\Phake::when($this->drv)->userAdd->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($pass, $u->add($user, $pass));
|
$this->assertSame($pass, $u->add($user, $pass));
|
||||||
$this->drv->userAdd->calledWith($user, $pass);
|
\Phake::verify($this->drv)->userAdd($user, $pass);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->dbMock->userAdd->calledWith($user, $pass);
|
\Phake::verify(Arsse::$db)->userAdd($user, $pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddADuplicateUser(): void {
|
public function testAddADuplicateUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userAdd->throws(new ExceptionConflict("alreadyExists"));
|
\Phake::when($this->drv)->userAdd->thenThrow(new ExceptionConflict("alreadyExists"));
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("alreadyExists", "User", "ExceptionConflict");
|
$this->assertException("alreadyExists", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->add($user, $pass);
|
$u->add($user, $pass);
|
||||||
} finally {
|
} finally {
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->drv->userAdd->calledWith($user, $pass);
|
\Phake::verify($this->drv)->userAdd($user, $pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddADuplicateUserWeDoNotKnow(): void {
|
public function testAddADuplicateUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userAdd->throws(new ExceptionConflict("alreadyExists"));
|
\Phake::when($this->drv)->userAdd->thenThrow(new ExceptionConflict("alreadyExists"));
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("alreadyExists", "User", "ExceptionConflict");
|
$this->assertException("alreadyExists", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->add($user, $pass);
|
$u->add($user, $pass);
|
||||||
} finally {
|
} finally {
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->dbMock->userAdd->calledWith($user, null);
|
\Phake::verify(Arsse::$db)->userAdd($user, null);
|
||||||
$this->drv->userAdd->calledWith($user, $pass);
|
\Phake::verify($this->drv)->userAdd($user, $pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,68 +178,67 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function testAddAUserWithARandomPassword(): void {
|
public function testAddAUserWithARandomPassword(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "random password";
|
$pass = "random password";
|
||||||
$this->drv->userAdd->returns(null)->returns($pass);
|
$u = \Phake::partialMock(User::class, $this->drv);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when($u)->generatePassword->thenReturn($pass);
|
||||||
$u = $this->prepTest(function($u) use ($pass) {
|
\Phake::when($this->drv)->userAdd->thenReturn(null)->thenReturn($pass);
|
||||||
$u->generatePassword->returns($pass);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
});
|
|
||||||
$this->assertSame($pass, $u->add($user));
|
$this->assertSame($pass, $u->add($user));
|
||||||
$this->drv->userAdd->calledWith($user, null);
|
\Phake::verify($this->drv)->userAdd($user, null);
|
||||||
$this->drv->userAdd->calledWith($user, $pass);
|
\Phake::verify($this->drv)->userAdd($user, $pass);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenameAUser(): void {
|
public function testRenameAUser(): void {
|
||||||
$tr = $this->mock(Transaction::class);
|
$tr = \Phake::mock(Transaction::class);
|
||||||
$this->dbMock->begin->returns($tr);
|
\Phake::when(Arsse::$db)->begin->thenReturn($tr);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$this->dbMock->userAdd->returns(true);
|
\Phake::when(Arsse::$db)->userAdd->thenReturn(true);
|
||||||
$this->dbMock->userRename->returns(true);
|
\Phake::when(Arsse::$db)->userRename->thenReturn(true);
|
||||||
$this->drv->userRename->returns(true);
|
\Phake::when($this->drv)->userRename->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$old = "john.doe@example.com";
|
$old = "john.doe@example.com";
|
||||||
$new = "jane.doe@example.com";
|
$new = "jane.doe@example.com";
|
||||||
$this->assertTrue($u->rename($old, $new));
|
$this->assertTrue($u->rename($old, $new));
|
||||||
Phony::inOrder(
|
\Phake::inOrder(
|
||||||
$this->drv->userRename->calledWith($old, $new),
|
\Phake::verify($this->drv)->userRename($old, $new),
|
||||||
$this->dbMock->begin->calledWith(),
|
\Phake::verify(Arsse::$db)->begin(),
|
||||||
$this->dbMock->userExists->calledWith($old),
|
\Phake::verify(Arsse::$db)->userExists($old),
|
||||||
$this->dbMock->userRename->calledWith($old, $new),
|
\Phake::verify(Arsse::$db)->userRename($old, $new),
|
||||||
$this->dbMock->sessionDestroy->calledWith($new),
|
\Phake::verify(Arsse::$db)->sessionDestroy($new),
|
||||||
$this->dbMock->tokenRevoke->calledWith($new, "fever.login"),
|
\Phake::verify(Arsse::$db)->tokenRevoke($new, "fever.login"),
|
||||||
$tr->commit->called()
|
\Phake::verify($tr)->commit()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenameAUserWeDoNotKnow(): void {
|
public function testRenameAUserWeDoNotKnow(): void {
|
||||||
$tr = $this->mock(Transaction::class);
|
$tr = \Phake::mock(Transaction::class);
|
||||||
$this->dbMock->begin->returns($tr);
|
\Phake::when(Arsse::$db)->begin->thenReturn($tr);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$this->dbMock->userAdd->returns(true);
|
\Phake::when(Arsse::$db)->userAdd->thenReturn(true);
|
||||||
$this->dbMock->userRename->returns(true);
|
\Phake::when(Arsse::$db)->userRename->thenReturn(true);
|
||||||
$this->drv->userRename->returns(true);
|
\Phake::when($this->drv)->userRename->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$old = "john.doe@example.com";
|
$old = "john.doe@example.com";
|
||||||
$new = "jane.doe@example.com";
|
$new = "jane.doe@example.com";
|
||||||
$this->assertTrue($u->rename($old, $new));
|
$this->assertTrue($u->rename($old, $new));
|
||||||
Phony::inOrder(
|
\Phake::inOrder(
|
||||||
$this->drv->userRename->calledWith($old, $new),
|
\Phake::verify($this->drv)->userRename($old, $new),
|
||||||
$this->dbMock->begin->calledWith(),
|
\Phake::verify(Arsse::$db)->begin(),
|
||||||
$this->dbMock->userExists->calledWith($old),
|
\Phake::verify(Arsse::$db)->userExists($old),
|
||||||
$this->dbMock->userAdd->calledWith($new, null),
|
\Phake::verify(Arsse::$db)->userAdd($new, null),
|
||||||
$tr->commit->called()
|
\Phake::verify($tr)->commit()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenameAUserWithoutEffect(): void {
|
public function testRenameAUserWithoutEffect(): void {
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$this->dbMock->userAdd->returns(true);
|
\Phake::when(Arsse::$db)->userAdd->thenReturn(true);
|
||||||
$this->dbMock->userRename->returns(true);
|
\Phake::when(Arsse::$db)->userRename->thenReturn(true);
|
||||||
$this->drv->userRename->returns(false);
|
\Phake::when($this->drv)->userRename->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$old = "john.doe@example.com";
|
$old = "john.doe@example.com";
|
||||||
$this->assertFalse($u->rename($old, $old));
|
$this->assertFalse($u->rename($old, $old));
|
||||||
$this->drv->userRename->calledWith($old, $old);
|
\Phake::verify($this->drv)->userRename($old, $old);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider provideInvalidUserNames */
|
/** @dataProvider provideInvalidUserNames */
|
||||||
|
@ -251,164 +250,159 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function testRemoveAUser(): void {
|
public function testRemoveAUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userRemove->returns(true);
|
\Phake::when($this->drv)->userRemove->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertTrue($u->remove($user));
|
$this->assertTrue($u->remove($user));
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->dbMock->userRemove->calledWith($user);
|
\Phake::verify(Arsse::$db)->userRemove($user);
|
||||||
$this->drv->userRemove->calledWith($user);
|
\Phake::verify($this->drv)->userRemove($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveAUserWeDoNotKnow(): void {
|
public function testRemoveAUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userRemove->returns(true);
|
\Phake::when($this->drv)->userRemove->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertTrue($u->remove($user));
|
$this->assertTrue($u->remove($user));
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->drv->userRemove->calledWith($user);
|
\Phake::verify($this->drv)->userRemove($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveAMissingUser(): void {
|
public function testRemoveAMissingUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
\Phake::when($this->drv)->userRemove->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
$this->drv->userRemove->throws(new ExceptionConflict("doesNotExist"));
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(true);
|
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->remove($user);
|
$u->remove($user);
|
||||||
} finally {
|
} finally {
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->dbMock->userRemove->calledWith($user);
|
\Phake::verify(Arsse::$db)->userRemove($user);
|
||||||
$this->drv->userRemove->calledWith($user);
|
\Phake::verify($this->drv)->userRemove($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveAMissingUserWeDoNotKnow(): void {
|
public function testRemoveAMissingUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
\Phake::when($this->drv)->userRemove->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
$this->drv->userRemove->throws(new ExceptionConflict("doesNotExist"));
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$this->dbMock->userExists->returns(false);
|
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->remove($user);
|
$u->remove($user);
|
||||||
} finally {
|
} finally {
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
$this->drv->userRemove->calledWith($user);
|
\Phake::verify($this->drv)->userRemove($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAPassword(): void {
|
public function testSetAPassword(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userPasswordSet->returns($pass);
|
\Phake::when($this->drv)->userPasswordSet->thenReturn($pass);
|
||||||
$this->dbMock->userPasswordSet->returns($pass);
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($pass, $u->passwordSet($user, $pass));
|
$this->assertSame($pass, $u->passwordSet($user, $pass));
|
||||||
$this->drv->userPasswordSet->calledWith($user, $pass, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, $pass, null);
|
||||||
$this->dbMock->userPasswordSet->calledWith($user, $pass);
|
\Phake::verify(Arsse::$db)->userPasswordSet($user, $pass);
|
||||||
$this->dbMock->sessionDestroy->calledWith($user);
|
\Phake::verify(Arsse::$db)->sessionDestroy($user);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetARandomPassword(): void {
|
public function testSetARandomPassword(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "random password";
|
$pass = "random password";
|
||||||
$this->drv->userPasswordSet->returns(null)->returns($pass);
|
$u = \Phake::partialMock(User::class, $this->drv);
|
||||||
$this->dbMock->userPasswordSet->returns($pass);
|
\Phake::when($u)->generatePassword->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when($this->drv)->userPasswordSet->thenReturn(null)->thenReturn($pass);
|
||||||
$u = $this->prepTest(function($u) use ($pass) {
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn($pass);
|
||||||
$u->generatePassword->returns($pass);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
});
|
|
||||||
$this->assertSame($pass, $u->passwordSet($user, null));
|
$this->assertSame($pass, $u->passwordSet($user, null));
|
||||||
$this->drv->userPasswordSet->calledWith($user, null, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, null, null);
|
||||||
$this->drv->userPasswordSet->calledWith($user, $pass, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, $pass, null);
|
||||||
$this->dbMock->userPasswordSet->calledWith($user, $pass);
|
\Phake::verify(Arsse::$db)->userPasswordSet($user, $pass);
|
||||||
$this->dbMock->sessionDestroy->calledWith($user);
|
\Phake::verify(Arsse::$db)->sessionDestroy($user);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAPasswordForAUserWeDoNotKnow(): void {
|
public function testSetAPasswordForAUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "secret";
|
$pass = "secret";
|
||||||
$this->drv->userPasswordSet->returns($pass);
|
\Phake::when($this->drv)->userPasswordSet->thenReturn($pass);
|
||||||
$this->dbMock->userPasswordSet->returns($pass);
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($pass, $u->passwordSet($user, $pass));
|
$this->assertSame($pass, $u->passwordSet($user, $pass));
|
||||||
$this->drv->userPasswordSet->calledWith($user, $pass, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, $pass, null);
|
||||||
$this->dbMock->userAdd->calledWith($user, $pass);
|
\Phake::verify(Arsse::$db)->userAdd($user, $pass);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetARandomPasswordForAUserWeDoNotKnow(): void {
|
public function testSetARandomPasswordForAUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "random password";
|
$pass = "random password";
|
||||||
$this->drv->userPasswordSet->returns(null)->returns($pass);
|
$u = \Phake::partialMock(User::class, $this->drv);
|
||||||
$this->dbMock->userPasswordSet->returns($pass);
|
\Phake::when($u)->generatePassword->thenReturn($pass);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when($this->drv)->userPasswordSet->thenReturn(null)->thenReturn($pass);
|
||||||
$u = $this->prepTest(function($u) use ($pass) {
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn($pass);
|
||||||
$u->generatePassword->returns($pass);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
});
|
|
||||||
$this->assertSame($pass, $u->passwordSet($user, null));
|
$this->assertSame($pass, $u->passwordSet($user, null));
|
||||||
$this->drv->userPasswordSet->calledWith($user, null, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, null, null);
|
||||||
$this->drv->userPasswordSet->calledWith($user, $pass, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, $pass, null);
|
||||||
$this->dbMock->userAdd->calledWith($user, $pass);
|
\Phake::verify(Arsse::$db)->userAdd($user, $pass);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetARandomPasswordForAMissingUser(): void {
|
public function testSetARandomPasswordForAMissingUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$pass = "random password";
|
$pass = "random password";
|
||||||
$this->drv->userPasswordSet->throws(new ExceptionConflict("doesNotExist"));
|
$u = \Phake::partialMock(User::class, $this->drv);
|
||||||
$u = $this->prepTest(function($u) use ($pass) {
|
\Phake::when($u)->generatePassword->thenReturn($pass);
|
||||||
$u->generatePassword->returns($pass);
|
\Phake::when($this->drv)->userPasswordSet->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
});
|
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->passwordSet($user, null);
|
$u->passwordSet($user, null);
|
||||||
} finally {
|
} finally {
|
||||||
$this->drv->userPasswordSet->calledWith($user, null, null);
|
\Phake::verify($this->drv)->userPasswordSet($user, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnsetAPassword(): void {
|
public function testUnsetAPassword(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userPasswordUnset->returns(true);
|
\Phake::when($this->drv)->userPasswordUnset->thenReturn(true);
|
||||||
$this->dbMock->userPasswordSet->returns(true);
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertTrue($u->passwordUnset($user));
|
$this->assertTrue($u->passwordUnset($user));
|
||||||
$this->drv->userPasswordUnset->calledWith($user, null);
|
\Phake::verify($this->drv)->userPasswordUnset($user, null);
|
||||||
$this->dbMock->userPasswordSet->calledWith($user, null);
|
\Phake::verify(Arsse::$db)->userPasswordSet($user, null);
|
||||||
$this->dbMock->sessionDestroy->calledWith($user);
|
\Phake::verify(Arsse::$db)->sessionDestroy($user);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnsetAPasswordForAUserWeDoNotKnow(): void {
|
public function testUnsetAPasswordForAUserWeDoNotKnow(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userPasswordUnset->returns(true);
|
\Phake::when($this->drv)->userPasswordUnset->thenReturn(true);
|
||||||
$this->dbMock->userPasswordSet->returns(true);
|
\Phake::when(Arsse::$db)->userPasswordSet->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertTrue($u->passwordUnset($user));
|
$this->assertTrue($u->passwordUnset($user));
|
||||||
$this->drv->userPasswordUnset->calledWith($user, null);
|
\Phake::verify($this->drv)->userPasswordUnset($user, null);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnsetAPasswordForAMissingUser(): void {
|
public function testUnsetAPasswordForAMissingUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userPasswordUnset->throws(new ExceptionConflict("doesNotExist"));
|
\Phake::when($this->drv)->userPasswordUnset->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->passwordUnset($user);
|
$u->passwordUnset($user);
|
||||||
} finally {
|
} finally {
|
||||||
$this->drv->userPasswordUnset->calledWith($user, null);
|
\Phake::verify($this->drv)->userPasswordUnset($user, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,14 +410,14 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function testGetThePropertiesOfAUser(array $exp, array $base, array $extra): void {
|
public function testGetThePropertiesOfAUser(array $exp, array $base, array $extra): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$exp = array_merge(['num' => null], array_combine(array_keys(User::PROPERTIES), array_fill(0, sizeof(User::PROPERTIES), null)), $exp);
|
$exp = array_merge(['num' => null], array_combine(array_keys(User::PROPERTIES), array_fill(0, sizeof(User::PROPERTIES), null)), $exp);
|
||||||
$this->drv->userPropertiesGet->returns($extra);
|
\Phake::when($this->drv)->userPropertiesGet->thenReturn($extra);
|
||||||
$this->dbMock->userPropertiesGet->returns($base);
|
\Phake::when(Arsse::$db)->userPropertiesGet->thenReturn($base);
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($exp, $u->propertiesGet($user));
|
$this->assertSame($exp, $u->propertiesGet($user));
|
||||||
$this->drv->userPropertiesGet->calledWith($user, true);
|
\Phake::verify($this->drv)->userPropertiesGet($user, true);
|
||||||
$this->dbMock->userPropertiesGet->calledWith($user, true);
|
\Phake::verify(Arsse::$db)->userPropertiesGet($user, true);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideProperties(): iterable {
|
public function provideProperties(): iterable {
|
||||||
|
@ -442,28 +436,28 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$base = ['num' => 47, 'admin' => false, 'lang' => null, 'tz' => "Etc/UTC", 'sort_asc' => false];
|
$base = ['num' => 47, 'admin' => false, 'lang' => null, 'tz' => "Etc/UTC", 'sort_asc' => false];
|
||||||
$exp = ['num' => 47, 'admin' => false, 'lang' => null, 'tz' => "Europe/Istanbul", 'sort_asc' => false];
|
$exp = ['num' => 47, 'admin' => false, 'lang' => null, 'tz' => "Europe/Istanbul", 'sort_asc' => false];
|
||||||
$exp = array_merge(['num' => null], array_combine(array_keys(User::PROPERTIES), array_fill(0, sizeof(User::PROPERTIES), null)), $exp);
|
$exp = array_merge(['num' => null], array_combine(array_keys(User::PROPERTIES), array_fill(0, sizeof(User::PROPERTIES), null)), $exp);
|
||||||
$this->drv->userPropertiesGet->returns($extra);
|
\Phake::when($this->drv)->userPropertiesGet->thenReturn($extra);
|
||||||
$this->dbMock->userPropertiesGet->returns($base);
|
\Phake::when(Arsse::$db)->userPropertiesGet->thenReturn($base);
|
||||||
$this->dbMock->userAdd->returns(true);
|
\Phake::when(Arsse::$db)->userAdd->thenReturn(true);
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($exp, $u->propertiesGet($user));
|
$this->assertSame($exp, $u->propertiesGet($user));
|
||||||
$this->drv->userPropertiesGet->calledWith($user, true);
|
\Phake::verify($this->drv)->userPropertiesGet($user, true);
|
||||||
$this->dbMock->userPropertiesGet->calledWith($user, true);
|
\Phake::verify(Arsse::$db)->userPropertiesGet($user, true);
|
||||||
$this->dbMock->userPropertiesSet->calledWith($user, $extra);
|
\Phake::verify(Arsse::$db)->userPropertiesSet($user, $extra);
|
||||||
$this->dbMock->userAdd->calledWith($user, null);
|
\Phake::verify(Arsse::$db)->userAdd($user, null);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetThePropertiesOfAMissingUser(): void {
|
public function testGetThePropertiesOfAMissingUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$this->drv->userPropertiesGet->throws(new ExceptionConflict("doesNotExist"));
|
\Phake::when($this->drv)->userPropertiesGet->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->propertiesGet($user);
|
$u->propertiesGet($user);
|
||||||
} finally {
|
} finally {
|
||||||
$this->drv->userPropertiesGet->calledWith($user, true);
|
\Phake::verify($this->drv)->userPropertiesGet($user, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,14 +469,14 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->assertException($out);
|
$this->assertException($out);
|
||||||
$u->propertiesSet($user, $in);
|
$u->propertiesSet($user, $in);
|
||||||
} else {
|
} else {
|
||||||
$this->dbMock->userExists->returns(true);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
|
||||||
$this->drv->userPropertiesSet->returns($out);
|
\Phake::when($this->drv)->userPropertiesSet->thenReturn($out);
|
||||||
$this->dbMock->userPropertiesSet->returns(true);
|
\Phake::when(Arsse::$db)->userPropertiesSet->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($out, $u->propertiesSet($user, $in));
|
$this->assertSame($out, $u->propertiesSet($user, $in));
|
||||||
$this->drv->userPropertiesSet->calledWith($user, $in);
|
\Phake::verify($this->drv)->userPropertiesSet($user, $in);
|
||||||
$this->dbMock->userPropertiesSet->calledWith($user, $out);
|
\Phake::verify(Arsse::$db)->userPropertiesSet($user, $out);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::verify(Arsse::$db)->userExists($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,15 +488,15 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->assertException($out);
|
$this->assertException($out);
|
||||||
$u->propertiesSet($user, $in);
|
$u->propertiesSet($user, $in);
|
||||||
} else {
|
} else {
|
||||||
$this->dbMock->userExists->returns(false);
|
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
|
||||||
$this->drv->userPropertiesSet->returns($out);
|
\Phake::when($this->drv)->userPropertiesSet->thenReturn($out);
|
||||||
$this->dbMock->userPropertiesSet->returns(true);
|
\Phake::when(Arsse::$db)->userPropertiesSet->thenReturn(true);
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertSame($out, $u->propertiesSet($user, $in));
|
$this->assertSame($out, $u->propertiesSet($user, $in));
|
||||||
$this->drv->userPropertiesSet->calledWith($user, $in);
|
\Phake::when($this->drv)->userPropertiesSet($user, $in);
|
||||||
$this->dbMock->userPropertiesSet->calledWith($user, $out);
|
\Phake::when(Arsse::$db)->userPropertiesSet($user, $out);
|
||||||
$this->dbMock->userExists->calledWith($user);
|
\Phake::when(Arsse::$db)->userExists($user);
|
||||||
$this->dbMock->userAdd->calledWith($user, null);
|
\Phake::when(Arsse::$db)->userAdd($user, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,13 +517,13 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function testSetThePropertiesOfAMissingUser(): void {
|
public function testSetThePropertiesOfAMissingUser(): void {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$in = ['admin' => true];
|
$in = ['admin' => true];
|
||||||
$this->drv->userPropertiesSet->throws(new ExceptionConflict("doesNotExist"));
|
\Phake::when($this->drv)->userPropertiesSet->thenThrow(new ExceptionConflict("doesNotExist"));
|
||||||
$u = new User($this->drv);
|
$u = new User($this->drv);
|
||||||
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
$this->assertException("doesNotExist", "User", "ExceptionConflict");
|
||||||
try {
|
try {
|
||||||
$u->propertiesSet($user, $in);
|
$u->propertiesSet($user, $in);
|
||||||
} finally {
|
} finally {
|
||||||
$this->drv->userPropertiesSet->calledWith($user, $in);
|
\Phake::verify($this->drv)->userPropertiesSet($user, $in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue