mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Update to PHPUnit 10
This commit is contained in:
@@ -23,7 +23,7 @@ class ListApiKeysTest extends CliTestCase
|
||||
self::assertEquals(ExitCodes::EXIT_SUCCESS, $exitCode);
|
||||
}
|
||||
|
||||
public function provideFlags(): iterable
|
||||
public static function provideFlags(): iterable
|
||||
{
|
||||
$expiredApiKeyDate = Chronos::now()->subDay()->startOfDay()->toAtomString();
|
||||
$enabledOnlyOutput = <<<OUT
|
||||
|
||||
@@ -19,7 +19,7 @@ class ListShortUrlsTest extends CliTestCase
|
||||
self::assertStringContainsString($expectedOutput, $output);
|
||||
}
|
||||
|
||||
public function provideFlagsAndOutput(): iterable
|
||||
public static function provideFlagsAndOutput(): iterable
|
||||
{
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
yield 'no flags' => [[], <<<OUTPUT
|
||||
|
||||
@@ -32,24 +32,25 @@ class RoleResolverTest extends TestCase
|
||||
* @dataProvider provideRoles
|
||||
*/
|
||||
public function properRolesAreResolvedBasedOnInput(
|
||||
InputInterface $input,
|
||||
callable $createInput,
|
||||
array $expectedRoles,
|
||||
int $expectedDomainCalls,
|
||||
): void {
|
||||
$input = $createInput($this);
|
||||
$this->domainService->expects($this->exactly($expectedDomainCalls))->method('getOrCreate')->with(
|
||||
'example.com',
|
||||
)->willReturn($this->domainWithId(Domain::withAuthority('example.com')));
|
||||
)->willReturn(self::domainWithId(Domain::withAuthority('example.com')));
|
||||
|
||||
$result = $this->resolver->determineRoles($input);
|
||||
|
||||
self::assertEquals($expectedRoles, $result);
|
||||
}
|
||||
|
||||
public function provideRoles(): iterable
|
||||
public static function provideRoles(): iterable
|
||||
{
|
||||
$domain = $this->domainWithId(Domain::withAuthority('example.com'));
|
||||
$buildInput = function (array $definition): InputInterface {
|
||||
$input = $this->createStub(InputInterface::class);
|
||||
$domain = self::domainWithId(Domain::withAuthority('example.com'));
|
||||
$buildInput = static fn (array $definition) => function (TestCase $test) use ($definition): InputInterface {
|
||||
$input = $test->createStub(InputInterface::class);
|
||||
$input->method('getOption')->willReturnMap(
|
||||
map($definition, static fn (mixed $returnValue, string $param) => [$param, $returnValue]),
|
||||
);
|
||||
@@ -114,7 +115,7 @@ class RoleResolverTest extends TestCase
|
||||
$this->resolver->determineRoles($input);
|
||||
}
|
||||
|
||||
private function domainWithId(Domain $domain): Domain
|
||||
private static function domainWithId(Domain $domain): Domain
|
||||
{
|
||||
$domain->setId('1');
|
||||
return $domain;
|
||||
|
||||
@@ -43,7 +43,7 @@ class ListKeysCommandTest extends TestCase
|
||||
self::assertEquals($expected, $output);
|
||||
}
|
||||
|
||||
public function provideKeysAndOutputs(): iterable
|
||||
public static function provideKeysAndOutputs(): iterable
|
||||
{
|
||||
$dateInThePast = Chronos::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00');
|
||||
|
||||
@@ -84,14 +84,14 @@ class ListKeysCommandTest extends TestCase
|
||||
yield 'with roles' => [
|
||||
[
|
||||
$apiKey1 = ApiKey::create(),
|
||||
$apiKey2 = $this->apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]),
|
||||
$apiKey3 = $this->apiKeyWithRoles(
|
||||
[RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com')))],
|
||||
$apiKey2 = self::apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]),
|
||||
$apiKey3 = self::apiKeyWithRoles(
|
||||
[RoleDefinition::forDomain(self::domainWithId(Domain::withAuthority('example.com')))],
|
||||
),
|
||||
$apiKey4 = ApiKey::create(),
|
||||
$apiKey5 = $this->apiKeyWithRoles([
|
||||
$apiKey5 = self::apiKeyWithRoles([
|
||||
RoleDefinition::forAuthoredShortUrls(),
|
||||
RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com'))),
|
||||
RoleDefinition::forDomain(self::domainWithId(Domain::withAuthority('example.com'))),
|
||||
]),
|
||||
$apiKey6 = ApiKey::create(),
|
||||
],
|
||||
@@ -141,7 +141,7 @@ class ListKeysCommandTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
private function apiKeyWithRoles(array $roles): ApiKey
|
||||
private static function apiKeyWithRoles(array $roles): ApiKey
|
||||
{
|
||||
$apiKey = ApiKey::create();
|
||||
foreach ($roles as $role) {
|
||||
@@ -151,7 +151,7 @@ class ListKeysCommandTest extends TestCase
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
private function domainWithId(Domain $domain): Domain
|
||||
private static function domainWithId(Domain $domain): Domain
|
||||
{
|
||||
$domain->setId('1');
|
||||
return $domain;
|
||||
|
||||
@@ -124,7 +124,7 @@ class CreateDatabaseCommandTest extends TestCase
|
||||
self::assertStringContainsString('Database properly created!', $output);
|
||||
}
|
||||
|
||||
public function provideEmptyDatabase(): iterable
|
||||
public static function provideEmptyDatabase(): iterable
|
||||
{
|
||||
yield 'no tables' => [[]];
|
||||
yield 'migrations table' => [[MIGRATIONS_TABLE]];
|
||||
|
||||
@@ -60,7 +60,7 @@ class DomainRedirectsCommandTest extends TestCase
|
||||
self::assertEquals(3, substr_count($output, '(Leave empty for no redirect)'));
|
||||
}
|
||||
|
||||
public function provideDomains(): iterable
|
||||
public static function provideDomains(): iterable
|
||||
{
|
||||
yield 'no domain' => [null];
|
||||
yield 'domain without redirects' => [Domain::withAuthority('')];
|
||||
|
||||
@@ -57,7 +57,7 @@ class ListDomainsCommandTest extends TestCase
|
||||
self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode());
|
||||
}
|
||||
|
||||
public function provideInputsAndOutputs(): iterable
|
||||
public static function provideInputsAndOutputs(): iterable
|
||||
{
|
||||
$withoutRedirectsOutput = <<<OUTPUT
|
||||
+---------+------------+
|
||||
|
||||
@@ -139,7 +139,7 @@ class CreateShortUrlCommandTest extends TestCase
|
||||
self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode());
|
||||
}
|
||||
|
||||
public function provideDomains(): iterable
|
||||
public static function provideDomains(): iterable
|
||||
{
|
||||
yield 'no domain' => [[], null];
|
||||
yield 'non-default domain foo' => [['--domain' => 'foo.com'], 'foo.com'];
|
||||
@@ -166,7 +166,7 @@ class CreateShortUrlCommandTest extends TestCase
|
||||
$this->commandTester->execute($options);
|
||||
}
|
||||
|
||||
public function provideFlags(): iterable
|
||||
public static function provideFlags(): iterable
|
||||
{
|
||||
yield 'no flags' => [[], null];
|
||||
yield 'validate-url' => [['--validate-url' => true], true];
|
||||
|
||||
@@ -98,7 +98,7 @@ class DeleteShortUrlCommandTest extends TestCase
|
||||
self::assertStringContainsString($expectedMessage, $output);
|
||||
}
|
||||
|
||||
public function provideRetryDeleteAnswers(): iterable
|
||||
public static function provideRetryDeleteAnswers(): iterable
|
||||
{
|
||||
yield 'answering yes to retry' => [['yes'], 2, 'Short URL with short code "abc123" successfully deleted.'];
|
||||
yield 'answering no to retry' => [['no'], 1, 'Short URL was not deleted.'];
|
||||
|
||||
@@ -137,7 +137,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function provideOptionalFlags(): iterable
|
||||
public static function provideOptionalFlags(): iterable
|
||||
{
|
||||
$apiKey = ApiKey::fromMeta(ApiKeyMeta::withName('my api key'));
|
||||
$key = $apiKey->toString();
|
||||
@@ -200,7 +200,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
$this->commandTester->execute($commandArgs);
|
||||
}
|
||||
|
||||
public function provideArgs(): iterable
|
||||
public static function provideArgs(): iterable
|
||||
{
|
||||
yield [[], 1, null, [], TagsMode::ANY->value];
|
||||
yield [['--page' => $page = 3], $page, null, [], TagsMode::ANY->value];
|
||||
@@ -255,7 +255,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
$this->commandTester->execute($commandArgs);
|
||||
}
|
||||
|
||||
public function provideOrderBy(): iterable
|
||||
public static function provideOrderBy(): iterable
|
||||
{
|
||||
yield [[], null];
|
||||
yield [['--order-by' => 'visits'], 'visits'];
|
||||
|
||||
@@ -61,7 +61,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase
|
||||
self::assertSame($expectedExitCode, $exitCode);
|
||||
}
|
||||
|
||||
public function provideFailureParams(): iterable
|
||||
public static function provideFailureParams(): iterable
|
||||
{
|
||||
yield 'existing db' => [
|
||||
true,
|
||||
@@ -93,7 +93,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase
|
||||
self::assertSame(ExitCodes::EXIT_SUCCESS, $exitCode);
|
||||
}
|
||||
|
||||
public function provideSuccessParams(): iterable
|
||||
public static function provideSuccessParams(): iterable
|
||||
{
|
||||
yield 'up to date db' => [fn () => GeolocationResult::CHECK_SKIPPED, '[INFO] GeoLite2 db file is up to date.'];
|
||||
yield 'outdated db' => [function (callable $beforeDownload): GeolocationResult {
|
||||
|
||||
@@ -100,7 +100,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function provideArgs(): iterable
|
||||
public static function provideArgs(): iterable
|
||||
{
|
||||
yield 'no args' => [1, 0, 0, false, []];
|
||||
yield 'retry' => [1, 1, 0, false, ['--retry' => true]];
|
||||
@@ -131,7 +131,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
self::assertStringContainsString($message, $output);
|
||||
}
|
||||
|
||||
public function provideIgnoredAddresses(): iterable
|
||||
public static function provideIgnoredAddresses(): iterable
|
||||
{
|
||||
yield 'empty address' => [IpCannotBeLocatedException::forEmptyAddress(), 'Ignored visit with no IP address'];
|
||||
yield 'localhost address' => [IpCannotBeLocatedException::forLocalhost(), 'Ignored localhost address'];
|
||||
@@ -226,7 +226,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
$this->commandTester->execute(['--all' => true, '--retry' => true]);
|
||||
}
|
||||
|
||||
public function provideAbortInputs(): iterable
|
||||
public static function provideAbortInputs(): iterable
|
||||
{
|
||||
yield 'n' => [['n']];
|
||||
yield 'no' => [['no']];
|
||||
|
||||
@@ -46,7 +46,7 @@ class GeolocationDbUpdateFailedExceptionTest extends TestCase
|
||||
self::assertEquals($prev, $e->getPrevious());
|
||||
}
|
||||
|
||||
public function providePrev(): iterable
|
||||
public static function providePrev(): iterable
|
||||
{
|
||||
yield 'no prev' => [null];
|
||||
yield 'RuntimeException' => [new RuntimeException('prev')];
|
||||
|
||||
@@ -84,7 +84,7 @@ class GeolocationDbUpdaterTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function provideBigDays(): iterable
|
||||
public static function provideBigDays(): iterable
|
||||
{
|
||||
yield [36];
|
||||
yield [50];
|
||||
@@ -109,7 +109,7 @@ class GeolocationDbUpdaterTest extends TestCase
|
||||
self::assertEquals(GeolocationResult::DB_IS_UP_TO_DATE, $result);
|
||||
}
|
||||
|
||||
public function provideSmallDays(): iterable
|
||||
public static function provideSmallDays(): iterable
|
||||
{
|
||||
$generateParamsWithTimestamp = static function (int $days) {
|
||||
$timestamp = Chronos::now()->subDays($days)->getTimestamp();
|
||||
@@ -164,7 +164,7 @@ class GeolocationDbUpdaterTest extends TestCase
|
||||
self::assertEquals(GeolocationResult::CHECK_SKIPPED, $result);
|
||||
}
|
||||
|
||||
public function provideTrackingOptions(): iterable
|
||||
public static function provideTrackingOptions(): iterable
|
||||
{
|
||||
yield 'disableTracking' => [new TrackingOptions(disableTracking: true)];
|
||||
yield 'disableIpTracking' => [new TrackingOptions(disableIpTracking: true)];
|
||||
|
||||
Reference in New Issue
Block a user