Skip to content

Commit d381176

Browse files
MAGETWO-85537: 2907: Integration Test Annotation magentoAppArea breaks with some valid values. #996
2 parents 991aa5b + 3f949d7 commit d381176

File tree

4 files changed

+187
-19
lines changed

4 files changed

+187
-19
lines changed

dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class AppArea
1515
private $_application;
1616

1717
/**
18-
* List of allowed areas
18+
* List of allowed areas.
1919
*
2020
* @var array
2121
*/
2222
private $_allowedAreas = [
2323
\Magento\Framework\App\Area::AREA_GLOBAL,
24-
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
24+
\Magento\Framework\App\Area::AREA_ADMINHTML,
2525
\Magento\Framework\App\Area::AREA_FRONTEND,
26-
'webapi_rest',
27-
'webapi_soap',
28-
'cron',
26+
\Magento\Framework\App\Area::AREA_WEBAPI_REST,
27+
\Magento\Framework\App\Area::AREA_WEBAPI_SOAP,
28+
\Magento\Framework\App\Area::AREA_CRONTAB,
2929
];
3030

3131
/**

dev/tests/integration/framework/Magento/TestFramework/Application.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ public function getArea()
600600
*
601601
* @param string $areaCode
602602
* @return void
603+
* @throws \Magento\Framework\Exception\LocalizedException
603604
*/
604605
public function loadArea($areaCode)
605606
{
@@ -616,7 +617,13 @@ public function loadArea($areaCode)
616617
)
617618
);
618619
$app = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\AreaList::class);
619-
if ($areaCode == \Magento\TestFramework\Application::DEFAULT_APP_AREA) {
620+
$areasForPartialLoading = [
621+
\Magento\Framework\App\Area::AREA_GLOBAL,
622+
\Magento\Framework\App\Area::AREA_WEBAPI_REST,
623+
\Magento\Framework\App\Area::AREA_WEBAPI_SOAP,
624+
\Magento\Framework\App\Area::AREA_CRONTAB,
625+
];
626+
if (in_array($areaCode, $areasForPartialLoading, true)) {
620627
$app->getArea($areaCode)->load(\Magento\Framework\App\Area::PART_CONFIG);
621628
} else {
622629
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($areaCode);

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Test\Annotation;
78

9+
use Magento\Framework\App\Area;
10+
811
class AppAreaTest extends \PHPUnit\Framework\TestCase
912
{
1013
/**
@@ -13,12 +16,12 @@ class AppAreaTest extends \PHPUnit\Framework\TestCase
1316
protected $_object;
1417

1518
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
19+
* @var \Magento\TestFramework\Application|\PHPUnit_Framework_MockObject_MockObject
1720
*/
1821
protected $_applicationMock;
1922

2023
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
24+
* @var \PHPUnit\Framework\TestCase|\PHPUnit_Framework_MockObject_MockObject
2225
*/
2326
protected $_testCaseMock;
2427

@@ -69,6 +72,22 @@ public function testGetTestAppAreaWithInvalidArea()
6972
$this->_object->startTest($this->_testCaseMock);
7073
}
7174

75+
/**
76+
* Check startTest() with different allowed area codes.
77+
*
78+
* @dataProvider startTestWithDifferentAreaCodes
79+
* @param string $areaCode
80+
*/
81+
public function testStartTestWithDifferentAreaCodes(string $areaCode)
82+
{
83+
$annotations = ['method' => ['magentoAppArea' => [$areaCode]]];
84+
$this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
85+
$this->_applicationMock->expects($this->any())->method('getArea')->willReturn(null);
86+
$this->_applicationMock->expects($this->once())->method('reinitialize');
87+
$this->_applicationMock->expects($this->once())->method('loadArea')->with($areaCode);
88+
$this->_object->startTest($this->_testCaseMock);
89+
}
90+
7291
public function testStartTestPreventDoubleAreaLoadingAfterReinitialization()
7392
{
7493
$annotations = ['method' => ['magentoAppArea' => ['global']]];
@@ -89,4 +108,33 @@ public function testStartTestPreventDoubleAreaLoading()
89108
$this->_applicationMock->expects($this->never())->method('loadArea');
90109
$this->_object->startTest($this->_testCaseMock);
91110
}
111+
112+
/**
113+
* Provide test data for testStartTestWithDifferentAreaCodes().
114+
*
115+
* @return array
116+
*/
117+
public function startTestWithDifferentAreaCodes()
118+
{
119+
return [
120+
[
121+
'area_code' => Area::AREA_GLOBAL,
122+
],
123+
[
124+
'area_code' => Area::AREA_ADMINHTML,
125+
],
126+
[
127+
'area_code' => Area::AREA_FRONTEND,
128+
],
129+
[
130+
'area_code' => Area::AREA_WEBAPI_REST,
131+
],
132+
[
133+
'area_code' => Area::AREA_WEBAPI_SOAP,
134+
],
135+
[
136+
'area_code' => Area::AREA_CRONTAB,
137+
],
138+
];
139+
}
92140
}

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php

Lines changed: 124 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,71 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Test;
78

9+
use Magento\Framework\App\Area;
10+
use Magento\Framework\App\AreaList;
811
use Magento\Framework\App\Bootstrap;
12+
use Magento\Framework\App\ObjectManager\ConfigLoader;
913
use Magento\Framework\App\State;
14+
use Magento\Framework\Autoload\ClassLoaderWrapper;
15+
use Magento\Framework\Config\Scope;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\Framework\Shell;
18+
use Magento\TestFramework\Application;
1019

20+
/**
21+
* Provide tests for \Magento\TestFramework\Application.
22+
*/
1123
class ApplicationTest extends \PHPUnit\Framework\TestCase
1224
{
1325
/**
14-
* @covers \Magento\TestFramework\Application::getTempDir
15-
* @covers \Magento\TestFramework\Application::getDbInstance()
16-
* @covers \Magento\TestFramework\Application::getInitParams()
26+
* Test subject.
27+
*
28+
* @var Application
1729
*/
18-
public function testConstructor()
30+
private $subject;
31+
32+
/**
33+
* @var string
34+
*/
35+
private $tempDir;
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
protected function setUp()
1941
{
20-
$shell = $this->createMock(\Magento\Framework\Shell::class);
21-
$autoloadWrapper = $this->getMockBuilder(\Magento\Framework\Autoload\ClassLoaderWrapper::class)
42+
/** @var Shell|\PHPUnit_Framework_MockObject_MockObject $shell */
43+
$shell = $this->createMock(Shell::class);
44+
/** @var ClassLoaderWrapper|\PHPUnit_Framework_MockObject_MockObject $autoloadWrapper */
45+
$autoloadWrapper = $this->getMockBuilder(ClassLoaderWrapper::class)
2246
->disableOriginalConstructor()->getMock();
23-
$tempDir = '/temp/dir';
47+
$this->tempDir = '/temp/dir';
2448
$appMode = \Magento\Framework\App\State::MODE_DEVELOPER;
2549

26-
$object = new \Magento\TestFramework\Application(
50+
$this->subject = new Application(
2751
$shell,
28-
$tempDir,
52+
$this->tempDir,
2953
'config.php',
3054
'global-config.php',
3155
'',
3256
$appMode,
3357
$autoloadWrapper
3458
);
59+
}
3560

36-
$this->assertEquals($tempDir, $object->getTempDir(), 'Temp directory is not set in Application');
61+
/**
62+
* @covers \Magento\TestFramework\Application::getTempDir
63+
* @covers \Magento\TestFramework\Application::getDbInstance()
64+
* @covers \Magento\TestFramework\Application::getInitParams()
65+
*/
66+
public function testConstructor()
67+
{
68+
$this->assertEquals($this->tempDir, $this->subject->getTempDir(), 'Temp directory is not set in Application');
3769

38-
$initParams = $object->getInitParams();
70+
$initParams = $this->subject->getInitParams();
3971
$this->assertInternalType('array', $initParams, 'Wrong initialization parameters type');
4072
$this->assertArrayHasKey(
4173
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS,
@@ -49,4 +81,85 @@ public function testConstructor()
4981
'Wrong application mode configured'
5082
);
5183
}
84+
85+
/**
86+
* Test \Magento\TestFramework\Application will correctly load specified areas.
87+
*
88+
* @dataProvider partialLoadAreaDataProvider
89+
* @param string $areaCode
90+
*/
91+
public function testPartialLoadArea(string $areaCode)
92+
{
93+
$configScope = $this->getMockBuilder(Scope::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$configScope->expects($this->once())
97+
->method('setCurrentScope')
98+
->with($this->identicalTo($areaCode));
99+
100+
$configLoader = $this->getMockBuilder(ConfigLoader::class)
101+
->disableOriginalConstructor()
102+
->getMock();
103+
$configLoader->expects($this->once())
104+
->method('load')
105+
->with($this->identicalTo($areaCode))
106+
->willReturn([]);
107+
108+
$area = $this->getMockBuilder(Area::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$area->expects($this->once())
112+
->method('load')
113+
->with($this->identicalTo(Area::PART_CONFIG));
114+
115+
$areaList = $this->getMockBuilder(AreaList::class)
116+
->disableOriginalConstructor()
117+
->getMock();
118+
$areaList->expects($this->once())
119+
->method('getArea')
120+
->with($this->identicalTo($areaCode))
121+
->willReturn($area);
122+
123+
/** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
124+
$objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
$objectManager->expects($this->once())
128+
->method('configure')
129+
->with($this->identicalTo([]));
130+
$objectManager->expects($this->exactly(3))
131+
->method('get')
132+
->willReturnOnConsecutiveCalls(
133+
$configScope,
134+
$configLoader,
135+
$areaList
136+
);
137+
138+
\Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager);
139+
140+
$this->subject->loadArea($areaCode);
141+
}
142+
143+
/**
144+
* Provide test data for testPartialLoadArea().
145+
*
146+
* @return array
147+
*/
148+
public function partialLoadAreaDataProvider()
149+
{
150+
return [
151+
[
152+
'area_code' => Area::AREA_GLOBAL,
153+
],
154+
[
155+
'area_code' => Area::AREA_WEBAPI_REST,
156+
],
157+
[
158+
'area_code' => Area::AREA_WEBAPI_SOAP,
159+
],
160+
[
161+
'area_code' => Area::AREA_CRONTAB,
162+
],
163+
];
164+
}
52165
}

0 commit comments

Comments
 (0)