Completed
Push — develop ( e2b887...c09155 )
by
unknown
12:13
created

testIndexAction_WithPostRequest_WhenUserDoesNotHaveAnEmail()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 25

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 43
rs 8.8571
cc 1
eloc 25
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @license       MIT
8
 */
9
10
namespace AuthTest\Controller;
11
12
use Auth\Controller\ForgotPasswordController;
13
use Auth\Form\ForgotPasswordInputFilter;
14
use Auth\Service\Exception;
15
use Test\Bootstrap;
16
use Core\Controller\Plugin\Notification;
17
use CoreTest\Controller\AbstractControllerTestCase;
18
use PHPUnit_Framework_MockObject_MockObject as MockObject;
19
use Zend\Mvc\MvcEvent;
20
use Zend\Http\PhpEnvironment\Request;
21
use Zend\Http\PhpEnvironment\Response;
22
use Zend\Mvc\Controller\PluginManager;
23
use Zend\Stdlib\Parameters;
24
25
class ForgotPasswordControllerTest extends AbstractControllerTestCase
26
{
27
    /**
28
     * @var MockObject
29
     */
30
    private $formMock;
31
32
    /**
33
     * @var MockObject
34
     */
35
    private $serviceMock;
36
37
    public function setUp()
38
    {
39
        $this->init('forgot-password');
40
41
        $this->formMock = $this->getMock('Auth\Form\ForgotPassword');
42
43
        $this->serviceMock = $this->getMockBuilder('Auth\Service\ForgotPassword')
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $loggerMock = $this->getMock('Zend\Log\LoggerInterface');
48
49
        $this->controller = new ForgotPasswordController($this->formMock, $this->serviceMock, $loggerMock);
50
        $this->controller->setEvent($this->event);
51
52
        /** @var PluginManager $controllerPluginManager */
53
        $servicemanager = clone Bootstrap::getServiceManager();
54
        $controllerPluginManager = $servicemanager->get('ControllerPluginManager');
55
        $this->controller->setServiceLocator($servicemanager);
56
        $this->controller->setPluginManager($controllerPluginManager);
57
    }
58
59
    public function testIndexAction_WithGetRequest()
0 ignored issues
show
Coding Style introduced by
function testIndexAction_WithGetRequest() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
60
    {
61
        $request = new Request();
62
        $request->setMethod(Request::METHOD_GET);
63
64
        $result = $this->controller->dispatch($request);
65
66
        $expected = array(
67
            'form' => $this->formMock
68
        );
69
70
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
71
        $this->assertSame($expected, $result);
72
    }
73
74
    public function testIndexAction_WithPostRequest_WhenDataIsInvalid()
0 ignored issues
show
Coding Style introduced by
function testIndexAction...est_WhenDataIsInvalid() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
75
    {
76
        $postData = array();
77
78
        $request = new Request();
79
        $request->setMethod(Request::METHOD_POST);
80
        $request->setPost(new Parameters($postData));
81
82
        $this->formMock->expects($this->once())
83
            ->method('setData')
84
            ->with($postData);
85
86
        $this->formMock->expects($this->once())
87
            ->method('isValid')
88
            ->willReturn(false);
89
90
        $result = $this->controller->dispatch($request);
91
92
        $mvcEvent = new MvcEvent();
93
        $notifications = $this->controller->getServiceLocator()->get('coreListenerNotification');
94
        $notifications->reset()->renderHTML($mvcEvent);
95
96
        $expected = array(
97
            'form' => $this->formMock
98
        );
99
100
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
101
        $this->assertSame($expected, $result);
102
103
        //$fm = $this->controller->flashMessenger();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
104
        //$fm->setNamespace(Notification::NAMESPACE_DANGER);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
        //$expectedMessages = array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
106
        //    'Please fill form correctly'
107
        //);
108
        //$this->assertSame($expectedMessages, $fm->getCurrentMessages());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
    }
110
111
    public function testIndexAction_WithPostRequest_WhenUserCannotBeFoundByUsernameOrEmail()
0 ignored issues
show
Coding Style introduced by
function testIndexAction...oundByUsernameOrEmail() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
112
    {
113
        $postData = array('identity' => uniqid('identity'));
114
115
        $request = new Request();
116
        $request->setMethod(Request::METHOD_POST);
117
        $request->setPost(new Parameters($postData));
118
119
        $this->formMock->expects($this->once())
120
            ->method('setData')
121
            ->with($postData);
122
123
        $this->formMock->expects($this->once())
124
            ->method('isValid')
125
            ->willReturn(true);
126
127
        $this->formMock->expects($this->once())
128
            ->method('getInputFilter')
129
            ->willReturn(new ForgotPasswordInputFilter());
130
131
        $this->serviceMock->expects($this->once())
132
            ->method('proceed')
133
            ->willThrowException(new Exception\UserNotFoundException());
134
135
        $result = $this->controller->dispatch($request);
136
137
        $expected = array(
138
            'form' => $this->formMock
139
        );
140
141
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
142
        $this->assertSame($expected, $result);
143
144
        //$fm = $this->controller->flashMessenger();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
145
        //$fm->setNamespace(Notification::NAMESPACE_DANGER);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
        //$expectedMessages = array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147
        //    'User cannot be found for specified username or email'
148
        //);
149
        //$this->assertSame($expectedMessages, $fm->getCurrentMessages());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
150
    }
151
152
    public function testIndexAction_WithPostRequest_WhenUserDoesNotHaveAnEmail()
0 ignored issues
show
Coding Style introduced by
function testIndexAction...serDoesNotHaveAnEmail() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
153
    {
154
        $postData = array('identity' => uniqid('identity'));
155
156
        $request = new Request();
157
        $request->setMethod(Request::METHOD_POST);
158
        $request->setPost(new Parameters($postData));
159
160
        $this->formMock->expects($this->once())
161
            ->method('setData')
162
            ->with($postData);
163
164
        $this->formMock->expects($this->once())
165
            ->method('isValid')
166
            ->willReturn(true);
167
168
        $this->formMock->expects($this->once())
169
            ->method('getInputFilter')
170
            ->willReturn(new ForgotPasswordInputFilter());
171
172
        $this->serviceMock->expects($this->once())
173
            ->method('proceed')
174
            ->willThrowException(new Exception\UserDoesNotHaveAnEmailException());
175
176
        $result = $this->controller->dispatch($request);
177
178
        $mvcEvent = new MvcEvent();
179
        $notifications = $this->controller->getServiceLocator()->get('coreListenerNotification');
180
        $notifications->reset()->renderHTML($mvcEvent);
181
182
        $expected = array(
183
            'form' => $this->formMock
184
        );
185
186
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
187
        $this->assertSame($expected, $result);
188
189
        // @TODO: Fix this, the messages already have been transferred to somewhere
190
        //$fm = $this->controller->flashMessenger();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
        //$fm->setNamespace(Notification::NAMESPACE_DANGER);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
192
        //$expectedMessages = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
193
        //$this->assertSame($expectedMessages, $fm->getCurrentMessages());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
194
    }
195
196
    public function testIndexAction_WithPostRequest_WhenUnexpectedExceptionHasOccurred()
0 ignored issues
show
Coding Style introduced by
function testIndexAction...dExceptionHasOccurred() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
197
    {
198
        $postData = array('identity' => uniqid('identity'));
199
200
        $request = new Request();
201
        $request->setMethod(Request::METHOD_POST);
202
        $request->setPost(new Parameters($postData));
203
204
        $this->formMock->expects($this->once())
205
            ->method('setData')
206
            ->with($postData);
207
208
        $this->formMock->expects($this->once())
209
            ->method('isValid')
210
            ->willReturn(true);
211
212
        $this->formMock->expects($this->once())
213
            ->method('getInputFilter')
214
            ->willReturn(new ForgotPasswordInputFilter());
215
216
        $this->serviceMock->expects($this->once())
217
            ->method('proceed')
218
            ->willThrowException(new \LogicException());
219
220
        $result = $this->controller->dispatch($request);
221
222
        $expected = array(
223
            'form' => $this->formMock
224
        );
225
226
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
227
        $this->assertSame($expected, $result);
228
229
        //$fm = $this->controller->flashMessenger();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
230
        //$fm->setNamespace(Notification::NAMESPACE_DANGER);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
231
        //$expectedMessages = array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
232
        //    'An unexpected error has occurred, please contact your system administrator'
233
        //);
234
        //$this->assertSame($expectedMessages, $fm->getCurrentMessages());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
235
    }
236
237
    public function testIndexAction_WithPostRequest()
0 ignored issues
show
Coding Style introduced by
function testIndexAction_WithPostRequest() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
238
    {
239
        $postData = array('identity' => uniqid('identity'));
240
241
        $request = new Request();
242
        $request->setMethod(Request::METHOD_POST);
243
        $request->setPost(new Parameters($postData));
244
245
        $this->formMock->expects($this->once())
246
            ->method('setData')
247
            ->with($postData);
248
249
        $this->formMock->expects($this->once())
250
            ->method('isValid')
251
            ->willReturn(true);
252
253
        $this->formMock->expects($this->once())
254
            ->method('getInputFilter')
255
            ->willReturn(new ForgotPasswordInputFilter());
256
257
        $this->serviceMock->expects($this->once())
258
            ->method('proceed');
259
260
        $result = $this->controller->dispatch($request);
261
262
        $expected = array(
263
            'form' => $this->formMock
264
        );
265
266
        $this->assertResponseStatusCode(Response::STATUS_CODE_200);
267
        $this->assertSame($expected, $result);
268
269
        //$fm = $this->controller->flashMessenger();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
270
        //$fm->setNamespace(Notification::NAMESPACE_SUCCESS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
271
        //$expectedMessages = array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
272
        //    'Mail with link for reset password has been sent, please try to check your email box'
273
        //);
274
        //$this->assertSame($expectedMessages, $fm->getCurrentMessages());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
275
    }
276
}