Updated to readonly public props on as many models as possible

This commit is contained in:
Alejandro Celaya
2022-04-23 14:00:47 +02:00
parent e79391907a
commit bca3e62ced
74 changed files with 249 additions and 494 deletions

View File

@@ -37,9 +37,10 @@ class PixelActionTest extends TestCase
public function imageIsReturned(): void
{
$shortCode = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode, ''))->willReturn(
ShortUrl::withLongUrl('http://domain.com/foo/bar'),
)->shouldBeCalledOnce();
$this->urlResolver->resolveEnabledShortUrl(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'))
->shouldBeCalledOnce();
$this->requestTracker->trackIfApplicable(Argument::cetera())->shouldBeCalledOnce();
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);

View File

@@ -59,7 +59,7 @@ class QrCodeActionTest extends TestCase
public function aNotFoundShortCodeWillDelegateIntoNextMiddleware(): void
{
$shortCode = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode, ''))
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''))
->willThrow(ShortUrlNotFoundException::class)
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
@@ -74,7 +74,7 @@ class QrCodeActionTest extends TestCase
public function aCorrectRequestReturnsTheQrCodeResponse(): void
{
$shortCode = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode, ''))
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''))
->willReturn(ShortUrl::createEmpty())
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
@@ -100,7 +100,7 @@ class QrCodeActionTest extends TestCase
): void {
$this->options->setFromArray(['format' => $defaultFormat]);
$code = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($code, ''))->willReturn(
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($code, ''))->willReturn(
ShortUrl::createEmpty(),
);
$delegate = $this->prophesize(RequestHandlerInterface::class);
@@ -134,7 +134,7 @@ class QrCodeActionTest extends TestCase
): void {
$this->options->setFromArray($defaults);
$code = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($code, ''))->willReturn(
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($code, ''))->willReturn(
ShortUrl::createEmpty(),
);
$delegate = $this->prophesize(RequestHandlerInterface::class);
@@ -214,7 +214,7 @@ class QrCodeActionTest extends TestCase
->withQueryParams(['size' => 250, 'roundBlockSize' => $roundBlockSize])
->withAttribute('shortCode', $code);
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($code, ''))->willReturn(
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($code, ''))->willReturn(
ShortUrl::withLongUrl('https://shlink.io'),
);
$delegate = $this->prophesize(RequestHandlerInterface::class);

View File

@@ -54,7 +54,7 @@ class RedirectActionTest extends TestCase
$shortCode = 'abc123';
$shortUrl = ShortUrl::withLongUrl(self::LONG_URL);
$shortCodeToUrl = $this->urlResolver->resolveEnabledShortUrl(
new ShortUrlIdentifier($shortCode, ''),
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
)->willReturn($shortUrl);
$track = $this->requestTracker->trackIfApplicable(Argument::cetera())->will(function (): void {
});
@@ -74,7 +74,7 @@ class RedirectActionTest extends TestCase
public function nextMiddlewareIsInvokedIfLongUrlIsNotFound(): void
{
$shortCode = 'abc123';
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode, ''))
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''))
->willThrow(ShortUrlNotFoundException::class)
->shouldBeCalledOnce();
$this->requestTracker->trackIfApplicable(Argument::cetera())->shouldNotBeCalled();

View File

@@ -24,7 +24,7 @@ class ShortUrlNotFoundExceptionTest extends TestCase
$expectedAdditional['domain'] = $domain;
}
$e = ShortUrlNotFoundException::fromNotFound(new ShortUrlIdentifier($shortCode, $domain));
$e = ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain));
self::assertEquals($expectedMessage, $e->getMessage());
self::assertEquals($expectedMessage, $e->getDetail());

View File

@@ -24,9 +24,9 @@ class VisitorTest extends TestCase
$visitor = new Visitor(...$params);
['userAgent' => $userAgent, 'referer' => $referer, 'remoteAddress' => $remoteAddress] = $expected;
self::assertEquals($userAgent, $visitor->getUserAgent());
self::assertEquals($referer, $visitor->getReferer());
self::assertEquals($remoteAddress, $visitor->getRemoteAddress());
self::assertEquals($userAgent, $visitor->userAgent);
self::assertEquals($referer, $visitor->referer);
self::assertEquals($remoteAddress, $visitor->remoteAddress);
}
public function provideParams(): iterable
@@ -89,11 +89,11 @@ class VisitorTest extends TestCase
]));
self::assertNotSame($visitor, $normalizedVisitor);
self::assertEmpty($normalizedVisitor->getUserAgent());
self::assertNotEmpty($visitor->getUserAgent());
self::assertEmpty($normalizedVisitor->getReferer());
self::assertNotEmpty($visitor->getReferer());
self::assertNull($normalizedVisitor->getRemoteAddress());
self::assertNotNull($visitor->getRemoteAddress());
self::assertEmpty($normalizedVisitor->userAgent);
self::assertNotEmpty($visitor->userAgent);
self::assertEmpty($normalizedVisitor->referer);
self::assertNotEmpty($visitor->referer);
self::assertNull($normalizedVisitor->remoteAddress);
self::assertNotNull($visitor->remoteAddress);
}
}

View File

@@ -55,7 +55,7 @@ class DeleteShortUrlServiceTest extends TestCase
$this->shortCode,
));
$service->deleteByShortCode(new ShortUrlIdentifier($this->shortCode));
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode));
}
/** @test */
@@ -66,7 +66,7 @@ class DeleteShortUrlServiceTest extends TestCase
$remove = $this->em->remove(Argument::type(ShortUrl::class))->willReturn(null);
$flush = $this->em->flush()->willReturn(null);
$service->deleteByShortCode(new ShortUrlIdentifier($this->shortCode), true);
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode), true);
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();
@@ -80,7 +80,7 @@ class DeleteShortUrlServiceTest extends TestCase
$remove = $this->em->remove(Argument::type(ShortUrl::class))->willReturn(null);
$flush = $this->em->flush()->willReturn(null);
$service->deleteByShortCode(new ShortUrlIdentifier($this->shortCode));
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode));
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();
@@ -94,7 +94,7 @@ class DeleteShortUrlServiceTest extends TestCase
$remove = $this->em->remove(Argument::type(ShortUrl::class))->willReturn(null);
$flush = $this->em->flush()->willReturn(null);
$service->deleteByShortCode(new ShortUrlIdentifier($this->shortCode));
$service->deleteByShortCode(ShortUrlIdentifier::fromShortCodeAndDomain($this->shortCode));
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();

View File

@@ -91,7 +91,7 @@ class ShortUrlResolverTest extends TestCase
)->willReturn($shortUrl);
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$result = $this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode));
$result = $this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode));
self::assertSame($shortUrl, $result);
$findOneByShortCode->shouldHaveBeenCalledOnce();
@@ -116,7 +116,7 @@ class ShortUrlResolverTest extends TestCase
$findOneByShortCode->shouldBeCalledOnce();
$getRepo->shouldBeCalledOnce();
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode));
$this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode));
}
public function provideDisabledShortUrls(): iterable

View File

@@ -88,7 +88,7 @@ class ShortUrlServiceTest extends TestCase
$shortUrl = ShortUrl::withLongUrl($originalLongUrl);
$findShortUrl = $this->urlResolver->resolveShortUrl(
new ShortUrlIdentifier('abc123'),
ShortUrlIdentifier::fromShortCodeAndDomain('abc123'),
$apiKey,
)->willReturn($shortUrl);
$flush = $this->em->flush()->willReturn(null);
@@ -97,7 +97,11 @@ class ShortUrlServiceTest extends TestCase
$shortUrlEdit,
);
$result = $this->service->updateShortUrl(new ShortUrlIdentifier('abc123'), $shortUrlEdit, $apiKey);
$result = $this->service->updateShortUrl(
ShortUrlIdentifier::fromShortCodeAndDomain('abc123'),
$shortUrlEdit,
$apiKey,
);
self::assertSame($shortUrl, $result);
self::assertEquals($shortUrlEdit->validSince(), $shortUrl->getValidSince());

View File

@@ -39,7 +39,7 @@ class NonOrphanVisitsPaginatorAdapterTest extends TestCase
{
$expectedCount = 5;
$repoCount = $this->repo->countNonOrphanVisits(
new VisitsCountFiltering($this->params->getDateRange(), $this->params->excludeBots(), $this->apiKey),
new VisitsCountFiltering($this->params->dateRange, $this->params->excludeBots, $this->apiKey),
)->willReturn($expectedCount);
$result = $this->adapter->getNbResults();
@@ -57,8 +57,8 @@ class NonOrphanVisitsPaginatorAdapterTest extends TestCase
$visitor = Visitor::emptyInstance();
$list = [Visit::forRegularNotFound($visitor), Visit::forInvalidShortUrl($visitor)];
$repoFind = $this->repo->findNonOrphanVisits(new VisitsListFiltering(
$this->params->getDateRange(),
$this->params->excludeBots(),
$this->params->dateRange,
$this->params->excludeBots,
$this->apiKey,
$limit,
$offset,

View File

@@ -35,7 +35,7 @@ class OrphanVisitsPaginatorAdapterTest extends TestCase
{
$expectedCount = 5;
$repoCount = $this->repo->countOrphanVisits(
new VisitsCountFiltering($this->params->getDateRange()),
new VisitsCountFiltering($this->params->dateRange),
)->willReturn($expectedCount);
$result = $this->adapter->getNbResults();
@@ -53,7 +53,7 @@ class OrphanVisitsPaginatorAdapterTest extends TestCase
$visitor = Visitor::emptyInstance();
$list = [Visit::forRegularNotFound($visitor), Visit::forInvalidShortUrl($visitor)];
$repoFind = $this->repo->findOrphanVisits(
new VisitsListFiltering($this->params->getDateRange(), $this->params->excludeBots(), null, $limit, $offset),
new VisitsListFiltering($this->params->dateRange, $this->params->excludeBots, null, $limit, $offset),
)->willReturn($list);
$result = $this->adapter->getSlice($offset, $limit);

View File

@@ -68,7 +68,7 @@ class ShortUrlVisitsPaginatorAdapterTest extends TestCase
{
return new ShortUrlVisitsPaginatorAdapter(
$this->repo->reveal(),
new ShortUrlIdentifier(''),
ShortUrlIdentifier::fromShortCodeAndDomain(''),
VisitsParams::fromRawData([]),
$apiKey,
);