-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArrayUserPasswordTest.php
More file actions
73 lines (59 loc) · 1.66 KB
/
ArrayUserPasswordTest.php
File metadata and controls
73 lines (59 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace PhpMiddlewareTest\HttpAuthentication\CredentialAdapter;
use PhpMiddleware\HttpAuthentication\CredentialAdapter\ArrayUserPassword;
use PhpMiddleware\HttpAuthentication\CredentialAdapter\Exception\UsernameNotFoundException;
use PHPUnit_Framework_TestCase;
class ArrayUserPasswordTest extends PHPUnit_Framework_TestCase
{
protected $adapter;
protected $users = [
'boo' => 'bar',
'bar' => 'foo',
];
protected function setUp()
{
$this->adapter = new ArrayUserPassword($this->users);
}
/**
* @dataProvider correctDataProvider
*/
public function testAuthenticate($username, $password)
{
$result = $this->adapter->authenticate($username, $password);
$this->assertTrue($result);
}
/**
* @dataProvider incorrectDataProvider
*/
public function testNotAuthenticate($username, $password)
{
$result = $this->adapter->authenticate($username, $password);
$this->assertFalse($result);
}
public function testGetHash()
{
$result = $this->adapter->getHash('boo', 'any-realm');
$this->assertSame(32, strlen($result));
}
public function testInvalidUsername()
{
$this->setExpectedException(UsernameNotFoundException::class);
$this->adapter->getHash('baz', 'any-realm');
}
public function correctDataProvider()
{
return [
['boo', 'bar'],
['bar', 'foo'],
];
}
public function incorrectDataProvider()
{
return [
['bar', 'boo'],
['bar', null],
['bar', false],
[null, false],
];
}
}