ResolveShortUrlActionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
dl 0
loc 25
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A correctShortCodeReturnsSuccess() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
6
7
use Laminas\Diactoros\ServerRequest;
8
use PHPUnit\Framework\TestCase;
9
use Prophecy\PhpUnit\ProphecyTrait;
10
use Prophecy\Prophecy\ObjectProphecy;
11
use Shlinkio\Shlink\Core\Entity\ShortUrl;
12
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
13
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
14
use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction;
15
16
use function strpos;
17
18
class ResolveShortUrlActionTest extends TestCase
19
{
20
    use ProphecyTrait;
21
22
    private ResolveShortUrlAction $action;
23
    private ObjectProphecy $urlResolver;
24
25
    public function setUp(): void
26
    {
27
        $this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class);
28
        $this->action = new ResolveShortUrlAction($this->urlResolver->reveal(), []);
29
    }
30
31
    /** @test */
32
    public function correctShortCodeReturnsSuccess(): void
33
    {
34
        $shortCode = 'abc123';
35
        $this->urlResolver->resolveShortUrl(new ShortUrlIdentifier($shortCode))->willReturn(
36
            new ShortUrl('http://domain.com/foo/bar'),
37
        )->shouldBeCalledOnce();
38
39
        $request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
40
        $response = $this->action->handle($request);
41
        self::assertEquals(200, $response->getStatusCode());
42
        self::assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0);
43
    }
44
}
45