shlink/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2019-10-05 17:26:10 +02:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
2020-01-01 21:11:53 +01:00
use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\TestCase;
2020-11-02 11:50:19 +01:00
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction;
2020-11-08 11:28:27 +01:00
use Shlinkio\Shlink\Rest\Entity\ApiKey;
class SingleStepCreateShortUrlActionTest extends TestCase
{
2020-11-02 11:50:19 +01:00
use ProphecyTrait;
private SingleStepCreateShortUrlAction $action;
private ObjectProphecy $urlShortener;
private ObjectProphecy $apiKeyService;
2019-02-16 10:53:45 +01:00
public function setUp(): void
{
$this->urlShortener = $this->prophesize(UrlShortenerInterface::class);
$this->action = new SingleStepCreateShortUrlAction(
$this->urlShortener->reveal(),
[
'schema' => 'http',
'hostname' => 'foo.com',
2020-01-01 20:48:31 +01:00
],
);
}
2019-02-17 20:28:34 +01:00
/** @test */
public function properDataIsPassedWhenGeneratingShortCode(): void
{
2020-11-08 11:28:27 +01:00
$apiKey = new ApiKey();
$request = (new ServerRequest())->withQueryParams([
'longUrl' => 'http://foobar.com',
2021-01-21 19:26:19 +01:00
])->withAttribute(ApiKey::class, $apiKey);
$generateShortCode = $this->urlShortener->shorten(
ShortUrlMeta::fromRawData(['apiKey' => $apiKey, 'longUrl' => 'http://foobar.com']),
)->willReturn(ShortUrl::createEmpty());
$resp = $this->action->handle($request);
2020-10-04 00:35:14 +02:00
self::assertEquals(200, $resp->getStatusCode());
$generateShortCode->shouldHaveBeenCalled();
}
}