Created chainIpLocationResolver

This commit is contained in:
Alejandro Celaya 2018-11-11 13:18:21 +01:00
parent d152e2ef9a
commit fd6d180eba
47 changed files with 288 additions and 176 deletions

View File

@ -38,7 +38,7 @@ class DisableKeyCommandTest extends TestCase
public function providedApiKeyIsDisabled()
{
$apiKey = 'abcd1234';
$this->apiKeyService->disable($apiKey)->shouldBeCalledTimes(1);
$this->apiKeyService->disable($apiKey)->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'api-key:disable',
'apiKey' => $apiKey,
@ -52,7 +52,7 @@ class DisableKeyCommandTest extends TestCase
{
$apiKey = 'abcd1234';
$this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'api-key:disable',

View File

@ -39,7 +39,7 @@ class GenerateKeyCommandTest extends TestCase
*/
public function noExpirationDateIsDefinedIfNotProvided()
{
$this->apiKeyService->create(null)->shouldBeCalledTimes(1)
$this->apiKeyService->create(null)->shouldBeCalledOnce()
->willReturn(new ApiKey());
$this->commandTester->execute([
'command' => 'api-key:generate',
@ -51,7 +51,7 @@ class GenerateKeyCommandTest extends TestCase
*/
public function expirationDateIsDefinedIfProvided()
{
$this->apiKeyService->create(Argument::type(Chronos::class))->shouldBeCalledTimes(1)
$this->apiKeyService->create(Argument::type(Chronos::class))->shouldBeCalledOnce()
->willReturn(new ApiKey());
$this->commandTester->execute([
'command' => 'api-key:generate',

View File

@ -41,7 +41,7 @@ class ListKeysCommandTest extends TestCase
new ApiKey(),
new ApiKey(),
new ApiKey(),
])->shouldBeCalledTimes(1);
])->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'api-key:list',
]);
@ -55,7 +55,7 @@ class ListKeysCommandTest extends TestCase
$this->apiKeyService->listKeys(true)->willReturn([
new ApiKey(),
new ApiKey(),
])->shouldBeCalledTimes(1);
])->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'api-key:list',
'--enabledOnly' => true,

View File

@ -50,7 +50,7 @@ class DeleteShortCodeCommandTest extends TestCase
$output = $this->commandTester->getDisplay();
$this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output);
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
/**
@ -67,7 +67,7 @@ class DeleteShortCodeCommandTest extends TestCase
$output = $this->commandTester->getDisplay();
$this->assertContains(sprintf('Provided short code "%s" could not be found.', $shortCode), $output);
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
/**
@ -117,6 +117,6 @@ class DeleteShortCodeCommandTest extends TestCase
$shortCode
), $output);
$this->assertContains('Short URL was not deleted.', $output);
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
}

View File

@ -60,11 +60,11 @@ class GeneratePreviewCommandTest extends TestCase
new ShortUrl('https://bar.com'),
new ShortUrl('http://baz.com/something'),
]);
$this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledTimes(1);
$this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledOnce();
$this->previewGenerator->generatePreview('http://foo.com')->shouldBeCalledTimes(1);
$this->previewGenerator->generatePreview('https://bar.com')->shouldBeCalledTimes(1);
$this->previewGenerator->generatePreview('http://baz.com/something')->shouldBeCalledTimes(1);
$this->previewGenerator->generatePreview('http://foo.com')->shouldBeCalledOnce();
$this->previewGenerator->generatePreview('https://bar.com')->shouldBeCalledOnce();
$this->previewGenerator->generatePreview('http://baz.com/something')->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:process-previews',
@ -82,7 +82,7 @@ class GeneratePreviewCommandTest extends TestCase
new ShortUrl('http://baz.com/something'),
];
$paginator = $this->createPaginator($items);
$this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledTimes(1);
$this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledOnce();
$this->previewGenerator->generatePreview(Argument::any())->willThrow(PreviewGenerationException::class)
->shouldBeCalledTimes(count($items));

View File

@ -47,7 +47,7 @@ class GenerateShortcodeCommandTest extends TestCase
->willReturn(
(new ShortUrl(''))->setShortCode('abc123')
)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:generate',
@ -63,7 +63,7 @@ class GenerateShortcodeCommandTest extends TestCase
public function exceptionWhileParsingLongUrlOutputsError()
{
$this->urlShortener->urlToShortCode(Argument::cetera())->willThrow(new InvalidUrlException())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:generate',

View File

@ -46,7 +46,7 @@ class GetVisitsCommandTest extends TestCase
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, new DateRange(null, null))->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:visits',
@ -64,7 +64,7 @@ class GetVisitsCommandTest extends TestCase
$endDate = '2016-02-01';
$this->visitsTracker->info($shortCode, new DateRange(Chronos::parse($startDate), Chronos::parse($endDate)))
->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:visits',
@ -84,7 +84,7 @@ class GetVisitsCommandTest extends TestCase
(new Visit(new ShortUrl(''), new Visitor('bar', 'foo', '')))->setVisitLocation(
new VisitLocation(['country_name' => 'Spain'])
),
])->shouldBeCalledTimes(1);
])->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:visits',

View File

@ -41,7 +41,7 @@ class ListShortcodesCommandTest extends TestCase
public function noInputCallsListJustOnce()
{
$this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->setInputs(['n']);
$this->commandTester->execute(['command' => 'shortcode:list']);
@ -78,7 +78,7 @@ class ListShortcodesCommandTest extends TestCase
}
$this->shortUrlService->listShortUrls(Argument::cetera())->willReturn(new Paginator(new ArrayAdapter($data)))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->setInputs(['n']);
$this->commandTester->execute(['command' => 'shortcode:list']);
@ -91,7 +91,7 @@ class ListShortcodesCommandTest extends TestCase
{
$page = 5;
$this->shortUrlService->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->setInputs(['y']);
$this->commandTester->execute([
@ -106,7 +106,7 @@ class ListShortcodesCommandTest extends TestCase
public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
{
$this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->setInputs(['y']);
$this->commandTester->execute([

View File

@ -45,7 +45,7 @@ class ResolveUrlCommandTest extends TestCase
$expectedUrl = 'http://domain.com/foo/bar';
$shortUrl = new ShortUrl($expectedUrl);
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:parse',
@ -62,7 +62,7 @@ class ResolveUrlCommandTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:parse',
@ -79,7 +79,7 @@ class ResolveUrlCommandTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->commandTester->execute([
'command' => 'shortcode:parse',

View File

@ -62,7 +62,7 @@ class ProcessVisitsCommandTest extends TestCase
new Visit($shortUrl, new Visitor('', '', '12.34.56.78')),
];
$this->visitService->getUnlocatedVisits()->willReturn($visits)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->visitService->saveVisit(Argument::any())->shouldBeCalledTimes(count($visits));
$this->ipResolver->resolveIpLocation(Argument::any())->willReturn([])
@ -94,7 +94,7 @@ class ProcessVisitsCommandTest extends TestCase
new Visit($shortUrl, new Visitor('', '', null)),
];
$this->visitService->getUnlocatedVisits()->willReturn($visits)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->visitService->saveVisit(Argument::any())->shouldBeCalledTimes(count($visits) - 4);
$this->ipResolver->resolveIpLocation(Argument::any())->willReturn([])

View File

@ -36,6 +36,8 @@ return [
IpGeolocation\IpApiLocationResolver::class => ConfigAbstractFactory::class,
IpGeolocation\GeoLite2LocationResolver::class => ConfigAbstractFactory::class,
IpGeolocation\ChainIpLocationResolver::class => ConfigAbstractFactory::class,
Service\PreviewGenerator::class => ConfigAbstractFactory::class,
],
'aliases' => [
@ -57,8 +59,14 @@ return [
Template\Extension\TranslatorExtension::class => ['translator'],
Middleware\LocaleMiddleware::class => ['translator'],
IpGeolocation\IpApiLocationResolver::class => ['httpClient'],
IpGeolocation\GeoLite2LocationResolver::class => [Reader::class],
IpGeolocation\ChainIpLocationResolver::class => [
IpGeolocation\GeoLite2LocationResolver::class,
IpGeolocation\IpApiLocationResolver::class,
],
Service\PreviewGenerator::class => [
Image\ImageBuilder::class,
Filesystem::class,

View File

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\IpGeolocation;
use Shlinkio\Shlink\Common\Exception\WrongIpException;
class ChainIpLocationResolver implements IpLocationResolverInterface
{
/**
* @var IpLocationResolverInterface[]
*/
private $resolvers;
public function __construct(IpLocationResolverInterface ...$resolvers)
{
$this->resolvers = $resolvers;
}
/**
* @param string $ipAddress
* @return array
* @throws WrongIpException
*/
public function resolveIpLocation(string $ipAddress): array
{
$error = null;
foreach ($this->resolvers as $resolver) {
try {
return $resolver->resolveIpLocation($ipAddress);
} catch (WrongIpException $e) {
$error = $e;
}
}
// If this instruction is reached, it means no resolver was capable of resolving the address
throw WrongIpException::fromIpAddress($ipAddress, $error);
}
}

View File

@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\IpGeolocation;
use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\Model\City;
use MaxMind\Db\Reader\InvalidDatabaseException;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2LocationResolver;
class GeoLite2LocationResolverTest extends TestCase
{
/**
* @var GeoLite2LocationResolver
*/
private $resolver;
/**
* @var ObjectProphecy
*/
private $reader;
public function setUp()
{
$this->reader = $this->prophesize(Reader::class);
$this->resolver = new GeoLite2LocationResolver($this->reader->reveal());
}
/**
* @test
* @dataProvider provideReaderExceptions
*/
public function exceptionIsThrownIfReaderThrowsException(string $e, string $message)
{
$ipAddress = '1.2.3.4';
$cityMethod = $this->reader->city($ipAddress)->willThrow($e);
$this->expectException(WrongIpException::class);
$this->expectExceptionMessage($message);
$cityMethod->shouldBeCalledOnce();
$this->resolver->resolveIpLocation($ipAddress);
}
public function provideReaderExceptions(): array
{
return [
[AddressNotFoundException::class, 'Provided IP "1.2.3.4" is invalid'],
[InvalidDatabaseException::class, 'Provided GeoLite2 db file is invalid'],
];
}
/**
* @test
*/
public function resolvedCityIsProperlyMapped()
{
$ipAddress = '1.2.3.4';
$city = new City([]);
$cityMethod = $this->reader->city($ipAddress)->willReturn($city);
$result = $this->resolver->resolveIpLocation($ipAddress);
$this->assertEquals([
'country_code' => '',
'country_name' => '',
'region_name' => '',
'city' => '',
'latitude' => '',
'longitude' => '',
'time_zone' => '',
], $result);
$cityMethod->shouldHaveBeenCalledOnce();
}
}

View File

@ -52,7 +52,7 @@ class IpApiLocationResolverTest extends TestCase
$response->getBody()->rewind();
$this->client->get('http://ip-api.com/json/1.2.3.4')->willReturn($response)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->assertEquals($expected, $this->ipResolver->resolveIpLocation('1.2.3.4'));
}
@ -63,23 +63,7 @@ class IpApiLocationResolverTest extends TestCase
public function guzzleExceptionThrowsShlinkException()
{
$this->client->get('http://ip-api.com/json/1.2.3.4')->willThrow(new TransferException())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->ipResolver->resolveIpLocation('1.2.3.4');
}
/**
* @test
*/
public function getApiIntervalReturnsExpectedValue()
{
$this->assertEquals(65, $this->ipResolver->getApiInterval());
}
/**
* @test
*/
public function getApiLimitReturnsExpectedValue()
{
$this->assertEquals(145, $this->ipResolver->getApiLimit());
}
}

View File

@ -30,7 +30,7 @@ class PaginableRepositoryAdapterTest extends TestCase
*/
public function getItemsFallbacksToFindList()
{
$this->repo->findList(10, 5, 'search', ['foo', 'bar'], 'order')->shouldBeCalledTimes(1);
$this->repo->findList(10, 5, 'search', ['foo', 'bar'], 'order')->shouldBeCalledOnce();
$this->adapter->getItems(5, 10);
}
@ -39,7 +39,7 @@ class PaginableRepositoryAdapterTest extends TestCase
*/
public function countFallbacksToCountList()
{
$this->repo->countList('search', ['foo', 'bar'])->shouldBeCalledTimes(1);
$this->repo->countList('search', ['foo', 'bar'])->shouldBeCalledOnce();
$this->adapter->count();
}
}

View File

@ -50,7 +50,7 @@ class PreviewGeneratorTest extends TestCase
{
$url = 'http://foo.com';
$this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(true)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->image->saveAs(Argument::cetera())->shouldBeCalledTimes(0);
$this->assertEquals(sprintf('dir/preview_%s.png', urlencode($url)), $this->generator->generatePreview($url));
}
@ -65,10 +65,10 @@ class PreviewGeneratorTest extends TestCase
$expectedPath = 'dir/' . $cacheId;
$this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(false)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->image->saveAs($expectedPath)->shouldBeCalledTimes(1);
$this->image->getError()->willReturn('')->shouldBeCalledTimes(1);
$this->image->saveAs($expectedPath)->shouldBeCalledOnce();
$this->image->getError()->willReturn('')->shouldBeCalledOnce();
$this->assertEquals($expectedPath, $this->generator->generatePreview($url));
}
@ -83,10 +83,10 @@ class PreviewGeneratorTest extends TestCase
$expectedPath = 'dir/' . $cacheId;
$this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(false)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->image->saveAs($expectedPath)->shouldBeCalledTimes(1);
$this->image->getError()->willReturn('Error!!')->shouldBeCalledTimes(1);
$this->image->saveAs($expectedPath)->shouldBeCalledOnce();
$this->image->getError()->willReturn('Error!!')->shouldBeCalledOnce();
$this->generator->generatePreview($url);
}

View File

@ -28,8 +28,8 @@ class TranslatorExtensionTest extends TestCase
{
$engine = $this->prophesize(Engine::class);
$engine->registerFunction('translate', Argument::type('callable'))->shouldBeCalledTimes(1);
$engine->registerFunction('translate_plural', Argument::type('callable'))->shouldBeCalledTimes(1);
$engine->registerFunction('translate', Argument::type('callable'))->shouldBeCalledOnce();
$engine->registerFunction('translate_plural', Argument::type('callable'))->shouldBeCalledOnce();
$funcs = $this->extension->register($engine->reveal());
}

View File

@ -51,8 +51,8 @@ class PixelActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(
new ShortUrl('http://domain.com/foo/bar')
)->shouldBeCalledTimes(1);
$this->visitTracker->track(Argument::cetera())->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());

View File

@ -50,9 +50,9 @@ class PreviewActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->handle(Argument::cetera())->shouldBeCalledTimes(1)
$delegate->handle(Argument::cetera())->shouldBeCalledOnce()
->willReturn(new Response());
$this->action->process(
@ -70,8 +70,8 @@ class PreviewActionTest extends TestCase
$url = 'foobar.com';
$shortUrl = new ShortUrl($url);
$path = __FILE__;
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)->shouldBeCalledTimes(1);
$this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledTimes(1);
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)->shouldBeCalledOnce();
$this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce();
$resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@ -89,7 +89,7 @@ class PreviewActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */
$process = $delegate->handle(Argument::any())->willReturn(new Response());
@ -99,6 +99,6 @@ class PreviewActionTest extends TestCase
$delegate->reveal()
);
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
}

View File

@ -46,7 +46,7 @@ class QrCodeActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle(Argument::any())->willReturn(new Response());
@ -55,7 +55,7 @@ class QrCodeActionTest extends TestCase
$delegate->reveal()
);
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@ -65,7 +65,7 @@ class QrCodeActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */
$process = $delegate->handle(Argument::any())->willReturn(new Response());
@ -75,7 +75,7 @@ class QrCodeActionTest extends TestCase
$delegate->reveal()
);
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@ -85,7 +85,7 @@ class QrCodeActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(new ShortUrl(''))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$delegate = $this->prophesize(RequestHandlerInterface::class);
$resp = $this->action->process(

View File

@ -59,8 +59,8 @@ class RedirectActionTest extends TestCase
$expectedUrl = 'http://domain.com/foo/bar';
$shortUrl = new ShortUrl($expectedUrl);
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)
->shouldBeCalledTimes(1);
$this->visitTracker->track(Argument::cetera())->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
@ -78,7 +78,7 @@ class RedirectActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldNotBeCalled();
$handler = $this->prophesize(RequestHandlerInterface::class);
@ -87,7 +87,7 @@ class RedirectActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$this->action->process($request, $handler->reveal());
$handle->shouldHaveBeenCalledTimes(1);
$handle->shouldHaveBeenCalledOnce();
}
/**
@ -111,7 +111,7 @@ class RedirectActionTest extends TestCase
$this->assertEquals(302, $resp->getStatusCode());
$this->assertEquals('https://shlink.io', $resp->getHeaderLine('Location'));
$shortCodeToUrl->shouldHaveBeenCalledTimes(1);
$shortCodeToUrl->shouldHaveBeenCalledOnce();
$handle->shouldNotHaveBeenCalled();
}
@ -124,7 +124,7 @@ class RedirectActionTest extends TestCase
$expectedUrl = 'http://domain.com/foo/bar';
$shortUrl = new ShortUrl($expectedUrl);
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldNotBeCalled();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)

View File

@ -36,7 +36,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
public function noCachedPathFallsBackToNextMiddleware()
{
$delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledTimes(1);
$delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce();
$this->middleware->process(ServerRequestFactory::fromGlobals()->withUri(
new Uri('/foo/bar')

View File

@ -70,8 +70,8 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode('abc123', true);
$remove->shouldHaveBeenCalledTimes(1);
$flush->shouldHaveBeenCalledTimes(1);
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();
}
/**
@ -86,8 +86,8 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode('abc123');
$remove->shouldHaveBeenCalledTimes(1);
$flush->shouldHaveBeenCalledTimes(1);
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();
}
/**
@ -102,8 +102,8 @@ class DeleteShortUrlServiceTest extends TestCase
$service->deleteByShortCode('abc123');
$remove->shouldHaveBeenCalledTimes(1);
$flush->shouldHaveBeenCalledTimes(1);
$remove->shouldHaveBeenCalledOnce();
$flush->shouldHaveBeenCalledOnce();
}
private function createService(bool $checkVisitsThreshold = true, int $visitsThreshold = 5): DeleteShortUrlService

View File

@ -49,8 +49,8 @@ class ShortUrlServiceTest extends TestCase
];
$repo = $this->prophesize(ShortUrlRepository::class);
$repo->findList(Argument::cetera())->willReturn($list)->shouldBeCalledTimes(1);
$repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledTimes(1);
$repo->findList(Argument::cetera())->willReturn($list)->shouldBeCalledOnce();
$repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledOnce();
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$list = $this->service->listShortUrls();
@ -65,7 +65,7 @@ class ShortUrlServiceTest extends TestCase
$shortCode = 'abc123';
$repo = $this->prophesize(ShortUrlRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(null)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$this->expectException(InvalidShortCodeException::class);
@ -78,16 +78,16 @@ class ShortUrlServiceTest extends TestCase
public function providedTagsAreGetFromRepoAndSetToTheShortUrl()
{
$shortUrl = $this->prophesize(ShortUrl::class);
$shortUrl->setTags(Argument::any())->shouldBeCalledTimes(1);
$shortUrl->setTags(Argument::any())->shouldBeCalledOnce();
$shortCode = 'abc123';
$repo = $this->prophesize(ShortUrlRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl->reveal())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$tagRepo = $this->prophesize(EntityRepository::class);
$tagRepo->findOneBy(['name' => 'foo'])->willReturn(new Tag('foo'))->shouldbeCalledTimes(1);
$tagRepo->findOneBy(['name' => 'bar'])->willReturn(null)->shouldbeCalledTimes(1);
$tagRepo->findOneBy(['name' => 'foo'])->willReturn(new Tag('foo'))->shouldBeCalledOnce();
$tagRepo->findOneBy(['name' => 'bar'])->willReturn(null)->shouldBeCalledOnce();
$this->em->getRepository(Tag::class)->willReturn($tagRepo->reveal());
$this->service->setTagsByShortCode($shortCode, ['foo', 'bar']);

View File

@ -98,8 +98,8 @@ class UrlShortenerTest extends TestCase
$conn = $this->prophesize(Connection::class);
$conn->isTransactionActive()->willReturn(true);
$this->em->getConnection()->willReturn($conn->reveal());
$this->em->rollback()->shouldBeCalledTimes(1);
$this->em->close()->shouldBeCalledTimes(1);
$this->em->rollback()->shouldBeCalledOnce();
$this->em->close()->shouldBeCalledOnce();
$this->em->flush()->willThrow(new ORMException());
$this->urlShortener->urlToShortCode(new Uri('http://foobar.com/12345/hello?foo=bar'));
@ -135,7 +135,7 @@ class UrlShortenerTest extends TestCase
'custom-slug'
);
$slugify->shouldHaveBeenCalledTimes(1);
$slugify->shouldHaveBeenCalledOnce();
}
/**
@ -153,8 +153,8 @@ class UrlShortenerTest extends TestCase
/** @var MethodProphecy $getRepo */
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$slugify->shouldBeCalledTimes(1);
$findBySlug->shouldBeCalledTimes(1);
$slugify->shouldBeCalledOnce();
$findBySlug->shouldBeCalledOnce();
$getRepo->shouldBeCalled();
$this->expectException(NonUniqueSlugException::class);

View File

@ -35,8 +35,8 @@ class VisitServiceTest extends TestCase
public function saveVisitsPersistsProvidedVisit()
{
$visit = new Visit(new ShortUrl(''), Visitor::emptyInstance());
$this->em->persist($visit)->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->persist($visit)->shouldBeCalledOnce();
$this->em->flush()->shouldBeCalledOnce();
$this->visitService->saveVisit($visit);
}
@ -46,8 +46,8 @@ class VisitServiceTest extends TestCase
public function getUnlocatedVisitsFallbacksToRepository()
{
$repo = $this->prophesize(VisitRepository::class);
$repo->findUnlocatedVisits()->shouldBeCalledTimes(1);
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
$repo->findUnlocatedVisits()->shouldBeCalledOnce();
$this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
$this->visitService->getUnlocatedVisits();
}
}

View File

@ -40,9 +40,9 @@ class VisitsTrackerTest extends TestCase
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl(''));
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
$this->em->persist(Argument::any())->shouldBeCalledTimes(1);
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledTimes(1);
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
$this->em->persist(Argument::any())->shouldBeCalledOnce();
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledOnce();
$this->visitsTracker->track($shortCode, Visitor::emptyInstance());
}
@ -57,13 +57,13 @@ class VisitsTrackerTest extends TestCase
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl(''));
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
$this->em->persist(Argument::any())->will(function ($args) use ($test) {
/** @var Visit $visit */
$visit = $args[0];
$test->assertEquals('4.3.2.0', $visit->getRemoteAddr());
})->shouldBeCalledTimes(1);
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledTimes(1);
})->shouldBeCalledOnce();
$this->em->flush(Argument::type(Visit::class))->shouldBeCalledOnce();
$this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1'));
}
@ -77,7 +77,7 @@ class VisitsTrackerTest extends TestCase
$shortUrl = new ShortUrl('http://domain.com/foo/bar');
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl);
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1);
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
$list = [
new Visit(new ShortUrl(''), Visitor::emptyInstance()),
@ -85,7 +85,7 @@ class VisitsTrackerTest extends TestCase
];
$repo2 = $this->prophesize(VisitRepository::class);
$repo2->findVisitsByShortUrl($shortUrl, null)->willReturn($list);
$this->em->getRepository(Visit::class)->willReturn($repo2->reveal())->shouldBeCalledTimes(1);
$this->em->getRepository(Visit::class)->willReturn($repo2->reveal())->shouldBeCalledOnce();
$this->assertEquals($list, $this->visitsTracker->info($shortCode));
}

View File

@ -81,7 +81,7 @@ class InstallCommandTest extends TestCase
*/
public function generatedConfigIsProperlyPersisted()
{
$this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1);
$this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledOnce();
$this->commandTester->execute([]);
}
@ -97,8 +97,8 @@ class InstallCommandTest extends TestCase
$this->commandTester->execute([]);
$appConfigExists->shouldHaveBeenCalledTimes(1);
$appConfigRemove->shouldHaveBeenCalledTimes(1);
$appConfigExists->shouldHaveBeenCalledOnce();
$appConfigRemove->shouldHaveBeenCalledOnce();
}
/**
@ -115,8 +115,8 @@ class InstallCommandTest extends TestCase
$this->commandTester->execute([]);
$appConfigExists->shouldHaveBeenCalledTimes(1);
$appConfigRemove->shouldHaveBeenCalledTimes(1);
$appConfigExists->shouldHaveBeenCalledOnce();
$appConfigRemove->shouldHaveBeenCalledOnce();
$configToFile->shouldNotHaveBeenCalled();
}

View File

@ -51,7 +51,7 @@ class ApplicationConfigCustomizerTest extends TestCase
'CHECK_VISITS_THRESHOLD' => false,
], $config->getApp());
$ask->shouldHaveBeenCalledTimes(2);
$confirm->shouldHaveBeenCalledTimes(1);
$confirm->shouldHaveBeenCalledOnce();
}
/**
@ -77,7 +77,7 @@ class ApplicationConfigCustomizerTest extends TestCase
'VISITS_THRESHOLD' => 20,
], $config->getApp());
$ask->shouldHaveBeenCalledTimes(3);
$confirm->shouldHaveBeenCalledTimes(1);
$confirm->shouldHaveBeenCalledOnce();
}
/**
@ -101,7 +101,7 @@ class ApplicationConfigCustomizerTest extends TestCase
'CHECK_VISITS_THRESHOLD' => true,
'VISITS_THRESHOLD' => 20,
], $config->getApp());
$ask->shouldHaveBeenCalledTimes(1);
$ask->shouldHaveBeenCalledOnce();
}
/**

View File

@ -55,7 +55,7 @@ class DatabaseConfigCustomizerTest extends TestCase
'HOST' => 'param',
'PORT' => 'param',
], $config->getDatabase());
$choice->shouldHaveBeenCalledTimes(1);
$choice->shouldHaveBeenCalledOnce();
$ask->shouldHaveBeenCalledTimes(5);
}
@ -137,6 +137,6 @@ class DatabaseConfigCustomizerTest extends TestCase
$this->assertEquals([
'DRIVER' => 'pdo_sqlite',
], $config->getDatabase());
$copy->shouldHaveBeenCalledTimes(1);
$copy->shouldHaveBeenCalledOnce();
}
}

View File

@ -63,7 +63,7 @@ class LanguageConfigCustomizerTest extends TestCase
'DEFAULT' => 'en',
'CLI' => 'es',
], $config->getLanguage());
$choice->shouldHaveBeenCalledTimes(1);
$choice->shouldHaveBeenCalledOnce();
}
/**

View File

@ -50,7 +50,7 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'NOT_FOUND_REDIRECT_TO' => 'asked',
], $config->getUrlShortener());
$ask->shouldHaveBeenCalledTimes(3);
$choice->shouldHaveBeenCalledTimes(1);
$choice->shouldHaveBeenCalledOnce();
$confirm->shouldHaveBeenCalledTimes(2);
}
@ -81,8 +81,8 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'NOT_FOUND_REDIRECT_TO' => 'foo',
], $config->getUrlShortener());
$choice->shouldNotHaveBeenCalled();
$ask->shouldHaveBeenCalledTimes(1);
$confirm->shouldHaveBeenCalledTimes(1);
$ask->shouldHaveBeenCalledOnce();
$confirm->shouldHaveBeenCalledOnce();
}
/**
@ -146,6 +146,6 @@ class UrlShortenerConfigCustomizerTest extends TestCase
'ENABLE_NOT_FOUND_REDIRECTION' => false,
], $config->getUrlShortener());
$ask->shouldNotHaveBeenCalled();
$confirm->shouldHaveBeenCalledTimes(1);
$confirm->shouldHaveBeenCalledOnce();
}
}

View File

@ -57,7 +57,7 @@ class AuthenticateActionTest extends TestCase
public function properApiKeyReturnsTokenInResponse()
{
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setId('5'))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',
@ -75,7 +75,7 @@ class AuthenticateActionTest extends TestCase
public function invalidApiKeyReturnsErrorResponse()
{
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->disable())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',

View File

@ -56,7 +56,7 @@ class CreateShortUrlActionTest extends TestCase
->willReturn(
(new ShortUrl(''))->setShortCode('abc123')
)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@ -73,7 +73,7 @@ class CreateShortUrlActionTest extends TestCase
{
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
->willThrow(InvalidUrlException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@ -95,7 +95,7 @@ class CreateShortUrlActionTest extends TestCase
null,
'foo',
Argument::cetera()
)->willThrow(NonUniqueSlugException::class)->shouldBeCalledTimes(1);
)->willThrow(NonUniqueSlugException::class)->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@ -113,7 +113,7 @@ class CreateShortUrlActionTest extends TestCase
{
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',

View File

@ -43,7 +43,7 @@ class DeleteShortUrlActionTest extends TestCase
$resp = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals(204, $resp->getStatusCode());
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
/**
@ -60,7 +60,7 @@ class DeleteShortUrlActionTest extends TestCase
$this->assertEquals($statusCode, $resp->getStatusCode());
$this->assertEquals($error, $payload['error']);
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
public function provideExceptions(): array

View File

@ -45,7 +45,7 @@ class EditShortUrlTagsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
@ -61,7 +61,7 @@ class EditShortUrlTagsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl(''))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')

View File

@ -40,7 +40,7 @@ class ListShortUrlsActionTest extends TestCase
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
@ -55,7 +55,7 @@ class ListShortUrlsActionTest extends TestCase
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,

View File

@ -40,7 +40,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@ -56,7 +56,7 @@ class ResolveShortUrlActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(
new ShortUrl('http://domain.com/foo/bar')
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@ -71,7 +71,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@ -86,7 +86,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);

View File

@ -39,7 +39,7 @@ class GetVisitsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(200, $response->getStatusCode());
@ -53,7 +53,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
InvalidArgumentException::class
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(404, $response->getStatusCode());
@ -67,7 +67,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
Exception::class
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(500, $response->getStatusCode());
@ -81,7 +81,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, new DateRange(null, Chronos::parse('2016-01-01 00:00:00')))
->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)

View File

@ -37,7 +37,7 @@ class ApiKeyHeaderPluginTest extends TestCase
{
$apiKey = 'abc-ABC';
$check = $this->apiKeyService->check($apiKey)->willReturn(false);
$check->shouldBeCalledTimes(1);
$check->shouldBeCalledOnce();
$this->expectException(VerifyAuthenticationException::class);
$this->expectExceptionMessage('Provided API key does not exist or is invalid');
@ -55,7 +55,7 @@ class ApiKeyHeaderPluginTest extends TestCase
$this->plugin->verify($this->createRequest($apiKey));
$check->shouldHaveBeenCalledTimes(1);
$check->shouldHaveBeenCalledOnce();
}
/**

View File

@ -90,7 +90,7 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->plugin->verify($request);
$jwtVerify->shouldHaveBeenCalledTimes(1);
$jwtVerify->shouldHaveBeenCalledOnce();
}
/**
@ -107,7 +107,7 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->plugin->verify($request);
$jwtVerify->shouldHaveBeenCalledTimes(1);
$jwtVerify->shouldHaveBeenCalledOnce();
}
/**
@ -126,6 +126,6 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->assertTrue($response->hasHeader(AuthorizationHeaderPlugin::HEADER_NAME));
$this->assertEquals('Bearer DEF-def', $response->getHeaderLine(AuthorizationHeaderPlugin::HEADER_NAME));
$jwtRefresh->shouldHaveBeenCalledTimes(1);
$jwtRefresh->shouldHaveBeenCalledOnce();
}
}

View File

@ -64,7 +64,7 @@ class RequestToAuthPluginTest extends TestCase
$this->requestToPlugin->fromRequest($request);
$getPlugin->shouldHaveBeenCalledTimes(1);
$getPlugin->shouldHaveBeenCalledOnce();
}
public function provideHeaders(): array

View File

@ -68,7 +68,7 @@ class AuthenticationMiddlewareTest extends TestCase
$this->middleware->process($request, $handler->reveal());
$handle->shouldHaveBeenCalledTimes(1);
$handle->shouldHaveBeenCalledOnce();
$fromRequest->shouldNotHaveBeenCalled();
}
@ -116,7 +116,7 @@ class AuthenticationMiddlewareTest extends TestCase
'Expected one of the following authentication headers, but none were provided, ["%s"]',
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
), $payload['message']);
$fromRequest->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledOnce();
}
public function provideExceptions(): array
@ -150,8 +150,8 @@ class AuthenticationMiddlewareTest extends TestCase
$this->assertEquals('the_error', $payload['error']);
$this->assertEquals('the_message', $payload['message']);
$verify->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledTimes(1);
$verify->shouldHaveBeenCalledOnce();
$fromRequest->shouldHaveBeenCalledOnce();
}
/**
@ -176,10 +176,10 @@ class AuthenticationMiddlewareTest extends TestCase
$response = $this->middleware->process($request, $handler->reveal());
$this->assertSame($response, $newResponse);
$verify->shouldHaveBeenCalledTimes(1);
$update->shouldHaveBeenCalledTimes(1);
$handle->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledTimes(1);
$verify->shouldHaveBeenCalledOnce();
$update->shouldHaveBeenCalledOnce();
$handle->shouldHaveBeenCalledOnce();
$fromRequest->shouldHaveBeenCalledOnce();
}
private function getDummyMiddleware(): MiddlewareInterface

View File

@ -38,7 +38,7 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@ -70,7 +70,7 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@ -101,6 +101,6 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
}

View File

@ -34,7 +34,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function nonCrossDomainRequestsAreNotAffected()
{
$originalResponse = new Response();
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->delegate->reveal());
$this->assertSame($originalResponse, $response);
@ -50,7 +50,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function anyRequestIncludesTheAllowAccessHeader()
{
$originalResponse = new Response();
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'),
@ -70,7 +70,7 @@ class CrossDomainMiddlewareTest extends TestCase
{
$originalResponse = new Response();
$request = ServerRequestFactory::fromGlobals()->withMethod('OPTIONS')->withHeader('Origin', 'local');
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process($request, $this->delegate->reveal());
$this->assertNotSame($originalResponse, $response);

View File

@ -45,6 +45,6 @@ class ShortCodePathMiddlewareTest extends TestCase
$this->middleware->process($request->reveal(), $this->requestHandler->reveal());
$withUri->shouldHaveBeenCalledTimes(1);
$withUri->shouldHaveBeenCalledOnce();
}
}

View File

@ -34,8 +34,8 @@ class ApiKeyServiceTest extends TestCase
*/
public function keyIsProperlyCreated()
{
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledOnce();
$key = $this->service->create();
$this->assertNull($key->getExpirationDate());
@ -46,8 +46,8 @@ class ApiKeyServiceTest extends TestCase
*/
public function keyIsProperlyCreatedWithExpirationDate()
{
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledOnce();
$date = Chronos::parse('2030-01-01');
$key = $this->service->create($date);
@ -61,7 +61,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(null)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@ -76,7 +76,7 @@ class ApiKeyServiceTest extends TestCase
$key->disable();
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@ -90,7 +90,7 @@ class ApiKeyServiceTest extends TestCase
$key = new ApiKey(Chronos::now()->subDay());
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@ -103,7 +103,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(new ApiKey())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertTrue($this->service->check('12345'));
@ -117,7 +117,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(null)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->disable('12345');
@ -131,10 +131,10 @@ class ApiKeyServiceTest extends TestCase
$key = new ApiKey();
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->assertTrue($key->isEnabled());
$returnedKey = $this->service->disable('12345');
@ -149,7 +149,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findBy([])->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->listKeys();
@ -162,7 +162,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findBy(['enabled' => true])->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->listKeys(true);