diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3f18413..0c2ab09 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,7 +5,10 @@ bootstrap="./vendor/autoload.php" colors="true" cacheDirectory="build/.phpunit.cache" - displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnPhpunitDeprecations="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnPhpunitNotices="true" + displayDetailsOnTestsThatTriggerNotices="true" > diff --git a/src/Service/InstallationCommandsRunner.php b/src/Service/InstallationCommandsRunner.php index 5a45f32..10af679 100644 --- a/src/Service/InstallationCommandsRunner.php +++ b/src/Service/InstallationCommandsRunner.php @@ -16,7 +16,7 @@ use function sprintf; use function trim; -class InstallationCommandsRunner implements InstallationCommandsRunnerInterface +readonly class InstallationCommandsRunner implements InstallationCommandsRunnerInterface { private string $phpBinary; diff --git a/test/Command/InitCommandTest.php b/test/Command/InitCommandTest.php index 26b43e0..d74358f 100644 --- a/test/Command/InitCommandTest.php +++ b/test/Command/InitCommandTest.php @@ -104,7 +104,7 @@ public static function provideInputs(): iterable #[Test, DataProvider('provideExitCodes')] public function properExitCodeIsReturnedBasedOnCommandsExecution(bool $result, int $expectedExitCode): void { - $this->commandsRunner->method('execPhpCommand')->willReturn($result); + $this->commandsRunner->expects($this->atLeastOnce())->method('execPhpCommand')->willReturn($result); $exitCode = $this->tester->execute([]); self::assertEquals($expectedExitCode, $exitCode); diff --git a/test/Config/ConfigGeneratorTest.php b/test/Config/ConfigGeneratorTest.php index ee29289..c4b0008 100644 --- a/test/Config/ConfigGeneratorTest.php +++ b/test/Config/ConfigGeneratorTest.php @@ -4,6 +4,7 @@ namespace ShlinkioTest\Shlink\Installer\Config; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -22,13 +23,11 @@ class ConfigGeneratorTest extends TestCase { private MockObject & ConfigOptionsManagerInterface $configOptionsManager; - private MockObject & ConfigOptionInterface $plugin; private MockObject & StyleInterface $io; public function setUp(): void { $this->configOptionsManager = $this->createMock(ConfigOptionsManagerInterface::class); - $this->plugin = $this->createMock(ConfigOptionInterface::class); $this->io = $this->createMock(StyleInterface::class); } @@ -41,12 +40,11 @@ public function configuresExpectedPlugins( $totalPlugins = count(ArrayUtils::flatten($configOptionsGroups)); $expectedQuestions = $enabledOptions === null ? $totalPlugins : count($enabledOptions); - $this->plugin->expects($this->exactly($expectedQuestions))->method('shouldBeAsked')->willReturn(true); - $this->plugin->expects($this->exactly($expectedQuestions))->method('getEnvVar')->willReturn('ENV_VAR'); - $this->plugin->expects($this->exactly($expectedQuestions))->method('ask')->willReturn('value'); - $this->configOptionsManager->expects($this->exactly($expectedQuestions))->method('get')->willReturn( - $this->plugin, - ); + $plugin = $this->createMock(ConfigOptionInterface::class); + $plugin->expects($this->exactly($expectedQuestions))->method('shouldBeAsked')->willReturn(true); + $plugin->expects($this->exactly($expectedQuestions))->method('getEnvVar')->willReturn('ENV_VAR'); + $plugin->expects($this->exactly($expectedQuestions))->method('ask')->willReturn('value'); + $this->configOptionsManager->expects($this->exactly($expectedQuestions))->method('get')->willReturn($plugin); $this->io->expects($this->exactly($expectedPrintTitleCalls))->method('title'); $generator = new ConfigGenerator($this->configOptionsManager, $configOptionsGroups, $enabledOptions); @@ -69,7 +67,7 @@ public static function provideConfigOptions(): iterable yield '1 enabled' => [$optionsGroups, ['foo'], 1]; } - #[Test] + #[Test, AllowMockObjectsWithoutExpectations] public function pluginsAreAskedInProperOrder(): void { $orderedAskedOptions = []; @@ -143,7 +141,7 @@ public function getDependentOption(): string self::assertEquals(['a', 'depends_on_a'], $orderedAskedOptions); } - #[Test, DataProvider('provideMigratorValues')] + #[Test, DataProvider('provideMigratorValues'), AllowMockObjectsWithoutExpectations] public function migratorPluginsAreProcessedWhenTheValuesShouldNotBeAsked( array $oldConfig, array $expectedResult, diff --git a/test/Config/ConfigOptionsManagerFactoryTest.php b/test/Config/ConfigOptionsManagerFactoryTest.php index 03f360a..8227cbe 100644 --- a/test/Config/ConfigOptionsManagerFactoryTest.php +++ b/test/Config/ConfigOptionsManagerFactoryTest.php @@ -44,9 +44,9 @@ public static function provideConfigs(): iterable static fn (TestCase $test) => [ 'config_options' => [ 'services' => [ - 'a' => $test->createMock(ConfigOptionInterface::class), - 'b' => $test->createMock(ConfigOptionInterface::class), - 'c' => $test->createMock(ConfigOptionInterface::class), + 'a' => $test->createStub(ConfigOptionInterface::class), + 'b' => $test->createStub(ConfigOptionInterface::class), + 'c' => $test->createStub(ConfigOptionInterface::class), ], ], ], diff --git a/test/Config/Option/RealTimeUpdates/RealTimeUpdatesTopicsConfigOptionTest.php b/test/Config/Option/RealTimeUpdates/RealTimeUpdatesTopicsConfigOptionTest.php index bef5422..87c4e6a 100644 --- a/test/Config/Option/RealTimeUpdates/RealTimeUpdatesTopicsConfigOptionTest.php +++ b/test/Config/Option/RealTimeUpdates/RealTimeUpdatesTopicsConfigOptionTest.php @@ -37,7 +37,7 @@ public function expectedQuestionIsAsked( array $topicAnswers, array|null $expectedTopics, ): void { - $io = $this->createMock(StyleInterface::class); + $io = $this->createStub(StyleInterface::class); $io->method('confirm')->willReturnOnConsecutiveCalls($individualTopicsAnswer, ...$topicAnswers); $answer = $this->configOption->ask($io, []); diff --git a/test/Config/Option/Redis/RedisServersConfigOptionTest.php b/test/Config/Option/Redis/RedisServersConfigOptionTest.php index 319167e..2e8de4e 100644 --- a/test/Config/Option/Redis/RedisServersConfigOptionTest.php +++ b/test/Config/Option/Redis/RedisServersConfigOptionTest.php @@ -4,6 +4,7 @@ namespace ShlinkioTest\Shlink\Installer\Config\Option\Redis; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -22,13 +23,13 @@ public function setUp(): void $this->io = $this->createMock(StyleInterface::class); } - #[Test] + #[Test, AllowMockObjectsWithoutExpectations] public function returnsExpectedEnvVar(): void { self::assertEquals('REDIS_SERVERS', $this->configOption->getEnvVar()); } - #[Test] + #[Test, AllowMockObjectsWithoutExpectations] public function serversAreNotRequestedWhenNoRedisConfigIsProvided(): void { $this->io->expects($this->once())->method('confirm')->with( diff --git a/test/Factory/ApplicationFactoryTest.php b/test/Factory/ApplicationFactoryTest.php index 54e8d5c..b4ae5b8 100644 --- a/test/Factory/ApplicationFactoryTest.php +++ b/test/Factory/ApplicationFactoryTest.php @@ -29,7 +29,7 @@ public function setUp(): void public function serviceIsCreated(): void { $createEnabledCommandWithName = function (string $name) { - $command = $this->createMock(Command::class); + $command = $this->createStub(Command::class); $command->method('isEnabled')->willReturn(true); $command->method('getAliases')->willReturn([]); $command->method('getName')->willReturn($name); diff --git a/test/Service/InstallationCommandsRunnerTest.php b/test/Service/InstallationCommandsRunnerTest.php index cd57671..c25af0b 100644 --- a/test/Service/InstallationCommandsRunnerTest.php +++ b/test/Service/InstallationCommandsRunnerTest.php @@ -6,9 +6,11 @@ use InvalidArgumentException; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Installer\Service\InstallationCommandsRunner; use Symfony\Component\Console\Helper\ProcessHelper; @@ -30,7 +32,7 @@ class InstallationCommandsRunnerTest extends TestCase public function setUp(): void { - $phpFinder = $this->createMock(PhpExecutableFinder::class); + $phpFinder = $this->createStub(PhpExecutableFinder::class); $phpFinder->method('find')->willReturn('php'); $this->processHelper = $this->createMock(ProcessHelper::class); @@ -59,7 +61,7 @@ private function buildCommands(): array ); } - #[Test] + #[Test, AllowMockObjectsWithoutExpectations] public function doesNothingWhenRequestedCommandDoesNotExist(): void { self::assertFalse($this->commandsRunner->execPhpCommand('invalid', $this->io, interactive: true, args: [])); @@ -228,9 +230,9 @@ public static function provideArgs(): iterable yield 'multiple arg' => [['first', 'second', 'third']]; } - private function createProcessMock(bool $isSuccessful): MockObject & Process + private function createProcessMock(bool $isSuccessful): Stub & Process { - $process = $this->createMock(Process::class); + $process = $this->createStub(Process::class); $process->method('isSuccessful')->willReturn($isSuccessful); return $process; diff --git a/test/Service/ShlinkAssetsHandlerTest.php b/test/Service/ShlinkAssetsHandlerTest.php index b589baa..b363980 100644 --- a/test/Service/ShlinkAssetsHandlerTest.php +++ b/test/Service/ShlinkAssetsHandlerTest.php @@ -4,6 +4,7 @@ namespace ShlinkioTest\Shlink\Installer\Service; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -18,6 +19,7 @@ use function array_map; use function str_starts_with; +#[AllowMockObjectsWithoutExpectations] class ShlinkAssetsHandlerTest extends TestCase { private ShlinkAssetsHandler $assetsHandler;