From 82f4e22f691439a083cb0115af798f53bd153560 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 9 Feb 2021 23:41:51 +0100 Subject: [PATCH] Created OrphanVisitsActionTest --- .../Action/Visit/OrphanVisitsActionTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 module/Rest/test/Action/Visit/OrphanVisitsActionTest.php diff --git a/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php b/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php new file mode 100644 index 00000000..36273d09 --- /dev/null +++ b/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php @@ -0,0 +1,58 @@ +visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class); + $this->orphanVisitTransformer = $this->prophesize(DataTransformerInterface::class); + + $this->action = new OrphanVisitsAction($this->visitsHelper->reveal(), $this->orphanVisitTransformer->reveal()); + } + + /** @test */ + public function requestIsHandled(): void + { + $visitor = Visitor::emptyInstance(); + $visits = [Visit::forInvalidShortUrl($visitor), Visit::forRegularNotFound($visitor)]; + $orphanVisits = $this->visitsHelper->orphanVisits(Argument::type(VisitsParams::class))->willReturn( + new Paginator(new ArrayAdapter($visits)), + ); + $transform = $this->orphanVisitTransformer->transform(Argument::type(Visit::class))->willReturn([]); + + $response = $this->action->handle(ServerRequestFactory::fromGlobals()); + + self::assertInstanceOf(JsonResponse::class, $response); + self::assertEquals(200, $response->getStatusCode()); + $orphanVisits->shouldHaveBeenCalledOnce(); + $transform->shouldHaveBeenCalledTimes(count($visits)); + } +}