11 use Symfony\Component\Console\Tester\CommandTester;
20 $this->directoryWriteMock->expects($this->once())
23 ->willReturn($authExist);
24 $this->directoryWriteMock->expects($authExist ? $this->never() : $this->once())->method(
'writeFile')->with(
28 $this->filesystemMock->expects($this->once())
29 ->method(
'getDirectoryWrite')
31 ->willReturn($this->directoryWriteMock);
43 public function testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg, $authExist)
45 $this->
setupMocks($sampleDataPackages,
'/path/to/composer.json', $appRunResult);
47 $commandTester = $this->createCommandTester();
48 $commandTester->execute([]);
50 $this->assertEquals($expectedMsg, $commandTester->getDisplay());
66 '/path/to/composer.json',
71 $commandInput = [
'--no-update' => 1];
73 $commandTester = $this->createCommandTester();
74 $commandTester->execute($commandInput);
76 $this->assertEquals($expectedMsg, $commandTester->getDisplay());
85 'No sample data found' => [
86 'sampleDataPackages' => [],
88 'expectedMsg' =>
'There is no sample data for current set of modules.' . PHP_EOL,
91 'No auth.json found' => [
92 'sampleDataPackages' => [
93 'magento/module-cms-sample-data' =>
'1.0.0-beta',
96 'expectedMsg' =>
'There is an error during sample data deployment. Composer file will be reverted.' 100 'Successful sample data installation' => [
101 'sampleDataPackages' => [
102 'magento/module-cms-sample-data' =>
'1.0.0-beta',
118 $this->directoryReadMock->expects($this->once())
120 ->with(
'composer.json')
121 ->willReturn(
'{"version": "0.0.1"}');
122 $this->filesystemMock->expects($this->once())
123 ->method(
'getDirectoryRead')
125 ->willReturn($this->directoryReadMock);
127 $this->directoryWriteMock->expects($this->once())
131 $this->directoryWriteMock->expects($this->once())
132 ->method(
'writeFile')
134 ->willThrowException(
new \Exception(
'Something went wrong...'));
135 $this->directoryWriteMock->expects($this->once())
136 ->method(
'getAbsolutePath')
138 ->willReturn(
'path/to/auth.json');
139 $this->filesystemMock->expects($this->once())
140 ->method(
'getDirectoryWrite')
142 ->willReturn($this->directoryWriteMock);
144 $this->createCommandTester()->execute([]);
150 private function createCommandTester(): CommandTester
152 $commandTester =
new CommandTester(
154 $this->filesystemMock,
155 $this->sampleDataDependencyMock,
156 $this->arrayInputFactoryMock,
157 $this->applicationFactoryMock
160 return $commandTester;
169 array $sampleDataPackages,
170 string $pathToComposerJson
173 'command' =>
'require',
174 '--working-dir' => $pathToComposerJson,
175 '--no-progress' => 1,
176 'packages' => $this->packageVersionStrings($sampleDataPackages),
184 private function packageVersionStrings(array $sampleDataPackages): array
186 array_walk($sampleDataPackages,
function (&$v, $k) {
190 return array_values($sampleDataPackages);
setupMocks( $sampleDataPackages, $pathToComposerJson, $appRunResult, $additionalComposerArgs=[])
testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg, $authExist)
expectedComposerArguments(array $sampleDataPackages, string $pathToComposerJson)
testExecuteWithException()
setupMocksForAuthFile($authExist)
testExecuteWithNoUpdate(array $sampleDataPackages, $appRunResult, $expectedMsg, $authExist)