mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created chainIpLocationResolver
This commit is contained in:
@@ -51,8 +51,8 @@ class PixelActionTest extends TestCase
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(
|
||||
new ShortUrl('http://domain.com/foo/bar')
|
||||
)->shouldBeCalledTimes(1);
|
||||
$this->visitTracker->track(Argument::cetera())->shouldBeCalledTimes(1);
|
||||
)->shouldBeCalledOnce();
|
||||
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
|
||||
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
|
||||
|
||||
@@ -50,9 +50,9 @@ class PreviewActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
$delegate->handle(Argument::cetera())->shouldBeCalledTimes(1)
|
||||
$delegate->handle(Argument::cetera())->shouldBeCalledOnce()
|
||||
->willReturn(new Response());
|
||||
|
||||
$this->action->process(
|
||||
@@ -70,8 +70,8 @@ class PreviewActionTest extends TestCase
|
||||
$url = 'foobar.com';
|
||||
$shortUrl = new ShortUrl($url);
|
||||
$path = __FILE__;
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)->shouldBeCalledTimes(1);
|
||||
$this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledTimes(1);
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)->shouldBeCalledOnce();
|
||||
$this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce();
|
||||
|
||||
$resp = $this->action->process(
|
||||
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
|
||||
@@ -89,7 +89,7 @@ class PreviewActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
/** @var MethodProphecy $process */
|
||||
$process = $delegate->handle(Argument::any())->willReturn(new Response());
|
||||
@@ -99,6 +99,6 @@ class PreviewActionTest extends TestCase
|
||||
$delegate->reveal()
|
||||
);
|
||||
|
||||
$process->shouldHaveBeenCalledTimes(1);
|
||||
$process->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class QrCodeActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
$process = $delegate->handle(Argument::any())->willReturn(new Response());
|
||||
|
||||
@@ -55,7 +55,7 @@ class QrCodeActionTest extends TestCase
|
||||
$delegate->reveal()
|
||||
);
|
||||
|
||||
$process->shouldHaveBeenCalledTimes(1);
|
||||
$process->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class QrCodeActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
/** @var MethodProphecy $process */
|
||||
$process = $delegate->handle(Argument::any())->willReturn(new Response());
|
||||
@@ -75,7 +75,7 @@ class QrCodeActionTest extends TestCase
|
||||
$delegate->reveal()
|
||||
);
|
||||
|
||||
$process->shouldHaveBeenCalledTimes(1);
|
||||
$process->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ class QrCodeActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(new ShortUrl(''))
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
|
||||
$resp = $this->action->process(
|
||||
|
||||
@@ -59,8 +59,8 @@ class RedirectActionTest extends TestCase
|
||||
$expectedUrl = 'http://domain.com/foo/bar';
|
||||
$shortUrl = new ShortUrl($expectedUrl);
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)
|
||||
->shouldBeCalledTimes(1);
|
||||
$this->visitTracker->track(Argument::cetera())->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
|
||||
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
|
||||
@@ -78,7 +78,7 @@ class RedirectActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$this->visitTracker->track(Argument::cetera())->shouldNotBeCalled();
|
||||
|
||||
$handler = $this->prophesize(RequestHandlerInterface::class);
|
||||
@@ -87,7 +87,7 @@ class RedirectActionTest extends TestCase
|
||||
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
|
||||
$this->action->process($request, $handler->reveal());
|
||||
|
||||
$handle->shouldHaveBeenCalledTimes(1);
|
||||
$handle->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class RedirectActionTest extends TestCase
|
||||
|
||||
$this->assertEquals(302, $resp->getStatusCode());
|
||||
$this->assertEquals('https://shlink.io', $resp->getHeaderLine('Location'));
|
||||
$shortCodeToUrl->shouldHaveBeenCalledTimes(1);
|
||||
$shortCodeToUrl->shouldHaveBeenCalledOnce();
|
||||
$handle->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class RedirectActionTest extends TestCase
|
||||
$expectedUrl = 'http://domain.com/foo/bar';
|
||||
$shortUrl = new ShortUrl($expectedUrl);
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$this->visitTracker->track(Argument::cetera())->shouldNotBeCalled();
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)
|
||||
|
||||
@@ -36,7 +36,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
|
||||
public function noCachedPathFallsBackToNextMiddleware()
|
||||
{
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
$delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledTimes(1);
|
||||
$delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce();
|
||||
|
||||
$this->middleware->process(ServerRequestFactory::fromGlobals()->withUri(
|
||||
new Uri('/foo/bar')
|
||||
|
||||
@@ -70,8 +70,8 @@ class DeleteShortUrlServiceTest extends TestCase
|
||||
|
||||
$service->deleteByShortCode('abc123', true);
|
||||
|
||||
$remove->shouldHaveBeenCalledTimes(1);
|
||||
$flush->shouldHaveBeenCalledTimes(1);
|
||||
$remove->shouldHaveBeenCalledOnce();
|
||||
$flush->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,8 +86,8 @@ class DeleteShortUrlServiceTest extends TestCase
|
||||
|
||||
$service->deleteByShortCode('abc123');
|
||||
|
||||
$remove->shouldHaveBeenCalledTimes(1);
|
||||
$flush->shouldHaveBeenCalledTimes(1);
|
||||
$remove->shouldHaveBeenCalledOnce();
|
||||
$flush->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,8 +102,8 @@ class DeleteShortUrlServiceTest extends TestCase
|
||||
|
||||
$service->deleteByShortCode('abc123');
|
||||
|
||||
$remove->shouldHaveBeenCalledTimes(1);
|
||||
$flush->shouldHaveBeenCalledTimes(1);
|
||||
$remove->shouldHaveBeenCalledOnce();
|
||||
$flush->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
private function createService(bool $checkVisitsThreshold = true, int $visitsThreshold = 5): DeleteShortUrlService
|
||||
|
||||
@@ -49,8 +49,8 @@ class ShortUrlServiceTest extends TestCase
|
||||
];
|
||||
|
||||
$repo = $this->prophesize(ShortUrlRepository::class);
|
||||
$repo->findList(Argument::cetera())->willReturn($list)->shouldBeCalledTimes(1);
|
||||
$repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledTimes(1);
|
||||
$repo->findList(Argument::cetera())->willReturn($list)->shouldBeCalledOnce();
|
||||
$repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledOnce();
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$list = $this->service->listShortUrls();
|
||||
@@ -65,7 +65,7 @@ class ShortUrlServiceTest extends TestCase
|
||||
$shortCode = 'abc123';
|
||||
$repo = $this->prophesize(ShortUrlRepository::class);
|
||||
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(null)
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$this->expectException(InvalidShortCodeException::class);
|
||||
@@ -78,16 +78,16 @@ class ShortUrlServiceTest extends TestCase
|
||||
public function providedTagsAreGetFromRepoAndSetToTheShortUrl()
|
||||
{
|
||||
$shortUrl = $this->prophesize(ShortUrl::class);
|
||||
$shortUrl->setTags(Argument::any())->shouldBeCalledTimes(1);
|
||||
$shortUrl->setTags(Argument::any())->shouldBeCalledOnce();
|
||||
$shortCode = 'abc123';
|
||||
$repo = $this->prophesize(ShortUrlRepository::class);
|
||||
$repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl->reveal())
|
||||
->shouldBeCalledTimes(1);
|
||||
->shouldBeCalledOnce();
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$tagRepo = $this->prophesize(EntityRepository::class);
|
||||
$tagRepo->findOneBy(['name' => 'foo'])->willReturn(new Tag('foo'))->shouldbeCalledTimes(1);
|
||||
$tagRepo->findOneBy(['name' => 'bar'])->willReturn(null)->shouldbeCalledTimes(1);
|
||||
$tagRepo->findOneBy(['name' => 'foo'])->willReturn(new Tag('foo'))->shouldBeCalledOnce();
|
||||
$tagRepo->findOneBy(['name' => 'bar'])->willReturn(null)->shouldBeCalledOnce();
|
||||
$this->em->getRepository(Tag::class)->willReturn($tagRepo->reveal());
|
||||
|
||||
$this->service->setTagsByShortCode($shortCode, ['foo', 'bar']);
|
||||
|
||||
@@ -98,8 +98,8 @@ class UrlShortenerTest extends TestCase
|
||||
$conn = $this->prophesize(Connection::class);
|
||||
$conn->isTransactionActive()->willReturn(true);
|
||||
$this->em->getConnection()->willReturn($conn->reveal());
|
||||
$this->em->rollback()->shouldBeCalledTimes(1);
|
||||
$this->em->close()->shouldBeCalledTimes(1);
|
||||
$this->em->rollback()->shouldBeCalledOnce();
|
||||
$this->em->close()->shouldBeCalledOnce();
|
||||
|
||||
$this->em->flush()->willThrow(new ORMException());
|
||||
$this->urlShortener->urlToShortCode(new Uri('http://foobar.com/12345/hello?foo=bar'));
|
||||
@@ -135,7 +135,7 @@ class UrlShortenerTest extends TestCase
|
||||
'custom-slug'
|
||||
);
|
||||
|
||||
$slugify->shouldHaveBeenCalledTimes(1);
|
||||
$slugify->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,8 +153,8 @@ class UrlShortenerTest extends TestCase
|
||||
/** @var MethodProphecy $getRepo */
|
||||
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
|
||||
|
||||
$slugify->shouldBeCalledTimes(1);
|
||||
$findBySlug->shouldBeCalledTimes(1);
|
||||
$slugify->shouldBeCalledOnce();
|
||||
$findBySlug->shouldBeCalledOnce();
|
||||
$getRepo->shouldBeCalled();
|
||||
$this->expectException(NonUniqueSlugException::class);
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ class VisitServiceTest extends TestCase
|
||||
public function saveVisitsPersistsProvidedVisit()
|
||||
{
|
||||
$visit = new Visit(new ShortUrl(''), Visitor::emptyInstance());
|
||||
$this->em->persist($visit)->shouldBeCalledTimes(1);
|
||||
$this->em->flush()->shouldBeCalledTimes(1);
|
||||
$this->em->persist($visit)->shouldBeCalledOnce();
|
||||
$this->em->flush()->shouldBeCalledOnce();
|
||||
$this->visitService->saveVisit($visit);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class VisitServiceTest extends TestCase
|
||||
public function getUnlocatedVisitsFallbacksToRepository()
|
||||
{
|
||||
$repo = $this->prophesize(VisitRepository::class);
|
||||
$repo->findUnlocatedVisits()->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
|
||||
$repo->findUnlocatedVisits()->shouldBeCalledOnce();
|
||||
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
|
||||
$this->visitService->getUnlocatedVisits();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ class VisitsTrackerTest extends TestCase
|
||||
$repo = $this->prophesize(EntityRepository::class);
|
||||
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl(''));
|
||||
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
|
||||
$this->em->persist(Argument::any())->shouldBeCalledTimes(1);
|
||||
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
|
||||
$this->em->persist(Argument::any())->shouldBeCalledOnce();
|
||||
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledOnce();
|
||||
|
||||
$this->visitsTracker->track($shortCode, Visitor::emptyInstance());
|
||||
}
|
||||
@@ -57,13 +57,13 @@ class VisitsTrackerTest extends TestCase
|
||||
$repo = $this->prophesize(EntityRepository::class);
|
||||
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl(''));
|
||||
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
|
||||
$this->em->persist(Argument::any())->will(function ($args) use ($test) {
|
||||
/** @var Visit $visit */
|
||||
$visit = $args[0];
|
||||
$test->assertEquals('4.3.2.0', $visit->getRemoteAddr());
|
||||
})->shouldBeCalledTimes(1);
|
||||
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledTimes(1);
|
||||
})->shouldBeCalledOnce();
|
||||
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledOnce();
|
||||
|
||||
$this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1'));
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class VisitsTrackerTest extends TestCase
|
||||
$shortUrl = new ShortUrl('http://domain.com/foo/bar');
|
||||
$repo = $this->prophesize(EntityRepository::class);
|
||||
$repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl);
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
|
||||
|
||||
$list = [
|
||||
new Visit(new ShortUrl(''), Visitor::emptyInstance()),
|
||||
@@ -85,7 +85,7 @@ class VisitsTrackerTest extends TestCase
|
||||
];
|
||||
$repo2 = $this->prophesize(VisitRepository::class);
|
||||
$repo2->findVisitsByShortUrl($shortUrl, null)->willReturn($list);
|
||||
$this->em->getRepository(Visit::class)->willReturn($repo2->reveal())->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(Visit::class)->willReturn($repo2->reveal())->shouldBeCalledOnce();
|
||||
|
||||
$this->assertEquals($list, $this->visitsTracker->info($shortCode));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user