|
7 | 7 | class CompilerTest extends \PHPUnit_Framework_TestCase
|
8 | 8 | {
|
9 | 9 | /**
|
10 |
| - * @var \Magento\Tools\Di\App\Compiler |
| 10 | + * @var Compiler |
11 | 11 | */
|
12 | 12 | private $model;
|
13 | 13 |
|
14 | 14 | /**
|
15 |
| - * @var \Magento\Framework\App\AreaList | \PHPUnit_Framework_MockObject_MockObject |
| 15 | + * @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject |
16 | 16 | */
|
17 |
| - private $areaList; |
| 17 | + private $objectManagerMock; |
18 | 18 |
|
19 | 19 | /**
|
20 |
| - * @var \Magento\Tools\Di\Code\Reader\ClassesScanner | \PHPUnit_Framework_MockObject_MockObject |
| 20 | + * @var \Magento\Tools\Di\App\Task\Manager | \PHPUnit_Framework_MockObject_MockObject |
21 | 21 | */
|
22 |
| - private $classesScanner; |
| 22 | + private $taskManagerMock; |
23 | 23 |
|
24 | 24 | /**
|
25 |
| - * @var \Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder | \PHPUnit_Framework_MockObject_MockObject |
| 25 | + * @var \Magento\Framework\App\Console\Response | \PHPUnit_Framework_MockObject_MockObject |
26 | 26 | */
|
27 |
| - private $interceptionConfigurationBuilder; |
28 |
| - |
29 |
| - /** |
30 |
| - * @var \Magento\Tools\Di\Compiler\Config\Reader | \PHPUnit_Framework_MockObject_MockObject |
31 |
| - */ |
32 |
| - private $configReader; |
33 |
| - |
34 |
| - /** |
35 |
| - * @var \Magento\Tools\Di\Compiler\Config\Writer\Filesystem | \PHPUnit_Framework_MockObject_MockObject |
36 |
| - */ |
37 |
| - private $configWriter; |
| 27 | + private $responseMock; |
38 | 28 |
|
39 | 29 | protected function setUp()
|
40 | 30 | {
|
41 |
| - $this->areaList = $this->getMockBuilder('\Magento\Framework\App\AreaList') |
42 |
| - ->disableOriginalConstructor() |
| 31 | + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') |
| 32 | + ->setMethods([]) |
43 | 33 | ->getMock();
|
44 |
| - |
45 |
| - $this->classesScanner = $this->getMockBuilder('\Magento\Tools\Di\Code\Reader\ClassesScanner') |
| 34 | + $this->taskManagerMock = $this->getMockBuilder('Magento\Tools\Di\App\Task\Manager') |
46 | 35 | ->disableOriginalConstructor()
|
47 |
| - ->setMethods(['getList']) |
| 36 | + ->setMethods([]) |
48 | 37 | ->getMock();
|
49 |
| - |
50 |
| - $this->interceptionConfigurationBuilder = $this->getMockBuilder( |
51 |
| - '\Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder' |
52 |
| - )->disableOriginalConstructor()->getMock(); |
53 |
| - |
54 |
| - $this->configReader = $this->getMockBuilder('\Magento\Tools\Di\Compiler\Config\Reader') |
| 38 | + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Console\Response') |
55 | 39 | ->disableOriginalConstructor()
|
| 40 | + ->setMethods([]) |
56 | 41 | ->getMock();
|
57 |
| - |
58 |
| - $this->configWriter = $this->getMockBuilder('\Magento\Tools\Di\Compiler\Config\Writer\Filesystem') |
59 |
| - ->setMethods(['write']) |
60 |
| - ->getMock(); |
61 |
| - |
62 |
| - $this->model = new \Magento\Tools\Di\App\Compiler( |
63 |
| - $this->areaList, |
64 |
| - $this->classesScanner, |
65 |
| - $this->interceptionConfigurationBuilder, |
66 |
| - $this->configReader, |
67 |
| - $this->configWriter |
| 42 | + $this->model = new Compiler( |
| 43 | + $this->taskManagerMock, |
| 44 | + $this->objectManagerMock, |
| 45 | + $this->responseMock |
68 | 46 | );
|
69 | 47 | }
|
70 | 48 |
|
71 |
| - public function testLaunch() |
| 49 | + public function testLaunchSuccess() |
72 | 50 | {
|
73 |
| - $this->classesScanner->expects($this->exactly(3)) |
74 |
| - ->method('getList') |
75 |
| - ->willReturn([]); |
76 |
| - |
77 |
| - $this->configReader->expects($this->any()) |
78 |
| - ->method('generateCachePerScope') |
79 |
| - ->willReturn([]); |
| 51 | + $this->objectManagerMock->expects($this->once()) |
| 52 | + ->method('configure') |
| 53 | + ->with($this->getPreferences()); |
| 54 | + $index = 0; |
| 55 | + foreach ($this->getOptions() as $code => $arguments) { |
| 56 | + $this->taskManagerMock->expects($this->at($index)) |
| 57 | + ->method('addOperation') |
| 58 | + ->with($code, $arguments); |
| 59 | + $index++; |
| 60 | + } |
| 61 | + $this->taskManagerMock->expects($this->at($index))->method('process'); |
| 62 | + $this->responseMock->expects($this->once()) |
| 63 | + ->method('setCode') |
| 64 | + ->with(\Magento\Framework\App\Console\Response::SUCCESS); |
80 | 65 |
|
81 |
| - $areaListResult = ['global', 'frontend', 'admin']; |
82 |
| - $this->areaList->expects($this->once()) |
83 |
| - ->method('getCodes') |
84 |
| - ->willReturn($areaListResult); |
| 66 | + $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); |
| 67 | + } |
85 | 68 |
|
86 |
| - $count = count($areaListResult) + 1; |
87 |
| - $this->configWriter->expects($this->exactly($count)) |
88 |
| - ->method('write'); |
| 69 | + public function testLaunchException() |
| 70 | + { |
| 71 | + $this->objectManagerMock->expects($this->once()) |
| 72 | + ->method('configure') |
| 73 | + ->with($this->getPreferences()); |
| 74 | + $code = key($this->getOptions()); |
| 75 | + $arguments = current($this->getOptions()); |
| 76 | + $exception = new Task\OperationException( |
| 77 | + 'Unrecognized operation', |
| 78 | + Task\OperationException::UNAVAILABLE_OPERATION |
| 79 | + ); |
89 | 80 |
|
90 |
| - $this->interceptionConfigurationBuilder->expects($this->exactly($count)) |
91 |
| - ->method('addAreaCode'); |
| 81 | + $this->taskManagerMock->expects($this->once()) |
| 82 | + ->method('addOperation') |
| 83 | + ->with($code, $arguments) |
| 84 | + ->willThrowException($exception); |
92 | 85 |
|
93 |
| - $this->interceptionConfigurationBuilder->expects($this->once()) |
94 |
| - ->method('getInterceptionConfiguration') |
95 |
| - ->willReturn([]); |
| 86 | + $this->taskManagerMock->expects($this->never())->method('process'); |
| 87 | + $this->responseMock->expects($this->once()) |
| 88 | + ->method('setCode') |
| 89 | + ->with(\Magento\Framework\App\Console\Response::ERROR); |
96 | 90 |
|
97 | 91 | $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch());
|
98 | 92 | }
|
| 93 | + |
| 94 | + /** |
| 95 | + * Returns configured preferences |
| 96 | + * |
| 97 | + * @return array |
| 98 | + */ |
| 99 | + private function getPreferences() |
| 100 | + { |
| 101 | + return [ |
| 102 | + 'preferences' => |
| 103 | + [ |
| 104 | + 'Magento\Tools\Di\Compiler\Config\WriterInterface' => |
| 105 | + 'Magento\Tools\Di\Compiler\Config\Writer\Filesystem' |
| 106 | + ] |
| 107 | + ]; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Returns options |
| 112 | + * |
| 113 | + * @return array |
| 114 | + */ |
| 115 | + private function getOptions() |
| 116 | + { |
| 117 | + return [ |
| 118 | + Task\OperationFactory::AREA => [ |
| 119 | + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' |
| 120 | + ], |
| 121 | + Task\OperationFactory::INTERCEPTION => |
| 122 | + BP . '/var/generation', |
| 123 | + Task\OperationFactory::INTERCEPTION_CACHE => [ |
| 124 | + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' |
| 125 | + ] |
| 126 | + ]; |
| 127 | + } |
99 | 128 | }
|
0 commit comments