mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 09:13:11 +08:00
Update to PHPUnit 12
This commit is contained in:
@@ -15,7 +15,6 @@ use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
|
||||
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class GenerateKeyCommandTest extends TestCase
|
||||
@@ -27,7 +26,7 @@ class GenerateKeyCommandTest extends TestCase
|
||||
{
|
||||
$this->apiKeyService = $this->createMock(ApiKeyServiceInterface::class);
|
||||
$roleResolver = $this->createMock(RoleResolverInterface::class);
|
||||
$roleResolver->method('determineRoles')->with($this->isInstanceOf(InputInterface::class))->willReturn([]);
|
||||
$roleResolver->method('determineRoles')->willReturn([]);
|
||||
|
||||
$command = new GenerateKeyCommand($this->apiKeyService, $roleResolver);
|
||||
$this->commandTester = CliTestUtils::testerForCommand($command);
|
||||
|
||||
@@ -40,11 +40,11 @@ class CreateDatabaseCommandTest extends TestCase
|
||||
{
|
||||
$locker = $this->createMock(LockFactory::class);
|
||||
$lock = $this->createMock(SharedLockInterface::class);
|
||||
$lock->method('acquire')->withAnyParameters()->willReturn(true);
|
||||
$locker->method('createLock')->withAnyParameters()->willReturn($lock);
|
||||
$lock->method('acquire')->willReturn(true);
|
||||
$locker->method('createLock')->willReturn($lock);
|
||||
|
||||
$phpExecutableFinder = $this->createMock(PhpExecutableFinder::class);
|
||||
$phpExecutableFinder->method('find')->with($this->isFalse())->willReturn('/usr/local/bin/php');
|
||||
$phpExecutableFinder->method('find')->willReturn('/usr/local/bin/php');
|
||||
|
||||
$this->processHelper = $this->createMock(ProcessRunnerInterface::class);
|
||||
$this->schemaManager = $this->createMock(AbstractSchemaManager::class);
|
||||
@@ -60,7 +60,7 @@ class CreateDatabaseCommandTest extends TestCase
|
||||
$em->method('getMetadataFactory')->willReturn($this->metadataFactory);
|
||||
|
||||
$noDbNameConn = $this->createMock(Connection::class);
|
||||
$noDbNameConn->method('createSchemaManager')->withAnyParameters()->willReturn($this->schemaManager);
|
||||
$noDbNameConn->method('createSchemaManager')->willReturn($this->schemaManager);
|
||||
|
||||
$command = new CreateDatabaseCommand($locker, $this->processHelper, $phpExecutableFinder, $em, $noDbNameConn);
|
||||
$this->commandTester = CliTestUtils::testerForCommand($command);
|
||||
|
||||
@@ -25,11 +25,11 @@ class MigrateDatabaseCommandTest extends TestCase
|
||||
{
|
||||
$locker = $this->createMock(LockFactory::class);
|
||||
$lock = $this->createMock(SharedLockInterface::class);
|
||||
$lock->method('acquire')->withAnyParameters()->willReturn(true);
|
||||
$locker->method('createLock')->withAnyParameters()->willReturn($lock);
|
||||
$lock->method('acquire')->willReturn(true);
|
||||
$locker->method('createLock')->willReturn($lock);
|
||||
|
||||
$phpExecutableFinder = $this->createMock(PhpExecutableFinder::class);
|
||||
$phpExecutableFinder->method('find')->with($this->isFalse())->willReturn('/usr/local/bin/php');
|
||||
$phpExecutableFinder->method('find')->willReturn('/usr/local/bin/php');
|
||||
|
||||
$this->processHelper = $this->createMock(ProcessRunnerInterface::class);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class CreateShortUrlCommandTest extends TestCase
|
||||
$this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willThrowException(
|
||||
NonUniqueSlugException::fromSlug('my-slug'),
|
||||
);
|
||||
$this->stringifier->method('stringify')->with($this->isInstanceOf(ShortUrl::class))->willReturn('');
|
||||
$this->stringifier->method('stringify')->willReturn('');
|
||||
|
||||
$this->commandTester->execute(['longUrl' => 'http://domain.com/invalid', '--custom-slug' => 'my-slug']);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
@@ -112,7 +112,7 @@ class CreateShortUrlCommandTest extends TestCase
|
||||
return true;
|
||||
}),
|
||||
)->willReturn(UrlShorteningResult::withoutErrorOnEventDispatching(ShortUrl::createFake()));
|
||||
$this->stringifier->method('stringify')->with($this->isInstanceOf(ShortUrl::class))->willReturn('');
|
||||
$this->stringifier->method('stringify')->willReturn('');
|
||||
|
||||
$input['longUrl'] = 'http://domain.com/foo/bar';
|
||||
$this->commandTester->execute($input);
|
||||
@@ -139,7 +139,7 @@ class CreateShortUrlCommandTest extends TestCase
|
||||
return true;
|
||||
}),
|
||||
)->willReturn(UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl));
|
||||
$this->stringifier->method('stringify')->with($this->isInstanceOf(ShortUrl::class))->willReturn('');
|
||||
$this->stringifier->method('stringify')->willReturn('');
|
||||
|
||||
$options['longUrl'] = 'http://domain.com/foo/bar';
|
||||
$this->commandTester->execute($options);
|
||||
|
||||
@@ -47,7 +47,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
|
||||
$locker = $this->createMock(Lock\LockFactory::class);
|
||||
$this->lock = $this->createMock(Lock\SharedLockInterface::class);
|
||||
$locker->method('createLock')->with($this->isString(), 600.0, false)->willReturn($this->lock);
|
||||
$locker->method('createLock')->willReturn($this->lock);
|
||||
|
||||
$command = new LocateVisitsCommand($this->visitService, $this->visitToLocation, $locker);
|
||||
|
||||
@@ -67,7 +67,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
$location = VisitLocation::fromGeolocation(Location::empty());
|
||||
$mockMethodBehavior = $this->invokeHelperMethods($visit, $location);
|
||||
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
|
||||
$this->lock->method('acquire')->willReturn(true);
|
||||
$this->visitService->expects($this->exactly($expectedUnlocatedCalls))
|
||||
->method('locateUnlocatedVisits')
|
||||
->withAnyParameters()
|
||||
@@ -83,7 +83,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
$this->visitToLocation->expects(
|
||||
$this->exactly($expectedUnlocatedCalls + $expectedEmptyCalls + $expectedAllCalls),
|
||||
)->method('resolveVisitLocation')->withAnyParameters()->willReturn(Location::emptyInstance());
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->commandTester->setInputs(['y']);
|
||||
$this->commandTester->execute($args);
|
||||
@@ -108,15 +108,15 @@ class LocateVisitsCommandTest extends TestCase
|
||||
public function localhostAndEmptyAddressesAreIgnored(IpCannotBeLocatedException $e, string $message): void
|
||||
{
|
||||
$visit = Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty());
|
||||
$location = VisitLocation::fromGeolocation(Location::emptyInstance());
|
||||
$location = VisitLocation::fromGeolocation(Location::empty());
|
||||
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
|
||||
$this->lock->method('acquire')->willReturn(true);
|
||||
$this->visitService->expects($this->once())
|
||||
->method('locateUnlocatedVisits')
|
||||
->withAnyParameters()
|
||||
->willReturnCallback($this->invokeHelperMethods($visit, $location));
|
||||
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->willThrowException($e);
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]);
|
||||
|
||||
@@ -137,7 +137,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
$visit = Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::fromParams(remoteAddress: '1.2.3.4'));
|
||||
$location = VisitLocation::fromGeolocation(Location::emptyInstance());
|
||||
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
|
||||
$this->lock->method('acquire')->willReturn(true);
|
||||
$this->visitService->expects($this->once())
|
||||
->method('locateUnlocatedVisits')
|
||||
->withAnyParameters()
|
||||
@@ -145,7 +145,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->willThrowException(
|
||||
IpCannotBeLocatedException::forError(WrongIpException::fromIpAddress('1.2.3.4')),
|
||||
);
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]);
|
||||
|
||||
@@ -165,11 +165,11 @@ class LocateVisitsCommandTest extends TestCase
|
||||
#[Test]
|
||||
public function noActionIsPerformedIfLockIsAcquired(): void
|
||||
{
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(false);
|
||||
$this->lock->method('acquire')->willReturn(false);
|
||||
|
||||
$this->visitService->expects($this->never())->method('locateUnlocatedVisits');
|
||||
$this->visitToLocation->expects($this->never())->method('resolveVisitLocation');
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
@@ -183,8 +183,8 @@ class LocateVisitsCommandTest extends TestCase
|
||||
#[Test]
|
||||
public function showsProperMessageWhenGeoLiteUpdateFails(): void
|
||||
{
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_FAILURE);
|
||||
$this->lock->method('acquire')->willReturn(true);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_FAILURE);
|
||||
$this->visitService->expects($this->never())->method('locateUnlocatedVisits');
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
@@ -196,8 +196,8 @@ class LocateVisitsCommandTest extends TestCase
|
||||
#[Test]
|
||||
public function providingAllFlagOnItsOwnDisplaysNotice(): void
|
||||
{
|
||||
$this->lock->method('acquire')->with($this->isFalse())->willReturn(true);
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->lock->method('acquire')->willReturn(true);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->commandTester->execute(['--all' => true]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
@@ -208,7 +208,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||
#[Test, DataProvider('provideAbortInputs')]
|
||||
public function processingAllCancelsCommandIfUserDoesNotActivelyAgreeToConfirmation(array $inputs): void
|
||||
{
|
||||
$this->downloadDbCommand->method('run')->withAnyParameters()->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
$this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('Execution aborted');
|
||||
|
||||
@@ -25,11 +25,8 @@ class CliTestUtils
|
||||
$command = $generator->testDouble(
|
||||
Command::class,
|
||||
mockObject: true,
|
||||
markAsMockObject: true,
|
||||
callOriginalConstructor: false,
|
||||
callOriginalClone: false,
|
||||
cloneArguments: false,
|
||||
allowMockingUnknownTypes: false,
|
||||
);
|
||||
$command->method('getName')->willReturn($name);
|
||||
$command->method('isEnabled')->willReturn(true);
|
||||
|
||||
@@ -27,8 +27,8 @@ 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('debug_formatter')->willReturn($this->formatter);
|
||||
$this->helper->method('getHelperSet')->with()->willReturn($helperSet);
|
||||
$helperSet->method('get')->willReturn($this->formatter);
|
||||
$this->helper->method('getHelperSet')->willReturn($helperSet);
|
||||
$this->process = $this->createMock(Process::class);
|
||||
$this->output = $this->createMock(OutputInterface::class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user