FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Auth/AuthDatabaseTokenRepositoryTest.php at master · JavaDevl/framework · GitHub
JavaDevl
/
framework
Public
forked from
laravel/framework
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
framework
/
tests
/
Auth
/
AuthDatabaseTokenRepositoryTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
93 lines (77 loc) · 3.95 KB
Breadcrumbs
framework
/
tests
/
Auth
/
AuthDatabaseTokenRepositoryTest.php
Copy path
File metadata and controls
executable file
·
93 lines (77 loc) · 3.95 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
use
Mockery
as
m
;
class
AuthDatabaseTokenRepositoryTest
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\Contracts\Auth\CanResetPassword
'
);
$
user
->
shouldReceive
(
'
getEmailForPasswordReset
'
)->
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\Contracts\Auth\CanResetPassword
'
);
$
user
->
shouldReceive
(
'
getEmailForPasswordReset
'
)->
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
) [
'
created_at
'
=>
$
date
]);
$
user
= m::
mock
(
'
Illuminate\Contracts\Auth\CanResetPassword
'
);
$
user
->
shouldReceive
(
'
getEmailForPasswordReset
'
)->
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
) [
'
created_at
'
=>
$
date
]);
$
user
= m::
mock
(
'
Illuminate\Contracts\Auth\CanResetPassword
'
);
$
user
->
shouldReceive
(
'
getEmailForPasswordReset
'
)->
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
\
Passwords
\
DatabaseTokenRepository
(m::
mock
(
'
Illuminate\Database\Connection
'
),
'
table
'
,
'
key
'
);
}
}
Back
|
FazBrowse Home
|
New Git URL