mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created more unit tests
This commit is contained in:
39
module/Rest/test/Action/Visit/GlobalVisitsActionTest.php
Normal file
39
module/Rest/test/Action/Visit/GlobalVisitsActionTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
|
||||
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
|
||||
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\Visit\GlobalVisitsAction;
|
||||
|
||||
class GlobalVisitsActionTest extends TestCase
|
||||
{
|
||||
private GlobalVisitsAction $action;
|
||||
private ObjectProphecy $helper;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->helper = $this->prophesize(VisitsStatsHelperInterface::class);
|
||||
$this->action = new GlobalVisitsAction($this->helper->reveal());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function statsAreReturnedFromHelper(): void
|
||||
{
|
||||
$stats = new VisitsStats(5);
|
||||
$getStats = $this->helper->getVisitsStats()->willReturn($stats);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(ServerRequestFactory::fromGlobals());
|
||||
$payload = $resp->getPayload();
|
||||
|
||||
$this->assertEquals($payload, ['visits' => $stats]);
|
||||
$getStats->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user