forked from shlinkio/shlink-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateCommandTest.php
More file actions
87 lines (74 loc) · 3.41 KB
/
UpdateCommandTest.php
File metadata and controls
87 lines (74 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Installer\Command;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Command\InitCommand;
use Shlinkio\Shlink\Installer\Command\UpdateCommand;
use Shlinkio\Shlink\Installer\Config\ConfigGeneratorInterface;
use Shlinkio\Shlink\Installer\Model\ImportedConfig;
use Shlinkio\Shlink\Installer\Service\ShlinkAssetsHandlerInterface;
use Shlinkio\Shlink\Installer\Util\ConfigWriterInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Tester\CommandTester;
class UpdateCommandTest extends TestCase
{
private CommandTester $commandTester;
private MockObject & ConfigWriterInterface $configWriter;
private MockObject & ShlinkAssetsHandlerInterface $assetsHandler;
private MockObject & Command $initCommand;
public function setUp(): void
{
$this->assetsHandler = $this->createMock(ShlinkAssetsHandlerInterface::class);
$this->assetsHandler->expects($this->once())->method('dropCachedConfigIfAny');
$this->configWriter = $this->createMock(ConfigWriterInterface::class);
$generator = $this->createMock(ConfigGeneratorInterface::class);
$generator->method('generateConfigInteractively')->willReturn([]);
$app = new Application();
$command = new UpdateCommand($this->configWriter, $this->assetsHandler, $generator);
$app->addCommand($command);
$this->initCommand = $this->createMock(Command::class);
$this->initCommand->method('getName')->willReturn(InitCommand::NAME);
$this->initCommand->method('isEnabled')->willReturn(true);
$app->addCommand($this->initCommand);
$this->commandTester = new CommandTester($command);
}
#[Test, DataProvider('provideCommands')]
public function commandIsExecutedAsExpected(bool $rrBinExists, string $postUpdateCommands): void
{
$this->initCommand->expects($this->once())->method('run')->with(
$this->callback(function (ArrayInput $input) use ($postUpdateCommands) {
Assert::assertEquals(
$postUpdateCommands,
$input->__toString(),
);
return true;
}),
$this->anything(),
)->willReturn(0);
$this->assetsHandler->expects($this->once())->method('roadRunnerBinaryExistsInPath')->willReturn($rrBinExists);
$this->assetsHandler->expects($this->once())->method('resolvePreviousConfig')->willReturn(
ImportedConfig::notImported(),
);
$this->assetsHandler->expects($this->once())->method('importShlinkAssetsFromPath');
$this->configWriter->expects($this->once())->method('toFile')->with($this->anything(), $this->isArray());
$this->commandTester->setInputs(['no']);
$this->commandTester->execute([]);
}
public static function provideCommands(): iterable
{
yield 'no rr binary' => [
false,
'--skip-initialize-db=1 --clear-db-cache=1 --download-rr-binary',
];
yield 'rr binary' => [
true,
'--skip-initialize-db=1 --clear-db-cache=1 --download-rr-binary=1',
];
}
}