Make it impossible to create a short URL with an empty long URL

This commit is contained in:
Alejandro Celaya
2023-01-22 11:27:16 +01:00
parent 13e443880a
commit 39adef8ab8
25 changed files with 49 additions and 61 deletions

View File

@@ -29,8 +29,8 @@ class DeleteShortUrlServiceTest extends TestCase
protected function setUp(): void
{
$shortUrl = ShortUrl::createEmpty()->setVisits(new ArrayCollection(
map(range(0, 10), fn () => Visit::forValidShortUrl(ShortUrl::createEmpty(), Visitor::emptyInstance())),
$shortUrl = ShortUrl::createFake()->setVisits(new ArrayCollection(
map(range(0, 10), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())),
));
$this->shortCode = $shortUrl->getShortCode();

View File

@@ -42,7 +42,7 @@ class ShortUrlTest extends TestCase
'The short code cannot be regenerated on ShortUrls where a custom slug was provided.',
];
yield 'already persisted' => [
ShortUrl::createEmpty()->setId('1'),
ShortUrl::createFake()->setId('1'),
'The short code can be regenerated only on new ShortUrls which have not been persisted yet.',
];
}
@@ -64,7 +64,7 @@ class ShortUrlTest extends TestCase
public function provideValidShortUrls(): iterable
{
yield 'no custom slug' => [ShortUrl::createEmpty()];
yield 'no custom slug' => [ShortUrl::createFake()];
yield 'imported with custom slug' => [ShortUrl::fromImport(
new ImportedShlinkUrl(ImportSource::BITLY, 'longUrl', [], Chronos::now(), null, 'custom-slug', null),
true,

View File

@@ -36,10 +36,10 @@ class ShortUrlListServiceTest extends TestCase
public function listedUrlsAreReturnedFromEntityManager(?ApiKey $apiKey): void
{
$list = [
ShortUrl::createEmpty(),
ShortUrl::createEmpty(),
ShortUrl::createEmpty(),
ShortUrl::createEmpty(),
ShortUrl::createFake(),
ShortUrl::createFake(),
ShortUrl::createFake(),
ShortUrl::createFake(),
];
$this->repo->expects($this->once())->method('findList')->willReturn($list);

View File

@@ -38,7 +38,7 @@ class ShortUrlDataTransformerTest extends TestCase
$maxVisits = random_int(1, 1000);
$now = Chronos::now();
yield 'no metadata' => [ShortUrl::createEmpty(), [
yield 'no metadata' => [ShortUrl::createFake(), [
'validSince' => null,
'validUntil' => null,
'maxVisits' => null,