13 use Symfony\Component\Console\Input\ArgvInput;
14 use Zend\ServiceManager\ServiceManager;
16 use PHPUnit_Framework_MockObject_MockObject as Mock;
28 private $serviceManagerMock;
38 private $filesystemDriverMock;
43 private $generationDirectoryAccessMock;
50 $this->serviceManagerMock = $this->getMockBuilder(ServiceManager::class)
51 ->disableOriginalConstructor()
53 $this->inputMock = $this->getMockBuilder(ArgvInput::class)
54 ->disableOriginalConstructor()
56 $this->filesystemDriverMock = $this->getMockBuilder(File::class)
57 ->disableOriginalConstructor()
59 $this->generationDirectoryAccessMock = $this->getMockBuilder(GenerationDirectoryAccess::class)
60 ->disableOriginalConstructor()
64 CompilerPreparation::class,
66 'serviceManager' => $this->serviceManagerMock,
67 'input' => $this->inputMock,
68 'filesystemDriver' => $this->filesystemDriverMock,
69 'generationDirectoryAccess' => $this->generationDirectoryAccessMock,
83 $this->inputMock->expects($this->once())
84 ->method(
'getFirstArgument')
85 ->willReturn($commandName);
86 $this->inputMock->expects($this->atLeastOnce())
87 ->method(
'hasParameterOption')
88 ->with($this->logicalOr(
'--help',
'-h'))
89 ->willReturn($isHelpOption);
91 if ($isCompileCommand && !$isHelpOption) {
92 $this->filesystemDriverMock->expects($this->exactly(2))
94 ->willReturn($dirExists);
95 $this->filesystemDriverMock->expects($this->exactly(((
int)$dirExists) * 2))
96 ->method(
'deleteDirectory');
98 $this->filesystemDriverMock->expects($this->never())
100 $this->filesystemDriverMock->expects($this->never())
101 ->method(
'deleteDirectory');
104 $this->generationDirectoryAccessMock->expects($this->any())
108 $this->model->handleCompilerEnvironment();
117 'ST compiler, directory exists' => [
119 'isCompileCommand' =>
true,
120 'isHelpOption' =>
false,
123 'ST compiler, directory does not exist' => [
125 'isCompileCommand' =>
true,
126 'isHelpOption' =>
false,
129 'ST compiler, help option' => [
131 'isCompileCommand' =>
true,
132 'isHelpOption' =>
true,
136 'commandName' =>
'not:a:compiler',
137 'isCompileCommand' =>
false,
138 'isHelpOption' =>
false,
145 $customGenerationDirectory =
'/custom/generated/code/directory';
146 $defaultDiDirectory =
'/custom/di/directory';
147 $mageInitParams = [
'MAGE_DIRS' => [
'generation' => [
'path' => $customGenerationDirectory]]];
150 $customGenerationDirectory,
159 $this->inputMock->expects($this->once())
160 ->method(
'getFirstArgument')
162 $this->filesystemDriverMock->expects($this->exactly(2))
165 $this->filesystemDriverMock->expects($this->exactly(2))
166 ->method(
'deleteDirectory')
167 ->willReturnMap($dirValueMap);
168 $this->serviceManagerMock->expects($this->once())
171 ->willReturn($mageInitParams);
172 $this->generationDirectoryAccessMock->expects($this->once())
176 $this->model->handleCompilerEnvironment();
181 $customGenerationDirectory =
'/custom/generated/code/directory';
182 $customDiDirectory =
'/custom/di/directory';
185 $this->logicalNot($this->equalTo($customGenerationDirectory)),
186 $this->logicalNot($this->equalTo($customDiDirectory))
194 $this->inputMock->expects($this->once())
195 ->method(
'getFirstArgument')
197 $this->filesystemDriverMock->expects($this->exactly(2))
200 $this->filesystemDriverMock->expects($this->exactly(2))
201 ->method(
'deleteDirectory')
202 ->willReturnMap($dirResultMap);
203 $this->generationDirectoryAccessMock->expects($this->once())
207 $this->model->handleCompilerEnvironment();
testClearGenerationDirWhenNeeded($commandName, $isCompileCommand, $isHelpOption, $dirExists=false)
commandNameDataProvider()
testGenerationDirectoryFromInitParams()
testGenerationDirectoryFromCliOption()