Applied API role specs to short URL creation

This commit is contained in:
Alejandro Celaya
2021-01-04 20:15:42 +01:00
parent 19834f6715
commit 4b67d41362
15 changed files with 314 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ use Shlinkio\Shlink\Core\Domain\DomainService;
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
use Shlinkio\Shlink\Core\Entity\Domain;
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
class DomainServiceTest extends TestCase
{
@@ -54,4 +55,27 @@ class DomainServiceTest extends TestCase
[$default, new DomainItem('foo.com', false), new DomainItem('bar.com', false)],
];
}
/** @test */
public function getDomainThrowsExceptionWhenDomainIsNotFound(): void
{
$find = $this->em->find(Domain::class, '123')->willReturn(null);
$this->expectException(DomainNotFoundException::class);
$find->shouldBeCalledOnce();
$this->domainService->getDomain('123');
}
/** @test */
public function getDomainReturnsEntityWhenFound(): void
{
$domain = new Domain('');
$find = $this->em->find(Domain::class, '123')->willReturn($domain);
$result = $this->domainService->getDomain('123');
self::assertSame($domain, $result);
$find->shouldHaveBeenCalledOnce();
}
}