Ensured uniqueness on imported short URLs short code

This commit is contained in:
Alejandro Celaya
2020-10-25 10:26:11 +01:00
parent 2256f6a9e7
commit b1a073b1ab
3 changed files with 74 additions and 10 deletions

View File

@@ -4,12 +4,14 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Entity;
use Cake\Chronos\Chronos;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Validation\ShortUrlMetaInputFilter;
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
use function Functional\map;
use function range;
use function strlen;
@@ -44,10 +46,12 @@ class ShortUrlTest extends TestCase
];
}
/** @test */
public function regenerateShortCodeProperlyChangesTheValueOnValidShortUrls(): void
/**
* @test
* @dataProvider provideValidShortUrls
*/
public function regenerateShortCodeProperlyChangesTheValueOnValidShortUrls(ShortUrl $shortUrl): void
{
$shortUrl = new ShortUrl('');
$firstShortCode = $shortUrl->getShortCode();
$shortUrl->regenerateShortCode();
@@ -56,6 +60,14 @@ class ShortUrlTest extends TestCase
self::assertNotEquals($firstShortCode, $secondShortCode);
}
public function provideValidShortUrls(): iterable
{
yield 'no custom slug' => [new ShortUrl('')];
yield 'imported with custom slug' => [
ShortUrl::fromImport(new ImportedShlinkUrl('', '', [], Chronos::now(), null, 'custom-slug'), true),
];
}
/**
* @test
* @dataProvider provideLengths