Пример #1
0
 public function testLogout()
 {
     $user = $this->getMockBuilder('\\pmill\\Auth\\Interfaces\\AuthUser')->getMock();
     $user->method('getAuthId')->willReturn(1);
     $user->method('getAuthPassword')->willReturn($this->correctHashedPassword);
     $auth = new \pmill\Auth\Authenticate();
     $auth->login($user, $this->rawPassword);
     $this->assertEquals(1, $auth->getLoggedInUserId());
     $auth->logout();
     $this->assertEquals(null, $auth->getLoggedInUserId());
 }
Пример #2
0
<?php

require_once '../vendor/autoload.php';
require_once 'PasswordUser.php';
$output = [];
$user = new examples\PasswordUser();
$user->setId(1);
$user->setUsername('username');
$user->setPassword('hunter2');
$auth = new \pmill\Auth\Authenticate();
$auth->setMaxAttempts(3);
/**
 * Attempt login with correct password
 */
$auth->login($user, 'hunter2');
$output[] = 'successful login';
$auth->logout();
/**
 * Attempt login with incorrect password
 */
try {
    $auth->login($user, 'incorrect-password');
} catch (\pmill\Auth\Exceptions\PasswordException $e) {
    $output[] = 'login failed, incorrect password';
}
/**
 * Expected output:
 * successful login
 * login failed, incorrect password
 */
print_r($output);