summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2016-12-22 22:02:23 +0100
committerArnold Daniels <arnold@jasny.net>2016-12-22 22:02:23 +0100
commitef75e4c7123fdb2d728def81e509fd8190264b78 (patch)
tree70cf24911bc3ddd9c9d92758378d1d40b7cab906
parentecdd68ca23e9b48cc2b5338bebb9603e69bb4757 (diff)
downloadauth-ef75e4c7123fdb2d728def81e509fd8190264b78.zip
auth-ef75e4c7123fdb2d728def81e509fd8190264b78.tar.gz
auth-ef75e4c7123fdb2d728def81e509fd8190264b78.tar.bz2
Add test for Auth
-rw-r--r--tests/AuthTest.php85
1 files changed, 50 insertions, 35 deletions
diff --git a/tests/AuthTest.php b/tests/AuthTest.php
index 8e04951..90e88b9 100644
--- a/tests/AuthTest.php
+++ b/tests/AuthTest.php
@@ -60,41 +60,6 @@ class AuthTest extends TestCase
$this->assertFalse($this->auth->verifyCredentials($user, ''));
}
-
- public function testLogin()
- {
- $hash = password_hash('abc', PASSWORD_BCRYPT);
-
- $user = $this->createMock(Auth\User::class);
- $user->method('getHashedPassword')->willReturn($hash);
- $user->expects($this->once())->method('onLogin');
-
- $this->auth->expects($this->once())->method('fetchUserByUsername')->with('john')->willReturn($user);
- $this->auth->expects($this->once())->method('persistCurrentUser');
-
- $result = $this->auth->login('john', 'abc');
-
- $this->assertSame($user, $result);
- $this->assertSame($user, $this->auth->user());
- }
-
- public function testLoginWithIncorrectPassword()
- {
- $hash = password_hash('abc', PASSWORD_BCRYPT);
-
- $user = $this->createMock(Auth\User::class);
- $user->method('getHashedPassword')->willReturn($hash);
- $user->expects($this->never())->method('onLogin');
-
- $this->auth->expects($this->once())->method('fetchUserByUsername')->with('john')->willReturn($user);
- $this->auth->expects($this->never())->method('persistCurrentUser');
-
- $result = $this->auth->login('john', 'god');
-
- $this->assertNull($result);
- $this->assertNull($this->auth->user());
- }
-
/**
* @return Auth|MockObject
*/
@@ -144,4 +109,54 @@ class AuthTest extends TestCase
$this->assertNull($result);
$this->assertSame($oldUser, $this->auth->user());
}
+
+
+ public function testLogin()
+ {
+ $hash = password_hash('abc', PASSWORD_BCRYPT);
+
+ $user = $this->createMock(Auth\User::class);
+ $user->method('getHashedPassword')->willReturn($hash);
+ $user->expects($this->once())->method('onLogin');
+
+ $this->auth->expects($this->once())->method('fetchUserByUsername')->with('john')->willReturn($user);
+ $this->auth->expects($this->once())->method('persistCurrentUser');
+
+ $result = $this->auth->login('john', 'abc');
+
+ $this->assertSame($user, $result);
+ $this->assertSame($user, $this->auth->user());
+ }
+
+ public function testLoginWithIncorrectPassword()
+ {
+ $hash = password_hash('abc', PASSWORD_BCRYPT);
+
+ $user = $this->createMock(Auth\User::class);
+ $user->method('getHashedPassword')->willReturn($hash);
+ $user->expects($this->never())->method('onLogin');
+
+ $this->auth->expects($this->once())->method('fetchUserByUsername')->with('john')->willReturn($user);
+ $this->auth->expects($this->never())->method('persistCurrentUser');
+
+ $result = $this->auth->login('john', 'god');
+
+ $this->assertNull($result);
+ $this->assertNull($this->auth->user());
+ }
+
+ public function testLogout()
+ {
+ $user = $this->createMock(Auth\User::class);
+ $user->expects($this->once())->method('onLogout');
+
+ $this->auth->setUser($user);
+
+ $this->auth->logout();
+
+ $this->assertNull($this->auth->user());
+
+ // Logout again shouldn't really do anything
+ $this->auth->logout();
+ }
}