Skip to content

Commit 9468f68

Browse files
committed
On failed call to save(), missing return statement caused conflicting messages to be sent back
Closes #3
1 parent fc12ab3 commit 9468f68

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/LdcUserProfile/Controller/ProfileController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function indexAction()
5353

5454
if ( ! $this->getService()->save($form->getData()) ) {
5555
$fm->addErrorMessage('There was a problem saving your profile update.');
56+
57+
return $vm;
5658
}
5759

5860
$fm->addSuccessMessage('Profile updated successfully!');

tests/LdcUserProfileTest/Controller/ProfileControllerTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testControllerDispatchedWithValidFormDataWillCompleteAndRedirect
119119
$this->mockForm->shouldReceive('isValid')->andReturn(true);
120120
$this->mockForm->shouldReceive('getData')->andReturn($mockResult);
121121

122-
$this->mockProfileService->shouldReceive('save')->withArgs(array($mockResult));
122+
$this->mockProfileService->shouldReceive('save')->withArgs(array($mockResult))->andReturn(true);
123123

124124
$result = $this->controller->indexAction();
125125

@@ -153,6 +153,35 @@ public function testControllerDispatchedWithInvalidFormDataWillRenderForm()
153153
$this->assertSame($this->mockModuleOptions, $result->getVariable('options'));
154154
}
155155

156+
public function testControllerWillRenderFormWhenSaveCallFails()
157+
{
158+
$this->event->setResponse($this->controller->getResponse());
159+
160+
$req = $this->controller->getRequest();
161+
$req->setMethod(Request::METHOD_POST);
162+
$req->getPost()->set('foo', 'bar');
163+
164+
$postData = $req->getPost()->toArray();
165+
$mockResult = new \stdClass();
166+
167+
$mockPrg = \Mockery::mock('Zend\Mvc\Controller\Plugin\PostRedirectGet[__invoke]]');
168+
$mockPrg->shouldReceive('__invoke')->andReturn($postData);
169+
$pm = $this->controller->getPluginManager();
170+
$pm->setService('prg', $mockPrg);
171+
172+
$this->mockForm->shouldReceive('setData')->withArgs(array($postData));
173+
$this->mockForm->shouldReceive('isValid')->andReturn(true);
174+
$this->mockForm->shouldReceive('getData')->andReturn($mockResult);
175+
176+
$this->mockProfileService->shouldReceive('save')->withArgs(array($mockResult))->andReturn(false);
177+
178+
$result = $this->controller->indexAction();
179+
180+
$this->assertInstanceOf('Zend\View\Model\ModelInterface', $result);
181+
$this->assertSame($this->mockForm, $result->getVariable('profileForm'));
182+
$this->assertSame($this->mockModuleOptions, $result->getVariable('options'));
183+
}
184+
156185
public function testGetSetService()
157186
{
158187
$this->mockService = \Mockery::mock('LdcUserProfile\Service\ProfileService');

0 commit comments

Comments
 (0)