@@ -97,30 +97,63 @@ function (ResponseInterface $response, string $template, array $data) use (&$cap
9797 $ this ->assertArrayHasKey ('alertBoxWidgetSoundUrl ' , $ capturedData );
9898 }
9999
100- public function testWidgetAlertThrowsWhenNoIdProvided (): void
100+ public function testWidgetAlertRendersErrorWhenNoIdProvided (): void
101101 {
102- $ this ->expectException (Exception::class);
102+ $ capturedTemplate = null ;
103+ $ this ->view ->method ('render ' )
104+ ->willReturnCallback (
105+ function (ResponseInterface $ response , string $ template , array $ data ) use (&$ capturedTemplate ) {
106+ $ capturedTemplate = $ template ;
107+ $ response ->getBody ()->write ('<html>error</html> ' );
108+ return $ response ;
109+ }
110+ );
111+
103112 $ request = (new ServerRequestFactory ())->createServerRequest ('GET ' , '/widget-stream-alert/ ' );
104113 $ this ->controller ->widgetAlert ($ request , new Response (), ['id ' => '' ]);
114+
115+ $ this ->assertEquals ('widget/error.html.twig ' , $ capturedTemplate );
105116 }
106117
107- public function testWidgetAlertThrowsWhenWidgetNotFound (): void
118+ public function testWidgetAlertRendersErrorWhenWidgetNotFound (): void
108119 {
109120 $ this ->widgetRepository ->method ('selectAlertWidgetByGuid ' )->willReturn (null );
110121
111- $ this ->expectException (Exception::class);
122+ $ capturedTemplate = null ;
123+ $ this ->view ->method ('render ' )
124+ ->willReturnCallback (
125+ function (ResponseInterface $ response , string $ template , array $ data ) use (&$ capturedTemplate ) {
126+ $ capturedTemplate = $ template ;
127+ $ response ->getBody ()->write ('<html>error</html> ' );
128+ return $ response ;
129+ }
130+ );
131+
112132 $ request = (new ServerRequestFactory ())->createServerRequest ('GET ' , '/widget-stream-alert/unknown ' );
113133 $ this ->controller ->widgetAlert ($ request , new Response (), ['id ' => 'unknown-guid ' ]);
134+
135+ $ this ->assertEquals ('widget/error.html.twig ' , $ capturedTemplate );
114136 }
115137
116- public function testWidgetAlertThrowsWhenStreamNotFound (): void
138+ public function testWidgetAlertRendersErrorWhenStreamNotFound (): void
117139 {
118140 $ this ->widgetRepository ->method ('selectAlertWidgetByGuid ' )->willReturn ($ this ->buildAlertWidget ('g ' ));
119141 $ this ->streamRepository ->method ('selectByGuid ' )->willReturn (null );
120142
121- $ this ->expectException (Exception::class);
143+ $ capturedTemplate = null ;
144+ $ this ->view ->method ('render ' )
145+ ->willReturnCallback (
146+ function (ResponseInterface $ response , string $ template , array $ data ) use (&$ capturedTemplate ) {
147+ $ capturedTemplate = $ template ;
148+ $ response ->getBody ()->write ('<html>error</html> ' );
149+ return $ response ;
150+ }
151+ );
152+
122153 $ request = (new ServerRequestFactory ())->createServerRequest ('GET ' , '/widget-stream-alert/g ' );
123154 $ this ->controller ->widgetAlert ($ request , new Response (), ['id ' => 'g ' ]);
155+
156+ $ this ->assertEquals ('widget/error.html.twig ' , $ capturedTemplate );
124157 }
125158
126159 // =====================================================================
@@ -228,20 +261,42 @@ function (ResponseInterface $response, string $template, array $data) use (&$cap
228261 $ this ->assertArrayHasKey ('donationGoalWidget ' , $ capturedData );
229262 }
230263
231- public function testWidgetDonationThrowsWhenNoIdProvided (): void
264+ public function testWidgetDonationRendersErrorWhenNoIdProvided (): void
232265 {
233- $ this ->expectException (Exception::class);
266+ $ capturedTemplate = null ;
267+ $ this ->view ->method ('render ' )
268+ ->willReturnCallback (
269+ function (ResponseInterface $ response , string $ template , array $ data ) use (&$ capturedTemplate ) {
270+ $ capturedTemplate = $ template ;
271+ $ response ->getBody ()->write ('<html>error</html> ' );
272+ return $ response ;
273+ }
274+ );
275+
234276 $ request = (new ServerRequestFactory ())->createServerRequest ('GET ' , '/widget-stream-donation/ ' );
235277 $ this ->controller ->widgetDonation ($ request , new Response (), ['id ' => '' ]);
278+
279+ $ this ->assertEquals ('widget/error.html.twig ' , $ capturedTemplate );
236280 }
237281
238- public function testWidgetDonationThrowsWhenWidgetNotFound (): void
282+ public function testWidgetDonationRendersErrorWhenWidgetNotFound (): void
239283 {
240284 $ this ->widgetRepository ->method ('selectDonationWidgetByGuid ' )->willReturn (null );
241285
242- $ this ->expectException (Exception::class);
286+ $ capturedTemplate = null ;
287+ $ this ->view ->method ('render ' )
288+ ->willReturnCallback (
289+ function (ResponseInterface $ response , string $ template , array $ data ) use (&$ capturedTemplate ) {
290+ $ capturedTemplate = $ template ;
291+ $ response ->getBody ()->write ('<html>error</html> ' );
292+ return $ response ;
293+ }
294+ );
295+
243296 $ request = (new ServerRequestFactory ())->createServerRequest ('GET ' , '/widget-stream-donation/x ' );
244297 $ this ->controller ->widgetDonation ($ request , new Response (), ['id ' => 'x ' ]);
298+
299+ $ this ->assertEquals ('widget/error.html.twig ' , $ capturedTemplate );
245300 }
246301
247302 // =====================================================================
0 commit comments