From 210b08b61f55257d38b31cabcdc8e2bbc0f582d6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 26 Mar 2018 20:17:33 +0200 Subject: [PATCH] Created PixelActionTest --- module/Core/test/Action/PixelActionTest.php | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 module/Core/test/Action/PixelActionTest.php diff --git a/module/Core/test/Action/PixelActionTest.php b/module/Core/test/Action/PixelActionTest.php new file mode 100644 index 00000000..1a7f7296 --- /dev/null +++ b/module/Core/test/Action/PixelActionTest.php @@ -0,0 +1,63 @@ +urlShortener = $this->prophesize(UrlShortener::class); + $this->visitTracker = $this->prophesize(VisitsTracker::class); + + $this->action = new PixelAction( + $this->urlShortener->reveal(), + $this->visitTracker->reveal(), + new AppOptions() + ); + } + + /** + * @test + */ + public function imageIsReturned() + { + $shortCode = 'abc123'; + $this->urlShortener->shortCodeToUrl($shortCode)->willReturn('http://domain.com/foo/bar') + ->shouldBeCalledTimes(1); + $this->visitTracker->track(Argument::cetera())->willReturn(null) + ->shouldBeCalledTimes(1); + + $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal()); + + $this->assertInstanceOf(PixelResponse::class, $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('image/gif', $response->getHeaderLine('content-type')); + } +}