Fixed all phpstan inspections on tests

This commit is contained in:
Alejandro Celaya 2022-10-24 20:11:25 +02:00
parent 1650499a38
commit 85e18a4754
10 changed files with 36 additions and 19 deletions

View File

@ -38,7 +38,7 @@ class RoleResolverTest extends TestCase
): void {
$this->domainService->expects($this->exactly($expectedDomainCalls))->method('getOrCreate')->with(
'example.com',
)->willReturn(Domain::withAuthority('example.com')->setId('1'));
)->willReturn($this->domainWithId(Domain::withAuthority('example.com')));
$result = $this->resolver->determineRoles($input);
@ -47,7 +47,7 @@ class RoleResolverTest extends TestCase
public function provideRoles(): iterable
{
$domain = Domain::withAuthority('example.com')->setId('1');
$domain = $this->domainWithId(Domain::withAuthority('example.com'));
$buildInput = function (array $definition): InputInterface {
$input = $this->createStub(InputInterface::class);
$input->method('getOption')->willReturnMap(
@ -113,4 +113,10 @@ class RoleResolverTest extends TestCase
$this->resolver->determineRoles($input);
}
private function domainWithId(Domain $domain): Domain
{
$domain->setId('1');
return $domain;
}
}

View File

@ -86,12 +86,12 @@ class ListKeysCommandTest extends TestCase
$apiKey1 = ApiKey::create(),
$apiKey2 = $this->apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]),
$apiKey3 = $this->apiKeyWithRoles(
[RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1'))],
[RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com')))],
),
$apiKey4 = ApiKey::create(),
$apiKey5 = $this->apiKeyWithRoles([
RoleDefinition::forAuthoredShortUrls(),
RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1')),
RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com'))),
]),
$apiKey6 = ApiKey::create(),
],
@ -150,4 +150,10 @@ class ListKeysCommandTest extends TestCase
return $apiKey;
}
private function domainWithId(Domain $domain): Domain
{
$domain->setId('1');
return $domain;
}
}

View File

@ -37,7 +37,10 @@ class CreateShortUrlCommandTest extends TestCase
$command = new CreateShortUrlCommand(
$this->urlShortener,
$this->stringifier,
new UrlShortenerOptions(domain: ['hostname' => self::DEFAULT_DOMAIN], defaultShortCodesLength: 5),
new UrlShortenerOptions(
domain: ['hostname' => self::DEFAULT_DOMAIN, 'schema' => ''],
defaultShortCodesLength: 5,
),
);
$this->commandTester = $this->testerForCommand($command);
}

View File

@ -31,8 +31,6 @@ class GeolocationDbUpdaterTest extends TestCase
{
$this->dbUpdater = $this->createMock(DbUpdaterInterface::class);
$this->geoLiteDbReader = $this->createMock(Reader::class);
$this->trackingOptions = new TrackingOptions();
$this->lock = $this->createMock(Lock\LockInterface::class);
$this->lock->method('acquire')->with($this->isTrue())->willReturn(true);
}

View File

@ -115,8 +115,10 @@ class QrCodeActionTest extends TestCase
$delegate = $this->createMock(RequestHandlerInterface::class);
$resp = $this->action($defaultOptions)->process($req->withAttribute('shortCode', $code), $delegate);
[$size] = getimagesizefromstring($resp->getBody()->__toString());
$result = getimagesizefromstring($resp->getBody()->__toString());
self::assertNotFalse($result);
[$size] = $result;
self::assertEquals($expectedSize, $size);
}
@ -207,8 +209,9 @@ class QrCodeActionTest extends TestCase
$resp = $this->action($defaultOptions)->process($req, $delegate);
$image = imagecreatefromstring($resp->getBody()->__toString());
$color = imagecolorat($image, 1, 1);
self::assertNotFalse($image);
$color = imagecolorat($image, 1, 1);
self::assertEquals($color, $expectedColor);
}

View File

@ -48,8 +48,10 @@ class DomainServiceTest extends TestCase
{
$default = DomainItem::forDefaultDomain('default.com', new EmptyNotFoundRedirectConfig());
$adminApiKey = ApiKey::create();
$domain = Domain::withAuthority('');
$domain->setId('123');
$domainSpecificApiKey = ApiKey::fromMeta(
ApiKeyMeta::withRoles(RoleDefinition::forDomain(Domain::withAuthority('')->setId('123'))),
ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)),
);
yield 'empty list without API key' => [[], [$default], null];
@ -147,7 +149,8 @@ class DomainServiceTest extends TestCase
public function getOrCreateThrowsExceptionForApiKeysWithDomainRole(): void
{
$authority = 'example.com';
$domain = Domain::withAuthority($authority)->setId('1');
$domain = Domain::withAuthority($authority);
$domain->setId('1');
$apiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)));
$repo = $this->createMock(DomainRepositoryInterface::class);
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(null);

View File

@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Core\Visit\Geolocation;
use Doctrine\ORM\EntityManager;
use Exception;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
@ -19,10 +18,8 @@ use Shlinkio\Shlink\Core\Visit\Model\Visitor;
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use function array_shift;
use function count;
use function floor;
use function func_get_args;
use function Functional\map;
use function range;
use function sprintf;
@ -72,10 +69,6 @@ class VisitLocatorTest extends TestCase
public function onVisitLocated(VisitLocation $visitLocation, Visit $visit): void
{
$args = func_get_args();
Assert::assertInstanceOf(VisitLocation::class, array_shift($args));
Assert::assertInstanceOf(Visit::class, array_shift($args));
}
});
}

View File

@ -45,6 +45,8 @@ class NonOrphanVisitsPaginatorAdapterTest extends TestCase
}
/**
* @param int<0, max> $limit
* @param int<0, max> $offset
* @test
* @dataProvider provideLimitAndOffset
*/

View File

@ -41,6 +41,8 @@ class OrphanVisitsPaginatorAdapterTest extends TestCase
}
/**
* @param int<0, max> $limit
* @param int<0, max> $offset
* @test
* @dataProvider provideLimitAndOffset
*/

View File

@ -23,7 +23,8 @@ class RoleDefinitionTest extends TestCase
/** @test */
public function forDomainCreatesRoleDefinitionAsExpected(): void
{
$domain = Domain::withAuthority('foo.com')->setId('123');
$domain = Domain::withAuthority('foo.com');
$domain->setId('123');
$definition = RoleDefinition::forDomain($domain);
self::assertEquals(Role::DOMAIN_SPECIFIC, $definition->role);