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

UpdateTagActionTest::provideInvalidBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioApiTest\Shlink\Rest\Action;
6
7
use GuzzleHttp\RequestOptions;
8
use Shlinkio\Shlink\Rest\Util\RestUtils;
9
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
10
11
class UpdateTagActionTest extends ApiTestCase
12
{
13
    /**
14
     * @test
15
     * @dataProvider provideInvalidBody
16
     */
17
    public function notProvidingTagsReturnsBadRequest(array $body): void
18
    {
19
        $resp = $this->callApiWithKey(self::METHOD_PUT, '/tags', [RequestOptions::JSON => $body]);
20
        ['error' => $error] = $this->getJsonResponsePayload($resp);
21
22
        $this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
23
        $this->assertEquals(RestUtils::INVALID_ARGUMENT_ERROR, $error);
24
    }
25
26
    public function provideInvalidBody(): iterable
27
    {
28
        yield [[]];
29
        yield [['oldName' => 'foo']];
30
        yield [['newName' => 'foo']];
31
    }
32
33
    /** @test */
34
    public function tryingToRenameInvalidTagReturnsNotFound(): void
35
    {
36
        $resp = $this->callApiWithKey(self::METHOD_PUT, '/tags', [RequestOptions::JSON => [
37
            'oldName' => 'invalid_tag',
38
            'newName' => 'foo',
39
        ]]);
40
        ['error' => $error] = $this->getJsonResponsePayload($resp);
41
42
        $this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
43
        $this->assertEquals(RestUtils::NOT_FOUND_ERROR, $error);
44
    }
45
}
46