mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 05:38:06 +03:00
Removed all uinnecessary usages of equalsTo param constraint
This commit is contained in:
parent
1fbcea7a06
commit
6a2227efc5
43 changed files with 272 additions and 423 deletions
|
@ -36,11 +36,9 @@ class RoleResolverTest extends TestCase
|
|||
array $expectedRoles,
|
||||
int $expectedDomainCalls,
|
||||
): void {
|
||||
$this->domainService
|
||||
->expects($this->exactly($expectedDomainCalls))
|
||||
->method('getOrCreate')
|
||||
->with($this->equalTo('example.com'))
|
||||
->willReturn(Domain::withAuthority('example.com')->setId('1'));
|
||||
$this->domainService->expects($this->exactly($expectedDomainCalls))->method('getOrCreate')->with(
|
||||
'example.com',
|
||||
)->willReturn(Domain::withAuthority('example.com')->setId('1'));
|
||||
|
||||
$result = $this->resolver->determineRoles($input);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class DisableKeyCommandTest extends TestCase
|
|||
public function providedApiKeyIsDisabled(): void
|
||||
{
|
||||
$apiKey = 'abcd1234';
|
||||
$this->apiKeyService->expects($this->once())->method('disable')->with($this->equalTo($apiKey));
|
||||
$this->apiKeyService->expects($this->once())->method('disable')->with($apiKey);
|
||||
|
||||
$this->commandTester->execute([
|
||||
'apiKey' => $apiKey,
|
||||
|
@ -44,9 +44,9 @@ class DisableKeyCommandTest extends TestCase
|
|||
{
|
||||
$apiKey = 'abcd1234';
|
||||
$expectedMessage = 'API key "abcd1234" does not exist.';
|
||||
$this->apiKeyService->expects($this->once())->method('disable')->with(
|
||||
$this->equalTo($apiKey),
|
||||
)->willThrowException(new InvalidArgumentException($expectedMessage));
|
||||
$this->apiKeyService->expects($this->once())->method('disable')->with($apiKey)->willThrowException(
|
||||
new InvalidArgumentException($expectedMessage),
|
||||
);
|
||||
|
||||
$this->commandTester->execute([
|
||||
'apiKey' => $apiKey,
|
||||
|
|
|
@ -35,9 +35,7 @@ class ListKeysCommandTest extends TestCase
|
|||
*/
|
||||
public function returnsExpectedOutput(array $keys, bool $enabledOnly, string $expected): void
|
||||
{
|
||||
$this->apiKeyService->expects($this->once())->method('listKeys')->with(
|
||||
$this->equalTo($enabledOnly),
|
||||
)->willReturn($keys);
|
||||
$this->apiKeyService->expects($this->once())->method('listKeys')->with($enabledOnly)->willReturn($keys);
|
||||
|
||||
$this->commandTester->execute(['--enabled-only' => $enabledOnly]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
|
|
@ -87,7 +87,7 @@ class CreateDatabaseCommandTest extends TestCase
|
|||
$shlinkDatabase = 'shlink_database';
|
||||
$this->regularConn->expects($this->once())->method('getParams')->willReturn(['dbname' => $shlinkDatabase]);
|
||||
$this->schemaManager->expects($this->once())->method('listDatabases')->willReturn(['foo', 'bar']);
|
||||
$this->schemaManager->expects($this->once())->method('createDatabase')->with($this->equalTo($shlinkDatabase));
|
||||
$this->schemaManager->expects($this->once())->method('createDatabase')->with($shlinkDatabase);
|
||||
$this->schemaManager->expects($this->once())->method('listTableNames')->willReturn(
|
||||
['foo_table', 'bar_table', MIGRATIONS_TABLE],
|
||||
);
|
||||
|
@ -109,15 +109,12 @@ class CreateDatabaseCommandTest extends TestCase
|
|||
);
|
||||
$this->schemaManager->expects($this->never())->method('createDatabase');
|
||||
$this->schemaManager->expects($this->once())->method('listTableNames')->willReturn($tables);
|
||||
$this->processHelper->expects($this->once())->method('run')->with(
|
||||
$this->isInstanceOf(OutputInterface::class),
|
||||
$this->equalTo([
|
||||
'/usr/local/bin/php',
|
||||
CreateDatabaseCommand::DOCTRINE_SCRIPT,
|
||||
CreateDatabaseCommand::DOCTRINE_CREATE_SCHEMA_COMMAND,
|
||||
'--no-interaction',
|
||||
]),
|
||||
);
|
||||
$this->processHelper->expects($this->once())->method('run')->with($this->isInstanceOf(OutputInterface::class), [
|
||||
'/usr/local/bin/php',
|
||||
CreateDatabaseCommand::DOCTRINE_SCRIPT,
|
||||
CreateDatabaseCommand::DOCTRINE_CREATE_SCHEMA_COMMAND,
|
||||
'--no-interaction',
|
||||
]);
|
||||
$this->driver->method('getDatabasePlatform')->willReturn($this->createMock(AbstractPlatform::class));
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
|
|
|
@ -41,15 +41,12 @@ class MigrateDatabaseCommandTest extends TestCase
|
|||
/** @test */
|
||||
public function migrationsCommandIsRunWithProperVerbosity(): void
|
||||
{
|
||||
$this->processHelper->expects($this->once())->method('run')->with(
|
||||
$this->isInstanceOf(OutputInterface::class),
|
||||
$this->equalTo([
|
||||
'/usr/local/bin/php',
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
||||
'--no-interaction',
|
||||
]),
|
||||
);
|
||||
$this->processHelper->expects($this->once())->method('run')->with($this->isInstanceOf(OutputInterface::class), [
|
||||
'/usr/local/bin/php',
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATIONS_SCRIPT,
|
||||
MigrateDatabaseCommand::DOCTRINE_MIGRATE_COMMAND,
|
||||
'--no-interaction',
|
||||
]);
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
|
|
@ -37,12 +37,12 @@ class DomainRedirectsCommandTest extends TestCase
|
|||
public function onlyPlainQuestionsAreAskedForNewDomainsAndDomainsWithNoRedirects(?Domain $domain): void
|
||||
{
|
||||
$domainAuthority = 'my-domain.com';
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with($domainAuthority)->willReturn(
|
||||
$domain,
|
||||
);
|
||||
$this->domainService->expects($this->once())->method('configureNotFoundRedirects')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
$this->equalTo(NotFoundRedirects::withRedirects('foo.com', null, 'baz.com')),
|
||||
$domainAuthority,
|
||||
NotFoundRedirects::withRedirects('foo.com', null, 'baz.com'),
|
||||
)->willReturn(Domain::withAuthority(''));
|
||||
$this->domainService->expects($this->never())->method('listDomains');
|
||||
|
||||
|
@ -73,12 +73,12 @@ class DomainRedirectsCommandTest extends TestCase
|
|||
$domain = Domain::withAuthority($domainAuthority);
|
||||
$domain->configureNotFoundRedirects(NotFoundRedirects::withRedirects('foo.com', 'bar.com', 'baz.com'));
|
||||
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with($domainAuthority)->willReturn(
|
||||
$domain,
|
||||
);
|
||||
$this->domainService->expects($this->once())->method('configureNotFoundRedirects')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
$this->equalTo(NotFoundRedirects::withRedirects(null, 'edited.com', 'baz.com')),
|
||||
$domainAuthority,
|
||||
NotFoundRedirects::withRedirects(null, 'edited.com', 'baz.com'),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->never())->method('listDomains');
|
||||
|
||||
|
@ -102,12 +102,12 @@ class DomainRedirectsCommandTest extends TestCase
|
|||
$domain = Domain::withAuthority($domainAuthority);
|
||||
|
||||
$this->domainService->expects($this->once())->method('listDomains')->with()->willReturn([]);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with($domainAuthority)->willReturn(
|
||||
$domain,
|
||||
);
|
||||
$this->domainService->expects($this->once())->method('configureNotFoundRedirects')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
$this->equalTo(NotFoundRedirects::withoutRedirects()),
|
||||
$domainAuthority,
|
||||
NotFoundRedirects::withoutRedirects(),
|
||||
)->willReturn($domain);
|
||||
|
||||
$this->commandTester->setInputs([$domainAuthority, '', '', '']);
|
||||
|
@ -128,12 +128,12 @@ class DomainRedirectsCommandTest extends TestCase
|
|||
DomainItem::forNonDefaultDomain(Domain::withAuthority('existing-one.com')),
|
||||
DomainItem::forNonDefaultDomain(Domain::withAuthority($domainAuthority)),
|
||||
]);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with($domainAuthority)->willReturn(
|
||||
$domain,
|
||||
);
|
||||
$this->domainService->expects($this->once())->method('configureNotFoundRedirects')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
$this->equalTo(NotFoundRedirects::withoutRedirects()),
|
||||
$domainAuthority,
|
||||
NotFoundRedirects::withoutRedirects(),
|
||||
)->willReturn($domain);
|
||||
|
||||
$this->commandTester->setInputs(['1', '', '', '']);
|
||||
|
@ -157,12 +157,12 @@ class DomainRedirectsCommandTest extends TestCase
|
|||
DomainItem::forNonDefaultDomain(Domain::withAuthority('existing-one.com')),
|
||||
DomainItem::forNonDefaultDomain(Domain::withAuthority('existing-two.com')),
|
||||
]);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
)->willReturn($domain);
|
||||
$this->domainService->expects($this->once())->method('findByAuthority')->with($domainAuthority)->willReturn(
|
||||
$domain,
|
||||
);
|
||||
$this->domainService->expects($this->once())->method('configureNotFoundRedirects')->with(
|
||||
$this->equalTo($domainAuthority),
|
||||
$this->equalTo(NotFoundRedirects::withoutRedirects()),
|
||||
$domainAuthority,
|
||||
NotFoundRedirects::withoutRedirects(),
|
||||
)->willReturn($domain);
|
||||
|
||||
$this->commandTester->setInputs(['2', $domainAuthority, '', '', '']);
|
||||
|
|
|
@ -46,10 +46,10 @@ class GetDomainVisitsCommandTest extends TestCase
|
|||
);
|
||||
$domain = 'doma.in';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForDomain')->with(
|
||||
$this->equalTo($domain),
|
||||
$domain,
|
||||
$this->anything(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([$visit])));
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($this->equalTo($shortUrl))->willReturn(
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn(
|
||||
'the_short_url',
|
||||
);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class CreateShortUrlCommandTest extends TestCase
|
|||
{
|
||||
$shortUrl = ShortUrl::createEmpty();
|
||||
$this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willReturn($shortUrl);
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($this->equalTo($shortUrl))->willReturn(
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn(
|
||||
'stringified_short_url',
|
||||
);
|
||||
|
||||
|
@ -103,7 +103,7 @@ class CreateShortUrlCommandTest extends TestCase
|
|||
return true;
|
||||
}),
|
||||
)->willReturn($shortUrl);
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($this->equalTo($shortUrl))->willReturn(
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn(
|
||||
'stringified_short_url',
|
||||
);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class DeleteShortUrlCommandTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->service->expects($this->once())->method('deleteByShortCode')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
$this->isFalse(),
|
||||
);
|
||||
|
||||
|
@ -54,7 +54,7 @@ class DeleteShortUrlCommandTest extends TestCase
|
|||
$shortCode = 'abc123';
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
$this->service->expects($this->once())->method('deleteByShortCode')->with(
|
||||
$this->equalTo($identifier),
|
||||
$identifier,
|
||||
$this->isFalse(),
|
||||
)->willThrowException(Exception\ShortUrlNotFoundException::fromNotFound($identifier));
|
||||
|
||||
|
@ -76,7 +76,7 @@ class DeleteShortUrlCommandTest extends TestCase
|
|||
$shortCode = 'abc123';
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
$this->service->expects($this->exactly($expectedDeleteCalls))->method('deleteByShortCode')->with(
|
||||
$this->equalTo($identifier),
|
||||
$identifier,
|
||||
$this->isType('bool'),
|
||||
)->willReturnCallback(function ($_, bool $ignoreThreshold) use ($shortCode): void {
|
||||
if (!$ignoreThreshold) {
|
||||
|
@ -110,7 +110,7 @@ class DeleteShortUrlCommandTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->service->expects($this->once())->method('deleteByShortCode')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
$this->isFalse(),
|
||||
)->willThrowException(Exception\DeleteShortUrlException::fromVisitsThreshold(
|
||||
10,
|
||||
|
|
|
@ -44,8 +44,8 @@ class GetShortUrlVisitsCommandTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
$this->equalTo(new VisitsParams(DateRange::allTime())),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
new VisitsParams(DateRange::allTime()),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
|
@ -58,8 +58,8 @@ class GetShortUrlVisitsCommandTest extends TestCase
|
|||
$startDate = '2016-01-01';
|
||||
$endDate = '2016-02-01';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
$this->equalTo(new VisitsParams(buildDateRange(Chronos::parse($startDate), Chronos::parse($endDate)))),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
new VisitsParams(buildDateRange(Chronos::parse($startDate), Chronos::parse($endDate))),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute([
|
||||
|
@ -75,8 +75,8 @@ class GetShortUrlVisitsCommandTest extends TestCase
|
|||
$shortCode = 'abc123';
|
||||
$startDate = 'foo';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
$this->equalTo(new VisitsParams(DateRange::allTime())),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
new VisitsParams(DateRange::allTime()),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute([
|
||||
|
@ -99,7 +99,7 @@ class GetShortUrlVisitsCommandTest extends TestCase
|
|||
);
|
||||
$shortCode = 'abc123';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
$this->anything(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([$visit])));
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
}
|
||||
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::emptyInstance()),
|
||||
ShortUrlsParams::emptyInstance(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter($data)));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
|
@ -94,7 +94,7 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
{
|
||||
$page = 5;
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::fromRawData(['page' => $page])),
|
||||
ShortUrlsParams::fromRawData(['page' => $page]),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->setInputs(['y']);
|
||||
|
@ -112,7 +112,7 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
ApiKey $apiKey,
|
||||
): void {
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::emptyInstance()),
|
||||
ShortUrlsParams::emptyInstance(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([
|
||||
ShortUrl::fromMeta(ShortUrlCreation::fromRawData([
|
||||
'longUrl' => 'foo.com',
|
||||
|
@ -187,16 +187,14 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
?string $startDate = null,
|
||||
?string $endDate = null,
|
||||
): void {
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::fromRawData([
|
||||
'page' => $page,
|
||||
'searchTerm' => $searchTerm,
|
||||
'tags' => $tags,
|
||||
'tagsMode' => $tagsMode,
|
||||
'startDate' => $startDate !== null ? Chronos::parse($startDate)->toAtomString() : null,
|
||||
'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null,
|
||||
])),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
|
||||
'page' => $page,
|
||||
'searchTerm' => $searchTerm,
|
||||
'tags' => $tags,
|
||||
'tagsMode' => $tagsMode,
|
||||
'startDate' => $startDate !== null ? Chronos::parse($startDate)->toAtomString() : null,
|
||||
'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null,
|
||||
]))->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute($commandArgs);
|
||||
|
@ -249,11 +247,9 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
*/
|
||||
public function orderByIsProperlyComputed(array $commandArgs, ?string $expectedOrderBy): void
|
||||
{
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::fromRawData([
|
||||
'orderBy' => $expectedOrderBy,
|
||||
])),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
|
||||
'orderBy' => $expectedOrderBy,
|
||||
]))->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute($commandArgs);
|
||||
|
@ -271,18 +267,16 @@ class ListShortUrlsCommandTest extends TestCase
|
|||
/** @test */
|
||||
public function requestingAllElementsWillSetItemsPerPage(): void
|
||||
{
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
$this->equalTo(ShortUrlsParams::fromRawData([
|
||||
'page' => 1,
|
||||
'searchTerm' => null,
|
||||
'tags' => [],
|
||||
'tagsMode' => TagsMode::ANY->value,
|
||||
'startDate' => null,
|
||||
'endDate' => null,
|
||||
'orderBy' => null,
|
||||
'itemsPerPage' => Paginator::ALL_ITEMS,
|
||||
])),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
|
||||
'page' => 1,
|
||||
'searchTerm' => null,
|
||||
'tags' => [],
|
||||
'tagsMode' => TagsMode::ANY->value,
|
||||
'startDate' => null,
|
||||
'endDate' => null,
|
||||
'orderBy' => null,
|
||||
'itemsPerPage' => Paginator::ALL_ITEMS,
|
||||
]))->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute(['--all' => true]);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class ResolveUrlCommandTest extends TestCase
|
|||
$expectedUrl = 'http://domain.com/foo/bar';
|
||||
$shortUrl = ShortUrl::withLongUrl($expectedUrl);
|
||||
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
)->willReturn($shortUrl);
|
||||
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
|
@ -52,9 +52,9 @@ class ResolveUrlCommandTest extends TestCase
|
|||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain('abc123');
|
||||
$shortCode = $identifier->shortCode;
|
||||
|
||||
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with(
|
||||
$this->equalTo($identifier),
|
||||
)->willThrowException(ShortUrlNotFoundException::fromNotFound($identifier));
|
||||
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with($identifier)->willThrowException(
|
||||
ShortUrlNotFoundException::fromNotFound($identifier),
|
||||
);
|
||||
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
|
|
@ -37,7 +37,7 @@ class DeleteTagsCommandTest extends TestCase
|
|||
public function serviceIsInvokedOnSuccess(): void
|
||||
{
|
||||
$tagNames = ['foo', 'bar'];
|
||||
$this->tagService->expects($this->once())->method('deleteTags')->with($this->equalTo($tagNames));
|
||||
$this->tagService->expects($this->once())->method('deleteTags')->with($tagNames);
|
||||
|
||||
$this->commandTester->execute([
|
||||
'--name' => $tagNames,
|
||||
|
|
|
@ -45,13 +45,10 @@ class GetTagVisitsCommandTest extends TestCase
|
|||
VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')),
|
||||
);
|
||||
$tag = 'abc123';
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForTag')->with(
|
||||
$this->equalTo($tag),
|
||||
$this->anything(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([$visit])));
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($this->equalTo($shortUrl))->willReturn(
|
||||
'the_short_url',
|
||||
$this->visitsHelper->expects($this->once())->method('visitsForTag')->with($tag, $this->anything())->willReturn(
|
||||
new Paginator(new ArrayAdapter([$visit])),
|
||||
);
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn('the_short_url');
|
||||
|
||||
$this->commandTester->execute(['tag' => $tag]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
|
|
@ -33,7 +33,7 @@ class RenameTagCommandTest extends TestCase
|
|||
$oldName = 'foo';
|
||||
$newName = 'bar';
|
||||
$this->tagService->expects($this->once())->method('renameTag')->with(
|
||||
$this->equalTo(TagRenaming::fromNames($oldName, $newName)),
|
||||
TagRenaming::fromNames($oldName, $newName),
|
||||
)->willThrowException(TagNotFoundException::fromTag('foo'));
|
||||
|
||||
$this->commandTester->execute([
|
||||
|
@ -51,7 +51,7 @@ class RenameTagCommandTest extends TestCase
|
|||
$oldName = 'foo';
|
||||
$newName = 'bar';
|
||||
$this->tagService->expects($this->once())->method('renameTag')->with(
|
||||
$this->equalTo(TagRenaming::fromNames($oldName, $newName)),
|
||||
TagRenaming::fromNames($oldName, $newName),
|
||||
)->willReturn(new Tag($newName));
|
||||
|
||||
$this->commandTester->execute([
|
||||
|
|
|
@ -47,9 +47,7 @@ class GetNonOrphanVisitsCommandTest extends TestCase
|
|||
$this->visitsHelper->expects($this->once())->method('nonOrphanVisits')->withAnyParameters()->willReturn(
|
||||
new Paginator(new ArrayAdapter([$visit])),
|
||||
);
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($this->equalTo($shortUrl))->willReturn(
|
||||
'the_short_url',
|
||||
);
|
||||
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn('the_short_url');
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
|
|
@ -26,7 +26,7 @@ class ProcessRunnerTest extends TestCase
|
|||
$this->helper = $this->createMock(ProcessHelper::class);
|
||||
$this->formatter = $this->createMock(DebugFormatterHelper::class);
|
||||
$helperSet = $this->createMock(HelperSet::class);
|
||||
$helperSet->method('get')->with($this->equalTo('debug_formatter'))->willReturn($this->formatter);
|
||||
$helperSet->method('get')->with('debug_formatter')->willReturn($this->formatter);
|
||||
$this->helper->method('getHelperSet')->with()->willReturn($helperSet);
|
||||
$this->process = $this->createMock(Process::class);
|
||||
$this->output = $this->createMock(OutputInterface::class);
|
||||
|
|
|
@ -34,16 +34,10 @@ class ShlinkTableTest extends TestCase
|
|||
$this->baseTable->expects($this->once())->method('setStyle')->with(
|
||||
$this->isInstanceOf(TableStyle::class),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaders')->with(
|
||||
$this->equalTo($headers),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setRows')->with($this->equalTo($rows))->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setFooterTitle')->with(
|
||||
$this->equalTo($footerTitle),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaderTitle')->with(
|
||||
$this->equalTo($headerTitle),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setRows')->with($rows)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setFooterTitle')->with($footerTitle)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaderTitle')->with($headerTitle)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('render')->with()->willReturnSelf();
|
||||
|
||||
$this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle);
|
||||
|
|
|
@ -34,7 +34,7 @@ class PixelActionTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
||||
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'));
|
||||
$this->requestTracker->expects($this->once())->method('trackIfApplicable')->withAnyParameters();
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class QrCodeActionTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
||||
)->willThrowException(ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('')));
|
||||
$delegate = $this->createMock(RequestHandlerInterface::class);
|
||||
$delegate->expects($this->once())->method('handle')->withAnyParameters()->willReturn(new Response());
|
||||
|
@ -55,7 +55,7 @@ class QrCodeActionTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
||||
)->willReturn(ShortUrl::createEmpty());
|
||||
$delegate = $this->createMock(RequestHandlerInterface::class);
|
||||
$delegate->expects($this->never())->method('handle');
|
||||
|
@ -77,7 +77,7 @@ class QrCodeActionTest extends TestCase
|
|||
): void {
|
||||
$code = 'abc123';
|
||||
$this->urlResolver->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($code, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($code, ''),
|
||||
)->willReturn(ShortUrl::createEmpty());
|
||||
$delegate = $this->createMock(RequestHandlerInterface::class);
|
||||
$req = (new ServerRequest())->withAttribute('shortCode', $code)->withQueryParams($query);
|
||||
|
@ -110,7 +110,7 @@ class QrCodeActionTest extends TestCase
|
|||
): void {
|
||||
$code = 'abc123';
|
||||
$this->urlResolver->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($code, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($code, ''),
|
||||
)->willReturn(ShortUrl::createEmpty());
|
||||
$delegate = $this->createMock(RequestHandlerInterface::class);
|
||||
|
||||
|
@ -201,7 +201,7 @@ class QrCodeActionTest extends TestCase
|
|||
->withAttribute('shortCode', $code);
|
||||
|
||||
$this->urlResolver->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($code, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($code, ''),
|
||||
)->willReturn(ShortUrl::withLongUrl('https://shlink.io'));
|
||||
$delegate = $this->createMock(RequestHandlerInterface::class);
|
||||
|
||||
|
|
|
@ -50,12 +50,12 @@ class RedirectActionTest extends TestCase
|
|||
$shortCode = 'abc123';
|
||||
$shortUrl = ShortUrl::withLongUrl(self::LONG_URL);
|
||||
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
||||
)->willReturn($shortUrl);
|
||||
$this->requestTracker->expects($this->once())->method('trackIfApplicable');
|
||||
$expectedResp = new Response\RedirectResponse(self::LONG_URL);
|
||||
$this->redirectRespHelper->expects($this->once())->method('buildRedirectResponse')->with(
|
||||
$this->equalTo(self::LONG_URL),
|
||||
self::LONG_URL,
|
||||
)->willReturn($expectedResp);
|
||||
|
||||
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
|
||||
|
@ -69,7 +69,7 @@ class RedirectActionTest extends TestCase
|
|||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, '')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
||||
)->willThrowException(ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('')));
|
||||
$this->requestTracker->expects($this->never())->method('trackIfApplicable');
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ class NotFoundRedirectResolverTest extends TestCase
|
|||
string $expectedRedirectTo,
|
||||
): void {
|
||||
$expectedResp = new Response();
|
||||
$this->helper->expects($this->once())->method('buildRedirectResponse')->with(
|
||||
$this->equalTo($expectedRedirectTo),
|
||||
)->willReturn($expectedResp);
|
||||
$this->helper->expects($this->once())->method('buildRedirectResponse')->with($expectedRedirectTo)->willReturn(
|
||||
$expectedResp,
|
||||
);
|
||||
|
||||
$resp = $this->resolver->resolveRedirectResponse($notFoundType, $redirectConfig, $uri);
|
||||
|
||||
|
|
|
@ -27,9 +27,7 @@ class CrawlingHelperTest extends TestCase
|
|||
{
|
||||
$repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$repo->expects($this->once())->method('findCrawlableShortCodes')->willReturn([]);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
||||
|
||||
$result = $this->helper->listCrawlableShortCodes();
|
||||
foreach ($result as $shortCode) {
|
||||
|
|
|
@ -36,10 +36,8 @@ class DomainServiceTest extends TestCase
|
|||
public function listDomainsDelegatesIntoRepository(array $domains, array $expectedResult, ?ApiKey $apiKey): void
|
||||
{
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo->expects($this->once())->method('findDomains')->with($this->equalTo($apiKey))->willReturn($domains);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(Domain::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$repo->expects($this->once())->method('findDomains')->with($apiKey)->willReturn($domains);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
|
||||
$result = $this->domainService->listDomains($apiKey);
|
||||
|
||||
|
@ -105,10 +103,7 @@ class DomainServiceTest extends TestCase
|
|||
/** @test */
|
||||
public function getDomainThrowsExceptionWhenDomainIsNotFound(): void
|
||||
{
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Domain::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(Domain::class, '123')->willReturn(null);
|
||||
|
||||
$this->expectException(DomainNotFoundException::class);
|
||||
|
||||
|
@ -119,10 +114,7 @@ class DomainServiceTest extends TestCase
|
|||
public function getDomainReturnsEntityWhenFound(): void
|
||||
{
|
||||
$domain = Domain::withAuthority('');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Domain::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn($domain);
|
||||
$this->em->expects($this->once())->method('find')->with(Domain::class, '123')->willReturn($domain);
|
||||
|
||||
$result = $this->domainService->getDomain('123');
|
||||
|
||||
|
@ -137,15 +129,11 @@ class DomainServiceTest extends TestCase
|
|||
{
|
||||
$authority = 'example.com';
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo->method('findOneByAuthority')->with($this->equalTo($authority), $this->equalTo($apiKey))->willReturn(
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(
|
||||
$foundDomain,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(Domain::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('persist')->with(
|
||||
$foundDomain !== null ? $this->equalTo($foundDomain) : $this->isInstanceOf(Domain::class),
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
$this->em->expects($this->once())->method('persist')->with($foundDomain ?? $this->isInstanceOf(Domain::class));
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
|
||||
$result = $this->domainService->getOrCreate($authority, $apiKey);
|
||||
|
@ -162,12 +150,8 @@ class DomainServiceTest extends TestCase
|
|||
$domain = Domain::withAuthority($authority)->setId('1');
|
||||
$apiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)));
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo->method('findOneByAuthority')->with($this->equalTo($authority), $this->equalTo($apiKey))->willReturn(
|
||||
null,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(Domain::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
$this->em->expects($this->never())->method('persist');
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
|
||||
|
@ -184,15 +168,9 @@ class DomainServiceTest extends TestCase
|
|||
{
|
||||
$authority = 'example.com';
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo->method('findOneByAuthority')->with($this->equalTo($authority), $this->equalTo($apiKey))->willReturn(
|
||||
$foundDomain,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(Domain::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('persist')->with(
|
||||
$foundDomain !== null ? $this->equalTo($foundDomain) : $this->isInstanceOf(Domain::class),
|
||||
);
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn($foundDomain);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
$this->em->expects($this->once())->method('persist')->with($foundDomain ?? $this->isInstanceOf(Domain::class));
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
|
||||
$result = $this->domainService->configureNotFoundRedirects($authority, NotFoundRedirects::withRedirects(
|
||||
|
|
|
@ -51,9 +51,7 @@ class NotFoundRedirectHandlerTest extends TestCase
|
|||
$expectedResp = new Response();
|
||||
|
||||
$setUp($this->domainService, $this->resolver);
|
||||
$this->next->expects($this->once())->method('handle')->with($this->equalTo($this->req))->willReturn(
|
||||
$expectedResp,
|
||||
);
|
||||
$this->next->expects($this->once())->method('handle')->with($this->req)->willReturn($expectedResp);
|
||||
|
||||
$result = $this->middleware->process($this->req, $this->next);
|
||||
|
||||
|
@ -105,7 +103,7 @@ class NotFoundRedirectHandlerTest extends TestCase
|
|||
$this->domainService->expects($this->once())->method('findByAuthority')->withAnyParameters()->willReturn(null);
|
||||
$this->resolver->expects($this->once())->method('resolveRedirectResponse')->with(
|
||||
$this->isInstanceOf(NotFoundType::class),
|
||||
$this->equalTo($this->redirectOptions),
|
||||
$this->redirectOptions,
|
||||
$this->isInstanceOf(UriInterface::class),
|
||||
)->willReturn($expectedResp);
|
||||
$this->next->expects($this->never())->method('handle');
|
||||
|
@ -126,7 +124,7 @@ class NotFoundRedirectHandlerTest extends TestCase
|
|||
);
|
||||
$this->resolver->expects($this->once())->method('resolveRedirectResponse')->with(
|
||||
$this->isInstanceOf(NotFoundType::class),
|
||||
$this->equalTo($domain),
|
||||
$domain,
|
||||
$this->isInstanceOf(UriInterface::class),
|
||||
)->willReturn($expectedResp);
|
||||
$this->next->expects($this->never())->method('handle');
|
||||
|
|
|
@ -35,10 +35,8 @@ class NotFoundTrackerMiddlewareTest extends TestCase
|
|||
/** @test */
|
||||
public function delegatesIntoRequestTracker(): void
|
||||
{
|
||||
$this->handler->expects($this->once())->method('handle')->with($this->equalTo($this->request));
|
||||
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with(
|
||||
$this->equalTo($this->request),
|
||||
);
|
||||
$this->handler->expects($this->once())->method('handle')->with($this->request);
|
||||
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with($this->request);
|
||||
|
||||
$this->middleware->process($this->request, $this->handler);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class CloseDbConnectionEventListenerDelegatorTest extends TestCase
|
|||
};
|
||||
};
|
||||
|
||||
$this->container->expects($this->once())->method('get')->with($this->equalTo('em'))->willReturn(
|
||||
$this->container->expects($this->once())->method('get')->with('em')->willReturn(
|
||||
$this->createMock(ReopeningEntityManagerInterface::class),
|
||||
);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class LocateUnlocatedVisitsTest extends TestCase
|
|||
/** @test */
|
||||
public function locatorIsCalledWhenInvoked(): void
|
||||
{
|
||||
$this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->equalTo($this->listener));
|
||||
$this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->listener);
|
||||
($this->listener)(new GeoLiteDbCreated());
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ class LocateUnlocatedVisitsTest extends TestCase
|
|||
$visit = Visit::forBasePath(Visitor::emptyInstance());
|
||||
$location = Location::emptyInstance();
|
||||
|
||||
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($location);
|
||||
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->with($visit)->willReturn(
|
||||
$location,
|
||||
);
|
||||
|
||||
$result = $this->listener->geolocateVisit($visit);
|
||||
|
||||
|
|
|
@ -53,18 +53,13 @@ class LocateVisitTest extends TestCase
|
|||
public function invalidVisitLogsWarning(): void
|
||||
{
|
||||
$event = new UrlVisited('123');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn(null);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to locate visit with id "{visitId}", but it does not exist.'),
|
||||
$this->equalTo(['visitId' => 123]),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
'Tried to locate visit with id "{visitId}", but it does not exist.',
|
||||
['visitId' => 123],
|
||||
);
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch')->with(new VisitLocated('123'));
|
||||
$this->ipLocationResolver->expects($this->never())->method('resolveIpLocation');
|
||||
|
||||
($this->locateVisit)($event);
|
||||
|
@ -74,19 +69,16 @@ class LocateVisitTest extends TestCase
|
|||
public function nonExistingGeoLiteDbLogsWarning(): void
|
||||
{
|
||||
$event = new UrlVisited('123');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn(
|
||||
Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')),
|
||||
);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->withAnyParameters()->willReturn(false);
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to locate visit with id "{visitId}", but a GeoLite2 db was not found.'),
|
||||
$this->equalTo(['visitId' => 123]),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
'Tried to locate visit with id "{visitId}", but a GeoLite2 db was not found.',
|
||||
['visitId' => 123],
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(new VisitLocated('123'));
|
||||
$this->ipLocationResolver->expects($this->never())->method('resolveIpLocation');
|
||||
|
||||
($this->locateVisit)($event);
|
||||
|
@ -96,22 +88,19 @@ class LocateVisitTest extends TestCase
|
|||
public function invalidAddressLogsWarning(): void
|
||||
{
|
||||
$event = new UrlVisited('123');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn(
|
||||
Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')),
|
||||
);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->withAnyParameters()->willReturn(true);
|
||||
$this->ipLocationResolver->expects(
|
||||
$this->once(),
|
||||
)->method('resolveIpLocation')->withAnyParameters()->willThrowException(WrongIpException::fromIpAddress(''));
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to locate visit with id "{visitId}", but its address seems to be wrong. {e}'),
|
||||
'Tried to locate visit with id "{visitId}", but its address seems to be wrong. {e}',
|
||||
$this->isType('array'),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(new VisitLocated('123'));
|
||||
|
||||
($this->locateVisit)($event);
|
||||
}
|
||||
|
@ -120,22 +109,19 @@ class LocateVisitTest extends TestCase
|
|||
public function unhandledExceptionLogsError(): void
|
||||
{
|
||||
$event = new UrlVisited('123');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn(
|
||||
Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')),
|
||||
);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->withAnyParameters()->willReturn(true);
|
||||
$this->ipLocationResolver->expects(
|
||||
$this->once(),
|
||||
)->method('resolveIpLocation')->withAnyParameters()->willThrowException(new OutOfRangeException());
|
||||
$this->logger->expects($this->once())->method('error')->with(
|
||||
$this->equalTo('An unexpected error occurred while trying to locate visit with id "{visitId}". {e}'),
|
||||
'An unexpected error occurred while trying to locate visit with id "{visitId}". {e}',
|
||||
$this->isType('array'),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(new VisitLocated('123'));
|
||||
|
||||
($this->locateVisit)($event);
|
||||
}
|
||||
|
@ -147,17 +133,12 @@ class LocateVisitTest extends TestCase
|
|||
public function nonLocatableVisitsResolveToEmptyLocations(Visit $visit): void
|
||||
{
|
||||
$event = new UrlVisited('123');
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->withAnyParameters()->willReturn(true);
|
||||
$this->ipLocationResolver->expects($this->never())->method('resolveIpLocation');
|
||||
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
);
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(new VisitLocated('123'));
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
|
||||
($this->locateVisit)($event);
|
||||
|
@ -184,19 +165,14 @@ class LocateVisitTest extends TestCase
|
|||
$location = new Location('', '', '', '', 0.0, 0.0, '');
|
||||
$event = UrlVisited::withOriginalIpAddress('123', $originalIpAddress);
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '123')->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->withAnyParameters()->willReturn(true);
|
||||
$this->ipLocationResolver->expects($this->once())->method('resolveIpLocation')->with(
|
||||
$this->equalTo($ipAddr),
|
||||
)->willReturn($location);
|
||||
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(
|
||||
$this->equalTo(new VisitLocated('123')),
|
||||
$this->ipLocationResolver->expects($this->once())->method('resolveIpLocation')->with($ipAddr)->willReturn(
|
||||
$location,
|
||||
);
|
||||
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(new VisitLocated('123'));
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
|
||||
($this->locateVisit)($event);
|
||||
|
|
|
@ -42,15 +42,12 @@ class NotifyNewShortUrlToMercureTest extends TestCase
|
|||
/** @test */
|
||||
public function messageIsLoggedWhenShortUrlIsNotFound(): void
|
||||
{
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, '123')->willReturn(null);
|
||||
$this->helper->expects($this->never())->method('publishUpdate');
|
||||
$this->updatesGenerator->expects($this->never())->method('newShortUrlUpdate');
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to notify {name} for new short URL with id "{shortUrlId}", but it does not exist.'),
|
||||
$this->equalTo(['shortUrlId' => '123', 'name' => 'Mercure']),
|
||||
'Tried to notify {name} for new short URL with id "{shortUrlId}", but it does not exist.',
|
||||
['shortUrlId' => '123', 'name' => 'Mercure'],
|
||||
);
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
|
||||
|
@ -63,14 +60,11 @@ class NotifyNewShortUrlToMercureTest extends TestCase
|
|||
$shortUrl = ShortUrl::withLongUrl('');
|
||||
$update = Update::forTopicAndPayload('', []);
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo('123'),
|
||||
)->willReturn($shortUrl);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with(
|
||||
$this->equalTo($shortUrl),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($this->equalTo($update));
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, '123')->willReturn($shortUrl);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with($shortUrl)->willReturn(
|
||||
$update,
|
||||
);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update);
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
|
||||
|
@ -85,19 +79,15 @@ class NotifyNewShortUrlToMercureTest extends TestCase
|
|||
$e = new Exception('Error');
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo('123'),
|
||||
ShortUrl::class,
|
||||
'123',
|
||||
)->willReturn($shortUrl);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with(
|
||||
$this->equalTo($shortUrl),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with(
|
||||
$this->equalTo($update),
|
||||
)->willThrowException($e);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with($shortUrl)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update)->willThrowException($e);
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new short URL. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'Mercure']),
|
||||
'Error while trying to notify {name} with new short URL. {e}',
|
||||
['e' => $e, 'name' => 'Mercure'],
|
||||
);
|
||||
|
||||
($this->listener)(new ShortUrlCreated('123'));
|
||||
|
|
|
@ -41,13 +41,10 @@ class NotifyVisitToMercureTest extends TestCase
|
|||
public function notificationsAreNotSentWhenVisitCannotBeFound(): void
|
||||
{
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn(null);
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to notify {name} for visit with id "{visitId}", but it does not exist.'),
|
||||
$this->equalTo(['visitId' => $visitId, 'name' => 'Mercure']),
|
||||
'Tried to notify {name} for visit with id "{visitId}", but it does not exist.',
|
||||
['visitId' => $visitId, 'name' => 'Mercure'],
|
||||
);
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
$this->updatesGenerator->expects($this->never())->method('newShortUrlVisitUpdate');
|
||||
|
@ -65,20 +62,15 @@ class NotifyVisitToMercureTest extends TestCase
|
|||
$visit = Visit::forValidShortUrl(ShortUrl::createEmpty(), Visitor::emptyInstance());
|
||||
$update = Update::forTopicAndPayload('', []);
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn($visit);
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlVisitUpdate')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($update);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlVisitUpdate')->with($visit)->willReturn(
|
||||
$update,
|
||||
);
|
||||
$this->updatesGenerator->expects($this->never())->method('newOrphanVisitUpdate');
|
||||
$this->updatesGenerator->expects($this->once())->method('newVisitUpdate')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->exactly(2))->method('publishUpdate')->with($this->equalTo($update));
|
||||
$this->updatesGenerator->expects($this->once())->method('newVisitUpdate')->with($visit)->willReturn($update);
|
||||
$this->helper->expects($this->exactly(2))->method('publishUpdate')->with($update);
|
||||
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
}
|
||||
|
@ -91,25 +83,18 @@ class NotifyVisitToMercureTest extends TestCase
|
|||
$update = Update::forTopicAndPayload('', []);
|
||||
$e = new RuntimeException('Error');
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn($visit);
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new visit. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'Mercure']),
|
||||
'Error while trying to notify {name} with new visit. {e}',
|
||||
['e' => $e, 'name' => 'Mercure'],
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlVisitUpdate')->with($visit)->willReturn(
|
||||
$update,
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlVisitUpdate')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($update);
|
||||
$this->updatesGenerator->expects($this->never())->method('newOrphanVisitUpdate');
|
||||
$this->updatesGenerator->expects($this->once())->method('newVisitUpdate')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with(
|
||||
$this->equalTo($update),
|
||||
)->willThrowException($e);
|
||||
$this->updatesGenerator->expects($this->once())->method('newVisitUpdate')->with($visit)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update)->willThrowException($e);
|
||||
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
}
|
||||
|
@ -123,18 +108,15 @@ class NotifyVisitToMercureTest extends TestCase
|
|||
$visitId = '123';
|
||||
$update = Update::forTopicAndPayload('', []);
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn($visit);
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
$this->updatesGenerator->expects($this->never())->method('newShortUrlVisitUpdate');
|
||||
$this->updatesGenerator->expects($this->once())->method('newOrphanVisitUpdate')->with(
|
||||
$this->equalTo($visit),
|
||||
)->willReturn($update);
|
||||
$this->updatesGenerator->expects($this->once())->method('newOrphanVisitUpdate')->with($visit)->willReturn(
|
||||
$update,
|
||||
);
|
||||
$this->updatesGenerator->expects($this->never())->method('newVisitUpdate');
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($this->equalTo($update));
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update);
|
||||
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
}
|
||||
|
|
|
@ -52,14 +52,11 @@ class NotifyVisitToWebHooksTest extends TestCase
|
|||
/** @test */
|
||||
public function invalidVisitDoesNotPerformAnyRequest(): void
|
||||
{
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('1'),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn(null);
|
||||
$this->httpClient->expects($this->never())->method('requestAsync');
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to notify webhooks for visit with id "{visitId}", but it does not exist.'),
|
||||
$this->equalTo(['visitId' => '1']),
|
||||
'Tried to notify webhooks for visit with id "{visitId}", but it does not exist.',
|
||||
['visitId' => '1'],
|
||||
);
|
||||
|
||||
$this->createListener(['foo', 'bar'])(new VisitLocated('1'));
|
||||
|
@ -68,10 +65,9 @@ class NotifyVisitToWebHooksTest extends TestCase
|
|||
/** @test */
|
||||
public function orphanVisitDoesNotPerformAnyRequestWhenDisabled(): void
|
||||
{
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('1'),
|
||||
)->willReturn(Visit::forBasePath(Visitor::emptyInstance()));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn(
|
||||
Visit::forBasePath(Visitor::emptyInstance()),
|
||||
);
|
||||
$this->httpClient->expects($this->never())->method('requestAsync');
|
||||
$this->logger->expects($this->never())->method('warning');
|
||||
|
||||
|
@ -87,12 +83,9 @@ class NotifyVisitToWebHooksTest extends TestCase
|
|||
$webhooks = ['foo', 'invalid', 'bar', 'baz'];
|
||||
$invalidWebhooks = ['invalid', 'baz'];
|
||||
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo('1'),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, '1')->willReturn($visit);
|
||||
$this->httpClient->expects($this->exactly(count($webhooks)))->method('requestAsync')->with(
|
||||
$this->equalTo(RequestMethodInterface::METHOD_POST),
|
||||
RequestMethodInterface::METHOD_POST,
|
||||
$this->istype('string'),
|
||||
$this->callback(function (array $requestOptions) use ($expectedResponseKeys) {
|
||||
Assert::assertArrayHasKey(RequestOptions::HEADERS, $requestOptions);
|
||||
|
@ -114,7 +107,7 @@ class NotifyVisitToWebHooksTest extends TestCase
|
|||
return $shouldReject ? new RejectedPromise(new Exception('')) : new FulfilledPromise('');
|
||||
});
|
||||
$this->logger->expects($this->exactly(count($invalidWebhooks)))->method('warning')->with(
|
||||
$this->equalTo('Failed to notify visit with id "{visitId}" to webhook "{webhook}". {e}'),
|
||||
'Failed to notify visit with id "{visitId}" to webhook "{webhook}". {e}',
|
||||
$this->callback(function (array $extra): bool {
|
||||
Assert::assertArrayHasKey('webhook', $extra);
|
||||
Assert::assertArrayHasKey('visitId', $extra);
|
||||
|
|
|
@ -51,13 +51,10 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
|||
public function notificationsAreNotSentWhenShortUrlCannotBeFound(): void
|
||||
{
|
||||
$shortUrlId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo($shortUrlId),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, $shortUrlId)->willReturn(null);
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to notify {name} for new short URL with id "{shortUrlId}", but it does not exist.'),
|
||||
$this->equalTo(['shortUrlId' => $shortUrlId, 'name' => 'RabbitMQ']),
|
||||
'Tried to notify {name} for new short URL with id "{shortUrlId}", but it does not exist.',
|
||||
['shortUrlId' => $shortUrlId, 'name' => 'RabbitMQ'],
|
||||
);
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
$this->helper->expects($this->never())->method('publishUpdate');
|
||||
|
@ -70,14 +67,13 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
|||
{
|
||||
$shortUrlId = '123';
|
||||
$update = Update::forTopicAndPayload(Topic::NEW_SHORT_URL->value, []);
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo($shortUrlId),
|
||||
)->willReturn(ShortUrl::withLongUrl(''));
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, $shortUrlId)->willReturn(
|
||||
ShortUrl::withLongUrl(''),
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with(
|
||||
$this->isInstanceOf(ShortUrl::class),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($this->equalTo($update));
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update);
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
|
||||
($this->listener())(new ShortUrlCreated($shortUrlId));
|
||||
|
@ -91,19 +87,16 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
|||
{
|
||||
$shortUrlId = '123';
|
||||
$update = Update::forTopicAndPayload(Topic::NEW_SHORT_URL->value, []);
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo($shortUrlId),
|
||||
)->willReturn(ShortUrl::withLongUrl(''));
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, $shortUrlId)->willReturn(
|
||||
ShortUrl::withLongUrl(''),
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with(
|
||||
$this->isInstanceOf(ShortUrl::class),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with(
|
||||
$this->equalTo($update),
|
||||
)->willThrowException($e);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update)->willThrowException($e);
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new short URL. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'RabbitMQ']),
|
||||
'Error while trying to notify {name} with new short URL. {e}',
|
||||
['e' => $e, 'name' => 'RabbitMQ'],
|
||||
);
|
||||
|
||||
($this->listener())(new ShortUrlCreated($shortUrlId));
|
||||
|
|
|
@ -59,13 +59,10 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
|||
public function notificationsAreNotSentWhenVisitCannotBeFound(): void
|
||||
{
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn(null);
|
||||
$this->logger->expects($this->once())->method('warning')->with(
|
||||
$this->equalTo('Tried to notify {name} for visit with id "{visitId}", but it does not exist.'),
|
||||
$this->equalTo(['visitId' => $visitId, 'name' => 'RabbitMQ']),
|
||||
'Tried to notify {name} for visit with id "{visitId}", but it does not exist.',
|
||||
['visitId' => $visitId, 'name' => 'RabbitMQ'],
|
||||
);
|
||||
$this->logger->expects($this->never())->method('debug');
|
||||
$this->helper->expects($this->never())->method('publishUpdate');
|
||||
|
@ -80,10 +77,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
|||
public function expectedChannelsAreNotifiedBasedOnTheVisitType(Visit $visit, array $expectedChannels): void
|
||||
{
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn($visit);
|
||||
each($expectedChannels, function (string $method): void {
|
||||
$this->updatesGenerator->expects($this->once())->method($method)->with(
|
||||
$this->isInstanceOf(Visit::class),
|
||||
|
@ -121,17 +115,16 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
|||
public function printsDebugMessageInCaseOfError(Throwable $e): void
|
||||
{
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn(Visit::forBasePath(Visitor::emptyInstance()));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn(
|
||||
Visit::forBasePath(Visitor::emptyInstance()),
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newOrphanVisitUpdate')->with(
|
||||
$this->isInstanceOf(Visit::class),
|
||||
)->willReturn(Update::forTopicAndPayload('', []));
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->withAnyParameters()->willThrowException($e);
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new visit. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'RabbitMQ']),
|
||||
'Error while trying to notify {name} with new visit. {e}',
|
||||
['e' => $e, 'name' => 'RabbitMQ'],
|
||||
);
|
||||
|
||||
($this->listener())(new VisitLocated($visitId));
|
||||
|
@ -155,10 +148,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
|||
callable $expect,
|
||||
): void {
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn($visit);
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn($visit);
|
||||
$setup($this->updatesGenerator);
|
||||
$expect($this->helper, $this->updatesGenerator);
|
||||
|
||||
|
|
|
@ -54,19 +54,16 @@ class NotifyNewShortUrlToRedisTest extends TestCase
|
|||
{
|
||||
$shortUrlId = '123';
|
||||
$update = Update::forTopicAndPayload(Topic::NEW_SHORT_URL->value, []);
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
$this->equalTo($shortUrlId),
|
||||
)->willReturn(ShortUrl::withLongUrl(''));
|
||||
$this->em->expects($this->once())->method('find')->with(ShortUrl::class, $shortUrlId)->willReturn(
|
||||
ShortUrl::withLongUrl(''),
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newShortUrlUpdate')->with(
|
||||
$this->isInstanceOf(ShortUrl::class),
|
||||
)->willReturn($update);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with(
|
||||
$this->equalTo($update),
|
||||
)->willThrowException($e);
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->with($update)->willThrowException($e);
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new short URL. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'Redis pub/sub']),
|
||||
'Error while trying to notify {name} with new short URL. {e}',
|
||||
['e' => $e, 'name' => 'Redis pub/sub'],
|
||||
);
|
||||
|
||||
$this->createListener()(new ShortUrlCreated($shortUrlId));
|
||||
|
|
|
@ -53,17 +53,16 @@ class NotifyVisitToRedisTest extends TestCase
|
|||
public function printsDebugMessageInCaseOfError(Throwable $e): void
|
||||
{
|
||||
$visitId = '123';
|
||||
$this->em->expects($this->once())->method('find')->with(
|
||||
$this->equalTo(Visit::class),
|
||||
$this->equalTo($visitId),
|
||||
)->willReturn(Visit::forBasePath(Visitor::emptyInstance()));
|
||||
$this->em->expects($this->once())->method('find')->with(Visit::class, $visitId)->willReturn(
|
||||
Visit::forBasePath(Visitor::emptyInstance()),
|
||||
);
|
||||
$this->updatesGenerator->expects($this->once())->method('newOrphanVisitUpdate')->with(
|
||||
$this->isInstanceOf(Visit::class),
|
||||
)->willReturn(Update::forTopicAndPayload('', []));
|
||||
$this->helper->expects($this->once())->method('publishUpdate')->withAnyParameters()->willThrowException($e);
|
||||
$this->logger->expects($this->once())->method('debug')->with(
|
||||
$this->equalTo('Error while trying to notify {name} with new visit. {e}'),
|
||||
$this->equalTo(['e' => $e, 'name' => 'Redis pub/sub']),
|
||||
'Error while trying to notify {name} with new visit. {e}',
|
||||
['e' => $e, 'name' => 'Redis pub/sub'],
|
||||
);
|
||||
|
||||
$this->createListener()(new VisitLocated($visitId));
|
||||
|
|
|
@ -39,8 +39,8 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||
|
||||
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willThrowException($e);
|
||||
$this->logger->expects($this->once())->method('error')->with(
|
||||
$this->equalTo('GeoLite2 database download failed. {e}'),
|
||||
$this->equalTo(['e' => $e]),
|
||||
'GeoLite2 database download failed. {e}',
|
||||
['e' => $e],
|
||||
);
|
||||
$this->logger->expects($this->never())->method('notice');
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch');
|
||||
|
@ -60,7 +60,7 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||
return GeolocationResult::DB_IS_UP_TO_DATE;
|
||||
},
|
||||
);
|
||||
$this->logger->expects($this->once())->method('notice')->with($this->equalTo($expectedMessage));
|
||||
$this->logger->expects($this->once())->method('notice')->with($expectedMessage);
|
||||
$this->logger->expects($this->never())->method('error');
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch');
|
||||
|
||||
|
@ -94,7 +94,7 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||
},
|
||||
);
|
||||
$logNoticeExpectation = $expectedMessage !== null ? $this->once() : $this->never();
|
||||
$this->logger->expects($logNoticeExpectation)->method('notice')->with($this->equalTo($expectedMessage));
|
||||
$this->logger->expects($logNoticeExpectation)->method('notice')->with($expectedMessage);
|
||||
$this->logger->expects($this->never())->method('error');
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch');
|
||||
|
||||
|
@ -123,7 +123,7 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||
): void {
|
||||
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturn($result);
|
||||
$this->eventDispatcher->expects($this->exactly($expectedDispatches))->method('dispatch')->with(
|
||||
$this->equalTo(new GeoLiteDbCreated()),
|
||||
new GeoLiteDbCreated(),
|
||||
);
|
||||
|
||||
($this->listener)();
|
||||
|
|
|
@ -41,7 +41,7 @@ class ImportedLinksProcessorTest extends TestCase
|
|||
{
|
||||
$this->em = $this->createMock(EntityManagerInterface::class);
|
||||
$this->repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$this->em->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn($this->repo);
|
||||
$this->em->method('getRepository')->with(ShortUrl::class)->willReturn($this->repo);
|
||||
|
||||
$this->shortCodeHelper = $this->createMock(ShortCodeUniquenessHelperInterface::class);
|
||||
$batchHelper = $this->createMock(DoctrineBatchHelperInterface::class);
|
||||
|
|
|
@ -38,14 +38,14 @@ class ShortCodeUniquenessHelperTest extends TestCase
|
|||
$expectedCalls = 3;
|
||||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->exactly($expectedCalls))->method('shortCodeIsInUseWithLock')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain('abc123', $expectedAuthority)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain('abc123', $expectedAuthority),
|
||||
)->willReturnCallback(function () use (&$callIndex, $expectedCalls) {
|
||||
$callIndex++;
|
||||
return $callIndex < $expectedCalls;
|
||||
});
|
||||
$this->em->expects($this->exactly($expectedCalls))->method('getRepository')->with(
|
||||
$this->equalTo(ShortUrl::class),
|
||||
)->willReturn($repo);
|
||||
$this->em->expects($this->exactly($expectedCalls))->method('getRepository')->with(ShortUrl::class)->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->shortUrl->method('getDomain')->willReturn($domain);
|
||||
$this->shortUrl->expects($this->exactly($expectedCalls - 1))->method('regenerateShortCode')->with();
|
||||
|
||||
|
@ -65,11 +65,9 @@ class ShortCodeUniquenessHelperTest extends TestCase
|
|||
{
|
||||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->once())->method('shortCodeIsInUseWithLock')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain('abc123')),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain('abc123'),
|
||||
)->willReturn(true);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
||||
$this->shortUrl->method('getDomain')->willReturn(null);
|
||||
$this->shortUrl->expects($this->never())->method('regenerateShortCode');
|
||||
|
||||
|
|
|
@ -29,11 +29,11 @@ class ShortUrlTitleResolutionHelperTest extends TestCase
|
|||
{
|
||||
$longUrl = 'http://foobar.com/12345/hello?foo=bar';
|
||||
$this->urlValidator->expects($this->exactly($validateWithTitleCallsNum))->method('validateUrlWithTitle')->with(
|
||||
$this->equalTo($longUrl),
|
||||
$longUrl,
|
||||
$this->isFalse(),
|
||||
);
|
||||
$this->urlValidator->expects($this->exactly($validateCallsNum))->method('validateUrl')->with(
|
||||
$this->equalTo($longUrl),
|
||||
$longUrl,
|
||||
$this->isFalse(),
|
||||
);
|
||||
|
||||
|
|
|
@ -48,13 +48,10 @@ class ShortUrlResolverTest extends TestCase
|
|||
$shortCode = $shortUrl->getShortCode();
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
|
||||
$this->repo->expects($this->once())->method('findOne')->with(
|
||||
$this->equalTo($identifier),
|
||||
$this->equalTo($apiKey?->spec()),
|
||||
)->willReturn($shortUrl);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$this->repo,
|
||||
$this->repo->expects($this->once())->method('findOne')->with($identifier, $apiKey?->spec())->willReturn(
|
||||
$shortUrl,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($this->repo);
|
||||
|
||||
$result = $this->urlResolver->resolveShortUrl($identifier, $apiKey);
|
||||
|
||||
|
@ -70,13 +67,8 @@ class ShortUrlResolverTest extends TestCase
|
|||
$shortCode = 'abc123';
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
|
||||
$this->repo->expects($this->once())->method('findOne')->with(
|
||||
$this->equalTo($identifier),
|
||||
$this->equalTo($apiKey?->spec()),
|
||||
)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$this->repo,
|
||||
);
|
||||
$this->repo->expects($this->once())->method('findOne')->with($identifier, $apiKey?->spec())->willReturn(null);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($this->repo);
|
||||
|
||||
$this->expectException(ShortUrlNotFoundException::class);
|
||||
|
||||
|
@ -90,11 +82,9 @@ class ShortUrlResolverTest extends TestCase
|
|||
$shortCode = $shortUrl->getShortCode();
|
||||
|
||||
$this->repo->expects($this->once())->method('findOneWithDomainFallback')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
)->willReturn($shortUrl);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$this->repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($this->repo);
|
||||
|
||||
$result = $this->urlResolver->resolveEnabledShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode));
|
||||
|
||||
|
@ -110,11 +100,9 @@ class ShortUrlResolverTest extends TestCase
|
|||
$shortCode = $shortUrl->getShortCode();
|
||||
|
||||
$this->repo->expects($this->once())->method('findOneWithDomainFallback')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode)),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||
)->willReturn($shortUrl);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$this->repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($this->repo);
|
||||
|
||||
$this->expectException(ShortUrlNotFoundException::class);
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class ShortUrlServiceTest extends TestCase
|
|||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->once())->method('findList')->willReturn($list);
|
||||
$repo->expects($this->once())->method('countList')->willReturn(count($list));
|
||||
$this->em->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn($repo);
|
||||
$this->em->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
||||
|
||||
$paginator = $this->service->listShortUrls(ShortUrlsParams::emptyInstance(), $apiKey);
|
||||
|
||||
|
@ -85,13 +85,13 @@ class ShortUrlServiceTest extends TestCase
|
|||
$shortUrl = ShortUrl::withLongUrl($originalLongUrl);
|
||||
|
||||
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with(
|
||||
$this->equalTo(ShortUrlIdentifier::fromShortCodeAndDomain('abc123')),
|
||||
$this->equalTo($apiKey),
|
||||
ShortUrlIdentifier::fromShortCodeAndDomain('abc123'),
|
||||
$apiKey,
|
||||
)->willReturn($shortUrl);
|
||||
|
||||
$this->titleResolutionHelper->expects($this->exactly($expectedValidateCalls))
|
||||
->method('processTitleAndValidateUrl')
|
||||
->with($this->equalTo($shortUrlEdit))
|
||||
->with($shortUrlEdit)
|
||||
->willReturn($shortUrlEdit);
|
||||
|
||||
$result = $this->service->updateShortUrl(
|
||||
|
|
|
@ -52,7 +52,7 @@ class UrlShortenerTest extends TestCase
|
|||
$longUrl = 'http://foobar.com/12345/hello?foo=bar';
|
||||
$meta = ShortUrlCreation::fromRawData(['longUrl' => $longUrl]);
|
||||
$this->titleResolutionHelper->expects($this->once())->method('processTitleAndValidateUrl')->with(
|
||||
$this->equalTo($meta),
|
||||
$meta,
|
||||
)->willReturnArgument(0);
|
||||
$this->shortCodeHelper->method('ensureShortCodeUniqueness')->willReturn(true);
|
||||
|
||||
|
@ -70,7 +70,7 @@ class UrlShortenerTest extends TestCase
|
|||
|
||||
$this->shortCodeHelper->expects($this->once())->method('ensureShortCodeUniqueness')->willReturn(false);
|
||||
$this->titleResolutionHelper->expects($this->once())->method('processTitleAndValidateUrl')->with(
|
||||
$this->equalTo($meta),
|
||||
$meta,
|
||||
)->willReturnArgument(0);
|
||||
|
||||
$this->expectException(NonUniqueSlugException::class);
|
||||
|
@ -86,9 +86,7 @@ class UrlShortenerTest extends TestCase
|
|||
{
|
||||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->once())->method('findOneMatching')->willReturn($expected);
|
||||
$this->em->expects($this->once())->method('getRepository')->with($this->equalTo(ShortUrl::class))->willReturn(
|
||||
$repo,
|
||||
);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
||||
$this->titleResolutionHelper->expects($this->never())->method('processTitleAndValidateUrl');
|
||||
$this->shortCodeHelper->method('ensureShortCodeUniqueness')->willReturn(true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue