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

59 lines
1.9 KiB
PHP
Raw Normal View History

2018-03-26 21:17:33 +03:00
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Action;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Response\PixelResponse;
use Shlinkio\Shlink\Core\Action\PixelAction;
use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
2018-03-26 21:17:33 +03:00
use Shlinkio\Shlink\Core\Options\AppOptions;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
class PixelActionTest extends TestCase
{
/** @var RedirectAction */
private $action;
/** @var ObjectProphecy */
private $urlShortener;
/** @var ObjectProphecy */
private $visitTracker;
2018-03-26 21:17:33 +03:00
public function setUp()
{
$this->urlShortener = $this->prophesize(UrlShortener::class);
$this->visitTracker = $this->prophesize(VisitsTracker::class);
$this->action = new PixelAction(
$this->urlShortener->reveal(),
$this->visitTracker->reveal(),
new AppOptions()
);
}
/**
* @test
*/
public function imageIsReturned()
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(
new ShortUrl('http://domain.com/foo/bar')
2018-11-11 15:18:21 +03:00
)->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
2018-03-26 21:17:33 +03:00
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertInstanceOf(PixelResponse::class, $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('image/gif', $response->getHeaderLine('content-type'));
}
}