FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Foundation/FoundationFormRequestTest.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
/
Foundation
/
FoundationFormRequestTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
105 lines (91 loc) · 4.08 KB
Breadcrumbs
framework
/
tests
/
Foundation
/
FoundationFormRequestTest.php
Copy path
File metadata and controls
105 lines (91 loc) · 4.08 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
94
95
96
97
98
99
100
101
102
103
104
105
<?php
use
Mockery
as
m
;
use
Illuminate
\
Container
\
Container
;
class
FoundationFormRequestTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
m::
close
();
}
public
function
testValidateFunctionRunsValidatorOnSpecifiedRules
()
{
$
request
= FoundationTestFormRequestStub::
create
(
'
/
'
,
'
GET
'
, [
'
name
'
=>
'
abigail
'
]);
$
request
->
setContainer
(
$
container
=
new
Container
);
$
factory
= m::
mock
(
'
Illuminate\Validation\Factory
'
);
$
factory
->
shouldReceive
(
'
make
'
)->
once
()->
with
([
'
name
'
=>
'
abigail
'
], [
'
name
'
=>
'
required
'
], [], [])->
andReturn
(
$
validator
= m::
mock
(
'
Illuminate\Validation\Validator
'
)
);
$
container
->
instance
(
'
Illuminate\Contracts\Validation\Factory
'
,
$
factory
);
$
validator
->
shouldReceive
(
'
passes
'
)->
once
()->
andReturn
(
true
);
$
request
->
validate
(
$
factory
);
}
/**
* @expectedException \Illuminate\Http\Exception\HttpResponseException
*/
public
function
testValidateFunctionThrowsHttpResponseExceptionIfValidationFails
()
{
$
request
= m::
mock
(
'
FoundationTestFormRequestStub[response]
'
);
$
request
->
initialize
([
'
name
'
=>
null
]);
$
request
->
setContainer
(
$
container
=
new
Container
);
$
factory
= m::
mock
(
'
Illuminate\Validation\Factory
'
);
$
factory
->
shouldReceive
(
'
make
'
)->
once
()->
with
([
'
name
'
=>
null
], [
'
name
'
=>
'
required
'
], [], [])->
andReturn
(
$
validator
= m::
mock
(
'
Illuminate\Validation\Validator
'
)
);
$
container
->
instance
(
'
Illuminate\Contracts\Validation\Factory
'
,
$
factory
);
$
validator
->
shouldReceive
(
'
passes
'
)->
once
()->
andReturn
(
false
);
$
validator
->
shouldReceive
(
'
getMessageBag
'
)->
once
()->
andReturn
(
$
messages
= m::
mock
(
'
Illuminate\Support\MessageBag
'
));
$
messages
->
shouldReceive
(
'
toArray
'
)->
once
()->
andReturn
([
'
name
'
=> [
'
Name required
'
]]);
$
request
->
shouldReceive
(
'
response
'
)->
once
()->
andReturn
(
new
Illuminate
\
Http
\
Response
);
$
request
->
validate
(
$
factory
);
}
/**
* @expectedException \Illuminate\Http\Exception\HttpResponseException
*/
public
function
testValidateFunctionThrowsHttpResponseExceptionIfAuthorizationFails
()
{
$
request
= m::
mock
(
'
FoundationTestFormRequestForbiddenStub[forbiddenResponse]
'
);
$
request
->
initialize
([
'
name
'
=>
null
]);
$
request
->
setContainer
(
$
container
=
new
Container
);
$
factory
= m::
mock
(
'
Illuminate\Validation\Factory
'
);
$
factory
->
shouldReceive
(
'
make
'
)->
once
()->
with
([
'
name
'
=>
null
], [
'
name
'
=>
'
required
'
], [], [])->
andReturn
(
$
validator
= m::
mock
(
'
Illuminate\Validation\Validator
'
)
);
$
container
->
instance
(
'
Illuminate\Contracts\Validation\Factory
'
,
$
factory
);
$
validator
->
shouldReceive
(
'
passes
'
)->
never
();
$
request
->
shouldReceive
(
'
forbiddenResponse
'
)->
once
()->
andReturn
(
new
Illuminate
\
Http
\
Response
);
$
request
->
validate
(
$
factory
);
}
public
function
testRedirectResponseIsProperlyCreatedWithGivenErrors
()
{
$
request
= FoundationTestFormRequestStub::
create
(
'
/
'
,
'
GET
'
);
$
request
->
setRedirector
(
$
redirector
= m::
mock
(
'
Illuminate\Routing\Redirector
'
));
$
redirector
->
shouldReceive
(
'
to
'
)->
once
()->
with
(
'
previous
'
)->
andReturn
(
$
response
= m::
mock
(
'
Illuminate\Http\RedirectResponse
'
));
$
redirector
->
shouldReceive
(
'
getUrlGenerator
'
)->
andReturn
(
$
url
= m::
mock
(
'
StdClass
'
));
$
url
->
shouldReceive
(
'
previous
'
)->
once
()->
andReturn
(
'
previous
'
);
$
response
->
shouldReceive
(
'
withInput
'
)->
andReturn
(
$
response
);
$
response
->
shouldReceive
(
'
withErrors
'
)->
with
([
'
errors
'
],
'
default
'
)->
andReturn
(
$
response
);
$
request
->
response
([
'
errors
'
]);
}
}
class
FoundationTestFormRequestStub
extends
Illuminate
\
Foundation
\
Http
\FormRequest
{
public
function
rules
()
{
return
[
'
name
'
=>
'
required
'
];
}
public
function
authorize
()
{
return
true
;
}
}
class
FoundationTestFormRequestForbiddenStub
extends
Illuminate
\
Foundation
\
Http
\FormRequest
{
public
function
rules
()
{
return
[
'
name
'
=>
'
required
'
];
}
public
function
authorize
()
{
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL