shlink/module/Core/test/Action/PixelActionTest.php

54 lines
1.9 KiB
PHP
Raw Normal View History

2018-03-26 21:17:33 +03:00
<?php
2019-10-05 18:26:10 +03:00
2018-03-26 21:17:33 +03:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Action;
2020-01-01 23:11:53 +03:00
use Laminas\Diactoros\ServerRequest;
2018-03-26 21:17:33 +03:00
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
2020-11-02 13:50:19 +03:00
use Prophecy\PhpUnit\ProphecyTrait;
2018-03-26 21:17:33 +03:00
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface;
2018-03-26 21:17:33 +03:00
use Shlinkio\Shlink\Common\Response\PixelResponse;
use Shlinkio\Shlink\Core\Action\PixelAction;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
2018-03-26 21:17:33 +03:00
class PixelActionTest extends TestCase
{
2020-11-02 13:50:19 +03:00
use ProphecyTrait;
2019-12-30 00:27:00 +03:00
private PixelAction $action;
private ObjectProphecy $urlResolver;
private ObjectProphecy $requestTracker;
2018-03-26 21:17:33 +03:00
2019-02-16 12:53:45 +03:00
public function setUp(): void
2018-03-26 21:17:33 +03:00
{
$this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class);
$this->requestTracker = $this->prophesize(RequestTrackerInterface::class);
2018-03-26 21:17:33 +03:00
$this->action = new PixelAction($this->urlResolver->reveal(), $this->requestTracker->reveal());
2018-03-26 21:17:33 +03:00
}
2019-02-17 22:28:34 +03:00
/** @test */
public function imageIsReturned(): void
2018-03-26 21:17:33 +03:00
{
$shortCode = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'))
->shouldBeCalledOnce();
$this->requestTracker->trackIfApplicable(Argument::cetera())->shouldBeCalledOnce();
2018-03-26 21:17:33 +03:00
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, $this->prophesize(RequestHandlerInterface::class)->reveal());
2018-03-26 21:17:33 +03:00
2020-10-04 01:35:14 +03:00
self::assertInstanceOf(PixelResponse::class, $response);
self::assertEquals(200, $response->getStatusCode());
self::assertEquals('image/gif', $response->getHeaderLine('content-type'));
2018-03-26 21:17:33 +03:00
}
}