Skip to content

Commit 4a045d9

Browse files
author
Kostiantyn Poida
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-31111' into develop
2 parents c7c47e7 + 7d2842f commit 4a045d9

File tree

22 files changed

+766
-205
lines changed

22 files changed

+766
-205
lines changed

dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Framework\Interception;
77

8-
use Magento\Framework\ObjectManager\Config\Config as ObjectManagerConfig;
9-
108
/**
119
* Class GeneralTest
1210
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)

dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public function createPluginsAndRelationsReadableDataProvider()
9191
{
9292
return [
9393
'relations' => [
94-
'DefinitionDir/relations.php',
94+
'DefinitionDir/relations.ser',
9595
'createRelations',
9696
'\Magento\Framework\ObjectManager\Relations\Compiled',
9797
],
9898
'plugins' => [
99-
'DefinitionDir/plugins.php',
99+
'DefinitionDir/plugins.ser',
100100
'createPluginDefinition',
101101
'\Magento\Framework\Interception\Definition\Compiled',
102102
],
@@ -121,12 +121,12 @@ public function createPluginsAndRelationsNotReadableDataProvider()
121121
{
122122
return [
123123
'relations' => [
124-
'DefinitionDir/relations.php',
124+
'DefinitionDir/relations.ser',
125125
'createRelations',
126126
'\Magento\Framework\ObjectManager\Relations\Runtime',
127127
],
128128
'plugins' => [
129-
'DefinitionDir/plugins.php',
129+
'DefinitionDir/plugins.ser',
130130
'createPluginDefinition',
131131
'\Magento\Framework\Interception\Definition\Runtime',
132132
],

dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php

Lines changed: 88 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,93 +7,122 @@
77
class CompilerTest extends \PHPUnit_Framework_TestCase
88
{
99
/**
10-
* @var \Magento\Tools\Di\App\Compiler
10+
* @var Compiler
1111
*/
1212
private $model;
1313

1414
/**
15-
* @var \Magento\Framework\App\AreaList | \PHPUnit_Framework_MockObject_MockObject
15+
* @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject
1616
*/
17-
private $areaList;
17+
private $objectManagerMock;
1818

1919
/**
20-
* @var \Magento\Tools\Di\Code\Reader\ClassesScanner | \PHPUnit_Framework_MockObject_MockObject
20+
* @var \Magento\Tools\Di\App\Task\Manager | \PHPUnit_Framework_MockObject_MockObject
2121
*/
22-
private $classesScanner;
22+
private $taskManagerMock;
2323

2424
/**
25-
* @var \Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder | \PHPUnit_Framework_MockObject_MockObject
25+
* @var \Magento\Framework\App\Console\Response | \PHPUnit_Framework_MockObject_MockObject
2626
*/
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;
3828

3929
protected function setUp()
4030
{
41-
$this->areaList = $this->getMockBuilder('\Magento\Framework\App\AreaList')
42-
->disableOriginalConstructor()
31+
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
32+
->setMethods([])
4333
->getMock();
44-
45-
$this->classesScanner = $this->getMockBuilder('\Magento\Tools\Di\Code\Reader\ClassesScanner')
34+
$this->taskManagerMock = $this->getMockBuilder('Magento\Tools\Di\App\Task\Manager')
4635
->disableOriginalConstructor()
47-
->setMethods(['getList'])
36+
->setMethods([])
4837
->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')
5539
->disableOriginalConstructor()
40+
->setMethods([])
5641
->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
6846
);
6947
}
7048

71-
public function testLaunch()
49+
public function testLaunchSuccess()
7250
{
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);
8065

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+
}
8568

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+
);
8980

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);
9285

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);
9690

9791
$this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch());
9892
}
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+
}
99128
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
7+
namespace Magento\Tools\Di\App\Task;
8+
9+
use Magento\Framework\App;
10+
use Magento\Tools\Di\App\Task\Operation\Area;
11+
use Magento\Tools\Di\Code\Reader\ClassesScanner;
12+
use Magento\Tools\Di\Compiler\Config;
13+
use Magento\Tools\Di\Definition\Collection as DefinitionsCollection;
14+
15+
class AreaTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var App\AreaList | \PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $areaListMock;
21+
22+
/**
23+
* @var ClassesScanner | \PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $classesScannerMock;
26+
27+
/**
28+
* @var Config\Reader | \PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $configReaderMock;
31+
32+
/**
33+
* @var Config\WriterInterface | \PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $configWriterMock;
36+
37+
protected function setUp()
38+
{
39+
$this->areaListMock = $this->getMockBuilder('Magento\Framework\App\AreaList')
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->classesScannerMock = $this->getMockBuilder('Magento\Tools\Di\Code\Reader\ClassesScanner')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$this->configReaderMock = $this->getMockBuilder('Magento\Tools\Di\Compiler\Config\Reader')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
$this->configWriterMock = $this->getMockBuilder('Magento\Tools\Di\Compiler\Config\WriterInterface')
49+
->disableOriginalConstructor()
50+
->getMock();
51+
}
52+
53+
public function testDoOperationEmptyPath()
54+
{
55+
$areaOperation = new Area(
56+
$this->areaListMock,
57+
$this->classesScannerMock,
58+
$this->configReaderMock,
59+
$this->configWriterMock
60+
);
61+
62+
$this->assertNull($areaOperation->doOperation());
63+
}
64+
65+
public function testDoOperationGlobalArea()
66+
{
67+
$path = 'path/to/codebase/';
68+
$generatedConfig = [
69+
'arguments' => [],
70+
'nonShared' => [],
71+
'preferences' => [],
72+
'instanceTypes' => []
73+
];
74+
$definitions = new DefinitionsCollection();
75+
$definitions->addDefinition('class', []);
76+
$areaOperation = new Area(
77+
$this->areaListMock,
78+
$this->classesScannerMock,
79+
$this->configReaderMock,
80+
$this->configWriterMock,
81+
[$path]
82+
);
83+
84+
$this->areaListMock->expects($this->once())
85+
->method('getCodes')
86+
->willReturn([]);
87+
$this->classesScannerMock->expects($this->once())
88+
->method('getList')
89+
->with($path)
90+
->willReturn(['class' => []]);
91+
$this->configReaderMock->expects($this->once())
92+
->method('generateCachePerScope')
93+
->with(
94+
$this->isInstanceOf('Magento\Tools\Di\Definition\Collection'),
95+
App\Area::AREA_GLOBAL
96+
)
97+
->willReturn($generatedConfig);
98+
$this->configWriterMock->expects($this->once())
99+
->method('write')
100+
->with(
101+
App\Area::AREA_GLOBAL,
102+
$generatedConfig
103+
);
104+
105+
$areaOperation->doOperation();
106+
}
107+
}

0 commit comments

Comments
 (0)