From 08f6d2de78389d0fed61c6165bee8a071259ee3f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 31 Jul 2016 16:16:26 +0200 Subject: [PATCH] Created ListShortcodesActionTest --- .../test/Action/ListShortcodesActionTest.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 module/Rest/test/Action/ListShortcodesActionTest.php diff --git a/module/Rest/test/Action/ListShortcodesActionTest.php b/module/Rest/test/Action/ListShortcodesActionTest.php new file mode 100644 index 00000000..b5ec0c9d --- /dev/null +++ b/module/Rest/test/Action/ListShortcodesActionTest.php @@ -0,0 +1,66 @@ +service = $this->prophesize(ShortUrlService::class); + $this->action = new ListShortcodesAction($this->service->reveal(), Translator::factory([])); + } + + /** + * @test + */ + public function properListReturnsSuccessResponse() + { + $page = 3; + $this->service->listShortUrls($page)->willReturn(new Paginator(new ArrayAdapter())) + ->shouldBeCalledTimes(1); + + $response = $this->action->__invoke( + ServerRequestFactory::fromGlobals()->withQueryParams([ + 'page' => $page, + ]), + new Response() + ); + $this->assertEquals(200, $response->getStatusCode()); + } + + /** + * @test + */ + public function anExceptionsReturnsErrorResponse() + { + $page = 3; + $this->service->listShortUrls($page)->willThrow(\Exception::class) + ->shouldBeCalledTimes(1); + + $response = $this->action->__invoke( + ServerRequestFactory::fromGlobals()->withQueryParams([ + 'page' => $page, + ]), + new Response() + ); + $this->assertEquals(500, $response->getStatusCode()); + } +}