Skip to content

Commit 6e81557

Browse files
committed
Address notices reported by latest PHPUnit
1 parent a225b16 commit 6e81557

10 files changed

+30
-24
lines changed

phpunit.xml.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
bootstrap="./vendor/autoload.php"
66
colors="true"
77
cacheDirectory="build/.phpunit.cache"
8-
displayDetailsOnTestsThatTriggerWarnings="true"
8+
displayDetailsOnPhpunitDeprecations="true"
9+
displayDetailsOnTestsThatTriggerDeprecations="true"
10+
displayDetailsOnPhpunitNotices="true"
11+
displayDetailsOnTestsThatTriggerNotices="true"
912
>
1013
<testsuites>
1114
<testsuite name="Installer">

src/Service/InstallationCommandsRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use function sprintf;
1717
use function trim;
1818

19-
class InstallationCommandsRunner implements InstallationCommandsRunnerInterface
19+
readonly class InstallationCommandsRunner implements InstallationCommandsRunnerInterface
2020
{
2121
private string $phpBinary;
2222

test/Command/InitCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function provideInputs(): iterable
104104
#[Test, DataProvider('provideExitCodes')]
105105
public function properExitCodeIsReturnedBasedOnCommandsExecution(bool $result, int $expectedExitCode): void
106106
{
107-
$this->commandsRunner->method('execPhpCommand')->willReturn($result);
107+
$this->commandsRunner->expects($this->atLeastOnce())->method('execPhpCommand')->willReturn($result);
108108
$exitCode = $this->tester->execute([]);
109109

110110
self::assertEquals($expectedExitCode, $exitCode);

test/Config/ConfigGeneratorTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ShlinkioTest\Shlink\Installer\Config;
66

7+
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
78
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\Attributes\Test;
910
use PHPUnit\Framework\MockObject\MockObject;
@@ -22,13 +23,11 @@
2223
class ConfigGeneratorTest extends TestCase
2324
{
2425
private MockObject & ConfigOptionsManagerInterface $configOptionsManager;
25-
private MockObject & ConfigOptionInterface $plugin;
2626
private MockObject & StyleInterface $io;
2727

2828
public function setUp(): void
2929
{
3030
$this->configOptionsManager = $this->createMock(ConfigOptionsManagerInterface::class);
31-
$this->plugin = $this->createMock(ConfigOptionInterface::class);
3231
$this->io = $this->createMock(StyleInterface::class);
3332
}
3433

@@ -41,12 +40,11 @@ public function configuresExpectedPlugins(
4140
$totalPlugins = count(ArrayUtils::flatten($configOptionsGroups));
4241
$expectedQuestions = $enabledOptions === null ? $totalPlugins : count($enabledOptions);
4342

44-
$this->plugin->expects($this->exactly($expectedQuestions))->method('shouldBeAsked')->willReturn(true);
45-
$this->plugin->expects($this->exactly($expectedQuestions))->method('getEnvVar')->willReturn('ENV_VAR');
46-
$this->plugin->expects($this->exactly($expectedQuestions))->method('ask')->willReturn('value');
47-
$this->configOptionsManager->expects($this->exactly($expectedQuestions))->method('get')->willReturn(
48-
$this->plugin,
49-
);
43+
$plugin = $this->createMock(ConfigOptionInterface::class);
44+
$plugin->expects($this->exactly($expectedQuestions))->method('shouldBeAsked')->willReturn(true);
45+
$plugin->expects($this->exactly($expectedQuestions))->method('getEnvVar')->willReturn('ENV_VAR');
46+
$plugin->expects($this->exactly($expectedQuestions))->method('ask')->willReturn('value');
47+
$this->configOptionsManager->expects($this->exactly($expectedQuestions))->method('get')->willReturn($plugin);
5048
$this->io->expects($this->exactly($expectedPrintTitleCalls))->method('title');
5149

5250
$generator = new ConfigGenerator($this->configOptionsManager, $configOptionsGroups, $enabledOptions);
@@ -69,7 +67,7 @@ public static function provideConfigOptions(): iterable
6967
yield '1 enabled' => [$optionsGroups, ['foo'], 1];
7068
}
7169

72-
#[Test]
70+
#[Test, AllowMockObjectsWithoutExpectations]
7371
public function pluginsAreAskedInProperOrder(): void
7472
{
7573
$orderedAskedOptions = [];
@@ -143,7 +141,7 @@ public function getDependentOption(): string
143141
self::assertEquals(['a', 'depends_on_a'], $orderedAskedOptions);
144142
}
145143

146-
#[Test, DataProvider('provideMigratorValues')]
144+
#[Test, DataProvider('provideMigratorValues'), AllowMockObjectsWithoutExpectations]
147145
public function migratorPluginsAreProcessedWhenTheValuesShouldNotBeAsked(
148146
array $oldConfig,
149147
array $expectedResult,

test/Config/ConfigOptionsManagerFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public static function provideConfigs(): iterable
4444
static fn (TestCase $test) => [
4545
'config_options' => [
4646
'services' => [
47-
'a' => $test->createMock(ConfigOptionInterface::class),
48-
'b' => $test->createMock(ConfigOptionInterface::class),
49-
'c' => $test->createMock(ConfigOptionInterface::class),
47+
'a' => $test->createStub(ConfigOptionInterface::class),
48+
'b' => $test->createStub(ConfigOptionInterface::class),
49+
'c' => $test->createStub(ConfigOptionInterface::class),
5050
],
5151
],
5252
],

test/Config/Option/RealTimeUpdates/RealTimeUpdatesTopicsConfigOptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function expectedQuestionIsAsked(
3737
array $topicAnswers,
3838
array|null $expectedTopics,
3939
): void {
40-
$io = $this->createMock(StyleInterface::class);
40+
$io = $this->createStub(StyleInterface::class);
4141
$io->method('confirm')->willReturnOnConsecutiveCalls($individualTopicsAnswer, ...$topicAnswers);
4242

4343
$answer = $this->configOption->ask($io, []);

test/Config/Option/Redis/RedisServersConfigOptionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ShlinkioTest\Shlink\Installer\Config\Option\Redis;
66

7+
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
78
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\Attributes\Test;
910
use PHPUnit\Framework\MockObject\MockObject;
@@ -22,13 +23,13 @@ public function setUp(): void
2223
$this->io = $this->createMock(StyleInterface::class);
2324
}
2425

25-
#[Test]
26+
#[Test, AllowMockObjectsWithoutExpectations]
2627
public function returnsExpectedEnvVar(): void
2728
{
2829
self::assertEquals('REDIS_SERVERS', $this->configOption->getEnvVar());
2930
}
3031

31-
#[Test]
32+
#[Test, AllowMockObjectsWithoutExpectations]
3233
public function serversAreNotRequestedWhenNoRedisConfigIsProvided(): void
3334
{
3435
$this->io->expects($this->once())->method('confirm')->with(

test/Factory/ApplicationFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setUp(): void
2929
public function serviceIsCreated(): void
3030
{
3131
$createEnabledCommandWithName = function (string $name) {
32-
$command = $this->createMock(Command::class);
32+
$command = $this->createStub(Command::class);
3333
$command->method('isEnabled')->willReturn(true);
3434
$command->method('getAliases')->willReturn([]);
3535
$command->method('getName')->willReturn($name);

test/Service/InstallationCommandsRunnerTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use InvalidArgumentException;
88
use PHPUnit\Framework\Assert;
9+
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
910
use PHPUnit\Framework\Attributes\DataProvider;
1011
use PHPUnit\Framework\Attributes\Test;
1112
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\MockObject\Stub;
1214
use PHPUnit\Framework\TestCase;
1315
use Shlinkio\Shlink\Installer\Service\InstallationCommandsRunner;
1416
use Symfony\Component\Console\Helper\ProcessHelper;
@@ -30,7 +32,7 @@ class InstallationCommandsRunnerTest extends TestCase
3032

3133
public function setUp(): void
3234
{
33-
$phpFinder = $this->createMock(PhpExecutableFinder::class);
35+
$phpFinder = $this->createStub(PhpExecutableFinder::class);
3436
$phpFinder->method('find')->willReturn('php');
3537

3638
$this->processHelper = $this->createMock(ProcessHelper::class);
@@ -59,7 +61,7 @@ private function buildCommands(): array
5961
);
6062
}
6163

62-
#[Test]
64+
#[Test, AllowMockObjectsWithoutExpectations]
6365
public function doesNothingWhenRequestedCommandDoesNotExist(): void
6466
{
6567
self::assertFalse($this->commandsRunner->execPhpCommand('invalid', $this->io, interactive: true, args: []));
@@ -228,9 +230,9 @@ public static function provideArgs(): iterable
228230
yield 'multiple arg' => [['first', 'second', 'third']];
229231
}
230232

231-
private function createProcessMock(bool $isSuccessful): MockObject & Process
233+
private function createProcessMock(bool $isSuccessful): Stub & Process
232234
{
233-
$process = $this->createMock(Process::class);
235+
$process = $this->createStub(Process::class);
234236
$process->method('isSuccessful')->willReturn($isSuccessful);
235237

236238
return $process;

test/Service/ShlinkAssetsHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ShlinkioTest\Shlink\Installer\Service;
66

7+
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
78
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\Attributes\Test;
910
use PHPUnit\Framework\MockObject\MockObject;
@@ -18,6 +19,7 @@
1819
use function array_map;
1920
use function str_starts_with;
2021

22+
#[AllowMockObjectsWithoutExpectations]
2123
class ShlinkAssetsHandlerTest extends TestCase
2224
{
2325
private ShlinkAssetsHandler $assetsHandler;

0 commit comments

Comments
 (0)