mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created GetVisitsCommandTest
This commit is contained in:
parent
bb8404040a
commit
3923bf0604
91
module/CLI/test/Command/GetVisitsCommandTest.php
Normal file
91
module/CLI/test/Command/GetVisitsCommandTest.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
namespace ShlinkioTest\Shlink\CLI\Command;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase as TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
|
use Shlinkio\Shlink\CLI\Command\GetVisitsCommand;
|
||||||
|
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||||
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
|
use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use Zend\I18n\Translator\Translator;
|
||||||
|
|
||||||
|
class GetVisitsCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CommandTester
|
||||||
|
*/
|
||||||
|
protected $commandTester;
|
||||||
|
/**
|
||||||
|
* @var ObjectProphecy
|
||||||
|
*/
|
||||||
|
protected $visitsTracker;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user