mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Added errorhandling for individual imported URLs, so that one failing doe snot make the whole process fail
This commit is contained in:
@@ -11,6 +11,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use RuntimeException;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Importer\ImportedLinksProcessor;
|
||||
@@ -81,6 +82,37 @@ class ImportedLinksProcessorTest extends TestCase
|
||||
$this->io->text(Argument::type('string'))->shouldHaveBeenCalledTimes($expectedCalls);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function newUrlsWithErrorsAreSkipped(): void
|
||||
{
|
||||
$urls = [
|
||||
new ImportedShlinkUrl('', 'foo', [], Chronos::now(), null, 'foo', null),
|
||||
new ImportedShlinkUrl('', 'bar', [], Chronos::now(), null, 'bar', 'foo'),
|
||||
new ImportedShlinkUrl('', 'baz', [], Chronos::now(), null, 'baz', null),
|
||||
];
|
||||
|
||||
$importedUrlExists = $this->repo->findOneByImportedUrl(Argument::cetera())->willReturn(null);
|
||||
$ensureUniqueness = $this->shortCodeHelper->ensureShortCodeUniqueness(Argument::cetera())->willReturn(true);
|
||||
$persist = $this->em->persist(Argument::type(ShortUrl::class))->will(function (array $args): void {
|
||||
/** @var ShortUrl $shortUrl */
|
||||
[$shortUrl] = $args;
|
||||
|
||||
if ($shortUrl->getShortCode() === 'baz') {
|
||||
throw new RuntimeException('Whatever error');
|
||||
}
|
||||
});
|
||||
|
||||
$this->processor->process($this->io->reveal(), $urls, $this->buildParams());
|
||||
|
||||
$importedUrlExists->shouldHaveBeenCalledTimes(3);
|
||||
$ensureUniqueness->shouldHaveBeenCalledTimes(3);
|
||||
$persist->shouldHaveBeenCalledTimes(3);
|
||||
$this->io->text(Argument::containingString('<info>Imported</info>'))->shouldHaveBeenCalledTimes(2);
|
||||
$this->io->text(
|
||||
Argument::containingString('<comment>Skipped</comment>. Reason: Whatever error'),
|
||||
)->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function alreadyImportedUrlsAreSkipped(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user