From 3923bf06046d7c9ce79d0857e0053300ad0d0aef Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 30 Jul 2016 14:30:30 +0200 Subject: [PATCH] Created GetVisitsCommandTest --- .../CLI/test/Command/GetVisitsCommandTest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 module/CLI/test/Command/GetVisitsCommandTest.php diff --git a/module/CLI/test/Command/GetVisitsCommandTest.php b/module/CLI/test/Command/GetVisitsCommandTest.php new file mode 100644 index 00000000..4294823b --- /dev/null +++ b/module/CLI/test/Command/GetVisitsCommandTest.php @@ -0,0 +1,91 @@ +visitsTracker = $this->prophesize(VisitsTrackerInterface::class); + $command = new GetVisitsCommand($this->visitsTracker->reveal(), Translator::factory([])); + $app = new Application(); + $app->add($command); + $this->commandTester = new CommandTester($command); + } + + /** + * @test + */ + public function noDateFlagsTriesToListWithoutDateRange() + { + $shortCode = 'abc123'; + $this->visitsTracker->info($shortCode, new DateRange(null, null))->willReturn([]) + ->shouldBeCalledTimes(1); + + $this->commandTester->execute([ + 'command' => 'shortcode:visits', + 'shortCode' => $shortCode, + ]); + } + + /** + * @test + */ + public function providingDateFlagsTheListGetsFiltered() + { + $shortCode = 'abc123'; + $startDate = '2016-01-01'; + $endDate = '2016-02-01'; + $this->visitsTracker->info($shortCode, new DateRange(new \DateTime($startDate), new \DateTime($endDate))) + ->willReturn([]) + ->shouldBeCalledTimes(1); + + $this->commandTester->execute([ + 'command' => 'shortcode:visits', + 'shortCode' => $shortCode, + '--startDate' => $startDate, + '--endDate' => $endDate, + ]); + } + + /** + * @test + */ + public function outputIsProperlyGenerated() + { + $shortCode = 'abc123'; + $this->visitsTracker->info($shortCode, Argument::any())->willReturn([ + (new Visit())->setReferer('foo') + ->setRemoteAddr('1.2.3.4') + ->setUserAgent('bar'), + ])->shouldBeCalledTimes(1); + + $this->commandTester->execute([ + 'command' => 'shortcode:visits', + 'shortCode' => $shortCode, + ]); + $output = $this->commandTester->getDisplay(); + $this->assertTrue(strpos($output, 'foo') > 0); + $this->assertTrue(strpos($output, '1.2.3.4') > 0); + $this->assertTrue(strpos($output, 'bar') > 0); + } +}