Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
bootstrap="./vendor/autoload.php"
colors="true"
cacheDirectory="build/.phpunit.cache"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitNotices="true"
displayDetailsOnTestsThatTriggerNotices="true"
>
<testsuites>
<testsuite name="Installer">
Expand Down
2 changes: 1 addition & 1 deletion src/Service/InstallationCommandsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function sprintf;
use function trim;

class InstallationCommandsRunner implements InstallationCommandsRunnerInterface
readonly class InstallationCommandsRunner implements InstallationCommandsRunnerInterface
{
private string $phpBinary;

Expand Down
2 changes: 1 addition & 1 deletion test/Command/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions test/Config/ConfigGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -69,7 +67,7 @@ public static function provideConfigOptions(): iterable
yield '1 enabled' => [$optionsGroups, ['foo'], 1];
}

#[Test]
#[Test, AllowMockObjectsWithoutExpectations]
public function pluginsAreAskedInProperOrder(): void
{
$orderedAskedOptions = [];
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test/Config/ConfigOptionsManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
Expand Down
5 changes: 3 additions & 2 deletions test/Config/Option/Redis/RedisServersConfigOptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/Factory/ApplicationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions test/Service/InstallationCommandsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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: []));
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/Service/ShlinkAssetsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,7 @@
use function array_map;
use function str_starts_with;

#[AllowMockObjectsWithoutExpectations]
class ShlinkAssetsHandlerTest extends TestCase
{
private ShlinkAssetsHandler $assetsHandler;
Expand Down