Completed
Pull Request — master (#554)
by Alejandro
05:47
created

badRequestIsReturnedWhenTryingToDeleteUrlWithTooManyVisits()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioApiTest\Shlink\Rest\Action;
6
7
use Shlinkio\Shlink\Rest\Util\RestUtils;
8
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
9
10
class DeleteShortUrlActionTest extends ApiTestCase
11
{
12
    /** @test */
13
    public function notFoundErrorIsReturnWhenDeletingInvalidUrl(): void
14
    {
15
        $resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid');
16
        ['error' => $error] = $this->getJsonResponsePayload($resp);
17
18
        $this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
19
        $this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $error);
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...INVALID_SHORTCODE_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
        $this->assertEquals(/** @scrutinizer ignore-deprecated */ RestUtils::INVALID_SHORTCODE_ERROR, $error);
Loading history...
20
    }
21
22
    /** @test */
23
    public function badRequestIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void
24
    {
25
        // Generate visits first
26
        for ($i = 0; $i < 20; $i++) {
27
            $this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
28
        }
29
30
        $resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
31
        ['error' => $error] = $this->getJsonResponsePayload($resp);
32
33
        $this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
34
        $this->assertEquals(RestUtils::INVALID_SHORTCODE_DELETION_ERROR, $error);
35
    }
36
}
37