forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthDatabaseReminderRepositoryTest.php
More file actions
executable file
·101 lines (76 loc) · 3.6 KB
/
AuthDatabaseReminderRepositoryTest.php
File metadata and controls
executable file
·101 lines (76 loc) · 3.6 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
use Mockery as m;
class AuthDatabaseReminderRepositoryTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testCreateInsertsNewRecordIntoTable()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->with('email', 'email')->andReturn($query);
$query->shouldReceive('delete')->once();
$query->shouldReceive('insert')->once();
$user = m::mock('Illuminate\Auth\Reminders\RemindableInterface');
$user->shouldReceive('getReminderEmail')->andReturn('email');
$results = $repo->create($user);
$this->assertInternalType('string', $results);
$this->assertGreaterThan(1, strlen($results));
}
public function testExistReturnsFalseIfNoRowFoundForUser()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->once()->with('email', 'email')->andReturn($query);
$query->shouldReceive('where')->once()->with('token', 'token')->andReturn($query);
$query->shouldReceive('first')->andReturn(null);
$user = m::mock('Illuminate\Auth\Reminders\RemindableInterface');
$user->shouldReceive('getReminderEmail')->andReturn('email');
$this->assertFalse($repo->exists($user, 'token'));
}
public function testExistReturnsFalseIfRecordIsExpired()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->once()->with('email', 'email')->andReturn($query);
$query->shouldReceive('where')->once()->with('token', 'token')->andReturn($query);
$date = date('Y-m-d H:i:s', time() - 300000);
$query->shouldReceive('first')->andReturn((object) array('created_at' => $date));
$user = m::mock('Illuminate\Auth\Reminders\RemindableInterface');
$user->shouldReceive('getReminderEmail')->andReturn('email');
$this->assertFalse($repo->exists($user, 'token'));
}
public function testExistReturnsTrueIfValidRecordExists()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->once()->with('email', 'email')->andReturn($query);
$query->shouldReceive('where')->once()->with('token', 'token')->andReturn($query);
$date = date('Y-m-d H:i:s', time() - 600);
$query->shouldReceive('first')->andReturn((object) array('created_at' => $date));
$user = m::mock('Illuminate\Auth\Reminders\RemindableInterface');
$user->shouldReceive('getReminderEmail')->andReturn('email');
$this->assertTrue($repo->exists($user, 'token'));
}
public function testDeleteMethodDeletesByToken()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->once()->with('token', 'token')->andReturn($query);
$query->shouldReceive('delete')->once();
$repo->delete('token');
}
public function testDeleteExpiredMethodDeletesExpiredTokens()
{
$repo = $this->getRepo();
$repo->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('where')->once()->with('created_at', '<', m::any())->andReturn($query);
$query->shouldReceive('delete')->once();
$repo->deleteExpired();
}
protected function getRepo()
{
return new Illuminate\Auth\Reminders\DatabaseReminderRepository(m::mock('Illuminate\Database\Connection'), 'table', 'key');
}
}