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