mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Migrated NonOrphanVisitsActionTest to use PHPUnit mocks
This commit is contained in:
parent
e980a8d121
commit
bb444a02fe
1 changed files with 8 additions and 12 deletions
|
@ -7,10 +7,8 @@ namespace ShlinkioTest\Shlink\Rest\Action\Visit;
|
||||||
use Laminas\Diactoros\Response\JsonResponse;
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
use Laminas\Diactoros\ServerRequestFactory;
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
use Pagerfanta\Adapter\ArrayAdapter;
|
use Pagerfanta\Adapter\ArrayAdapter;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||||
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams;
|
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams;
|
||||||
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
||||||
|
@ -19,24 +17,23 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
class NonOrphanVisitsActionTest extends TestCase
|
class NonOrphanVisitsActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private NonOrphanVisitsAction $action;
|
private NonOrphanVisitsAction $action;
|
||||||
private ObjectProphecy $visitsHelper;
|
private MockObject $visitsHelper;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class);
|
$this->visitsHelper = $this->createMock(VisitsStatsHelperInterface::class);
|
||||||
$this->action = new NonOrphanVisitsAction($this->visitsHelper->reveal());
|
$this->action = new NonOrphanVisitsAction($this->visitsHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function requestIsHandled(): void
|
public function requestIsHandled(): void
|
||||||
{
|
{
|
||||||
$apiKey = ApiKey::create();
|
$apiKey = ApiKey::create();
|
||||||
$getVisits = $this->visitsHelper->nonOrphanVisits(Argument::type(VisitsParams::class), $apiKey)->willReturn(
|
$this->visitsHelper->expects($this->once())->method('nonOrphanVisits')->with(
|
||||||
new Paginator(new ArrayAdapter([])),
|
$this->isInstanceOf(VisitsParams::class),
|
||||||
);
|
$apiKey,
|
||||||
|
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||||
|
|
||||||
/** @var JsonResponse $response */
|
/** @var JsonResponse $response */
|
||||||
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
|
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
|
||||||
|
@ -44,6 +41,5 @@ class NonOrphanVisitsActionTest extends TestCase
|
||||||
|
|
||||||
self::assertEquals(200, $response->getStatusCode());
|
self::assertEquals(200, $response->getStatusCode());
|
||||||
self::assertArrayHasKey('visits', $payload);
|
self::assertArrayHasKey('visits', $payload);
|
||||||
$getVisits->shouldHaveBeenCalledOnce();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue