Improved tag conflict docs and tests

This commit is contained in:
Alejandro Celaya 2019-12-06 23:40:27 +01:00
parent a070a68a57
commit e5f262869c
2 changed files with 39 additions and 0 deletions

View file

@ -229,6 +229,16 @@
}
}
},
"409": {
"description": "The name provided in newName param is already in use for another tag.",
"content": {
"application/problem+json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
}
},
"500": {
"description": "Unexpected error.",
"content": {

View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Exception;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\TagConflictException;
use function sprintf;
class TagConflictExceptionTest extends TestCase
{
/** @test */
public function properlyCreatesExceptionFromNotFoundTag(): void
{
$oldName = 'foo';
$newName = 'bar';
$expectedMessage = sprintf('You cannot rename tag %s to %s, because it already exists', $oldName, $newName);
$e = TagConflictException::fromExistingTag($oldName, $newName);
$this->assertEquals($expectedMessage, $e->getMessage());
$this->assertEquals($expectedMessage, $e->getDetail());
$this->assertEquals('Tag conflict', $e->getTitle());
$this->assertEquals('TAG_CONFLICT', $e->getType());
$this->assertEquals(['oldName' => $oldName, 'newName' => $newName], $e->getAdditionalData());
$this->assertEquals(409, $e->getStatus());
}
}