@@ -10,21 +10,27 @@ class ContactControllerTest extends TestCase
10
10
* @dataProvider dataProvider
11
11
* @test
12
12
*
13
+ * @param bool $isClientPermittedPasswordGrant
14
+ * @param array $returnValueMap
15
+ * @param bool $isCommentAcceptable
16
+ * @param null $expectedException
17
+ * @param null $expectedExceptionMessage
18
+ * @param bool $spamShouldBeChecked
19
+ * @param bool $emailShouldBeSent
20
+ *
21
+ * @throws \Exception
13
22
*/
14
23
public function contactWorksAsExpected (
15
24
$ isClientPermittedPasswordGrant ,
16
25
array $ returnValueMap = [],
17
26
$ isCommentAcceptable = false ,
18
- $ spamCheckServiceIsSet = false ,
19
- $ emailServiceIsSet = false ,
20
27
$ expectedException = null ,
21
28
$ expectedExceptionMessage = null ,
29
+ $ spamShouldBeChecked = false ,
22
30
$ emailShouldBeSent = false
23
31
) {
24
32
$ request = $ this ->getMockBuilder ('\Request ' )->disableOriginalConstructor ()->getMock ();
25
33
26
- $ contactController = new \ContactController ();
27
-
28
34
$ oauthModel = $ this ->getMockBuilder ('\OAuthModel ' )->disableOriginalConstructor ()->getMock ();
29
35
$ oauthModel ->expects ($ this ->once ())->method ('isClientPermittedPasswordGrant ' )->willReturn ($ isClientPermittedPasswordGrant );
30
36
$ request ->expects ($ this ->once ())->method ('getOauthModel ' )->willReturn ($ oauthModel );
@@ -37,26 +43,22 @@ public function contactWorksAsExpected(
37
43
38
44
$ db = $ this ->getMockBuilder ('\PDO ' )->disableOriginalConstructor ()->getMock ();
39
45
40
- if ($ spamCheckServiceIsSet ) {
41
- $ spamCheckService = $ this ->getMockBuilder (\SpamCheckService::class)
42
- ->disableOriginalConstructor ()
43
- ->getMock ();
46
+ $ spamCheckService = $ this ->getMockBuilder (\SpamCheckServiceInterface::class)
47
+ ->disableOriginalConstructor ()
48
+ ->getMock ();
44
49
50
+ if ($ spamShouldBeChecked ) {
45
51
$ spamCheckService
46
52
->expects ($ this ->once ())
47
53
->method ('isCommentAcceptable ' )
48
54
->willReturn ($ isCommentAcceptable );
49
-
50
- $ contactController ->setSpamCheckService ($ spamCheckService );
51
55
}
52
56
53
- if ($ emailServiceIsSet ) {
54
- $ emailService = $ this ->getMockBuilder (\ContactEmailService::class)
55
- ->disableOriginalConstructor ()
56
- ->getMock ();
57
+ $ emailService = $ this ->getMockBuilder (\ContactEmailService::class)
58
+ ->disableOriginalConstructor ()
59
+ ->getMock ();
57
60
58
- $ contactController ->setEmailService ($ emailService );
59
- }
61
+ $ contactController = new \ContactController ($ emailService , $ spamCheckService );
60
62
61
63
if (null !== $ expectedException ) {
62
64
$ this ->expectException ($ expectedException );
@@ -102,11 +104,10 @@ public function dataProvider()
102
104
'isClientPermittedPasswordGrant ' => false ,
103
105
'returnValueMap ' => [],
104
106
'isCommentAcceptable ' => false ,
105
- 'spamCheckServiceIsSet ' => false ,
106
- 'emailCheckServiceIsSet ' => false ,
107
107
'exceptedException ' => 'Exception ' ,
108
108
'expectedExceptionMessage ' => 'This client cannot perform this action ' ,
109
- 'emailShouldBeSent ' => false
109
+ 'emailShouldBeSent ' => false ,
110
+ 'spamShouldBeChecked ' => false
110
111
],
111
112
//Not all required fields are set
112
113
[
@@ -120,8 +121,6 @@ public function dataProvider()
120
121
['comment ' , '' , '' ]
121
122
],
122
123
'isCommentAcceptable ' => false ,
123
- 'spamCheckServiceIsSet ' => false ,
124
- 'emailCheckServiceIsSet ' => true ,
125
124
'exceptedException ' => \Exception::class,
126
125
'expectedExceptionMessage ' => "The fields 'name', 'email', 'subject', 'comment' are required " ,
127
126
],
@@ -138,28 +137,9 @@ public function dataProvider()
138
137
],
139
138
140
139
'isCommentAcceptable ' => false ,
141
- 'spamCheckServiceIsSet ' => true ,
142
- 'emailCheckServiceIsSet ' => true ,
143
140
'exceptedException ' => \Exception::class,
144
141
'expectedExceptionMessage ' => 'Comment failed spam check ' ,
145
- ],
146
- //EmailService check throws an exception
147
- [
148
- 'isClientPermittedPasswordGrant ' => true ,
149
- 'returnValueMap ' => [
150
- ['client_id ' , '' , 'client_id ' ],
151
- ['client_secret ' , '' , 'client_secret ' ],
152
- ['name ' , '' , 'name ' ],
153
- ['email ' , '' , 'email ' ],
154
- ['subject ' , '' , 'subject ' ],
155
- ['comment ' , '' , 'comment ' ]
156
- ],
157
- 'isCommentAcceptable ' => true ,
158
- 'spamCheckServiceIsSet ' => false ,
159
- 'emailCheckServiceIsSet ' => false ,
160
- 'exceptedException ' => \RuntimeException::class,
161
- 'expectedExceptionMessage ' => 'The emailservice has not been set ' ,
162
- 'emailShouldBeSent ' => false
142
+ 'spamShouldBeChecked ' => true ,
163
143
],
164
144
//Email is sent without spamcheck
165
145
[
@@ -173,10 +153,9 @@ public function dataProvider()
173
153
['comment ' , '' , 'comment ' ]
174
154
],
175
155
'isCommentAcceptable ' => true ,
176
- 'spamCheckServiceIsSet ' => false ,
177
- 'emailCheckServiceIsSet ' => true ,
178
156
'exceptedException ' => null ,
179
157
'expectedExceptionMessage ' => null ,
158
+ 'spamShouldBeChecked ' => true ,
180
159
'emailShouldBeSent ' => true
181
160
],
182
161
//All is good email should be sent
@@ -191,10 +170,9 @@ public function dataProvider()
191
170
['comment ' , '' , 'comment ' ]
192
171
],
193
172
'isCommentAcceptable ' => true ,
194
- 'spamCheckServiceIsSet ' => true ,
195
- 'emailCheckServiceIsSet ' => true ,
196
173
'exceptedException ' => null ,
197
174
'expectedExceptionMessage ' => null ,
175
+ 'spamShouldBeChecked ' => true ,
198
176
'emailShouldBeSent ' => true
199
177
]
200
178
];
0 commit comments