@@ -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