From 1cd27f466b002b874dfb75a303b09ede6ea70918 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Mon, 11 Dec 2017 17:19:19 +0200 Subject: [PATCH 1/6] 2907: Integration Test Annotation magentoAppArea breaks with some valid values. --- .../Magento/TestFramework/Annotation/AppArea.php | 10 +++++----- .../framework/Magento/TestFramework/Application.php | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php index 3ef7cd608c779..6a63a96d47849 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php @@ -15,17 +15,17 @@ class AppArea private $_application; /** - * List of allowed areas + * List of allowed areas. * * @var array */ private $_allowedAreas = [ \Magento\Framework\App\Area::AREA_GLOBAL, - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + \Magento\Framework\App\Area::AREA_ADMINHTML, \Magento\Framework\App\Area::AREA_FRONTEND, - 'webapi_rest', - 'webapi_soap', - 'cron', + \Magento\Framework\App\Area::AREA_WEBAPI_REST, + \Magento\Framework\App\Area::AREA_WEBAPI_SOAP, + \Magento\Framework\App\Area::AREA_CRONTAB, ]; /** diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index e0cd3c52e2ca3..e8ad9d156a309 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -600,6 +600,7 @@ public function getArea() * * @param string $areaCode * @return void + * @throws \Magento\Framework\Exception\LocalizedException */ public function loadArea($areaCode) { @@ -616,7 +617,14 @@ public function loadArea($areaCode) ) ); $app = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\AreaList::class); - if ($areaCode == \Magento\TestFramework\Application::DEFAULT_APP_AREA) { + $areasForPartialLoading = [ + \Magento\Framework\App\Area::AREA_GLOBAL, + \Magento\Framework\App\Area::AREA_WEBAPI_REST, + \Magento\Framework\App\Area::AREA_WEBAPI_SOAP, + \Magento\Framework\App\Area::AREA_CRONTAB, + + ]; + if (in_array($areaCode, $areasForPartialLoading, true)) { $app->getArea($areaCode)->load(\Magento\Framework\App\Area::PART_CONFIG); } else { \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($areaCode); From 059c8b4374babf0f8c437cfb1cddd63b15d48522 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 12 Dec 2017 10:44:23 +0200 Subject: [PATCH 2/6] 2907: Integration Test Annotation magentoAppArea breaks with some valid values. --- .../integration/framework/Magento/TestFramework/Application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index e8ad9d156a309..368d756b88054 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -622,7 +622,6 @@ public function loadArea($areaCode) \Magento\Framework\App\Area::AREA_WEBAPI_REST, \Magento\Framework\App\Area::AREA_WEBAPI_SOAP, \Magento\Framework\App\Area::AREA_CRONTAB, - ]; if (in_array($areaCode, $areasForPartialLoading, true)) { $app->getArea($areaCode)->load(\Magento\Framework\App\Area::PART_CONFIG); From 70122b57918fd8709f48afedbc85c1de2802a71b Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 12 Dec 2017 14:47:14 +0200 Subject: [PATCH 3/6] 2907: magento/magento2#2907: Integration Test Annotation magentoAppArea breaks with some valid values --- .../Magento/Test/Annotation/AppAreaTest.php | 52 +++++- .../Magento/Test/ApplicationTest.php | 171 ++++++++++++++++-- 2 files changed, 210 insertions(+), 13 deletions(-) diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php index a4c8816b13ee1..dd361a5d0ed74 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php @@ -3,8 +3,11 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Test\Annotation; +use Magento\Framework\App\Area; + class AppAreaTest extends \PHPUnit\Framework\TestCase { /** @@ -13,12 +16,12 @@ class AppAreaTest extends \PHPUnit\Framework\TestCase protected $_object; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\TestFramework\Application|\PHPUnit_Framework_MockObject_MockObject */ protected $_applicationMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\TestCase|\PHPUnit_Framework_MockObject_MockObject */ protected $_testCaseMock; @@ -69,6 +72,22 @@ public function testGetTestAppAreaWithInvalidArea() $this->_object->startTest($this->_testCaseMock); } + /** + * Check startTest() with different allowed area codes. + * + * @dataProvider startTestWithDifferentAreaCodes + * @param string $areaCode + */ + public function testStartTestWithDifferentAreaCodes(string $areaCode) + { + $annotations = ['method' => ['magentoAppArea' => [$areaCode]]]; + $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations)); + $this->_applicationMock->expects($this->any())->method('getArea')->willReturn(null); + $this->_applicationMock->expects($this->once())->method('reinitialize'); + $this->_applicationMock->expects($this->once())->method('loadArea')->with($areaCode); + $this->_object->startTest($this->_testCaseMock); + } + public function testStartTestPreventDoubleAreaLoadingAfterReinitialization() { $annotations = ['method' => ['magentoAppArea' => ['global']]]; @@ -89,4 +108,33 @@ public function testStartTestPreventDoubleAreaLoading() $this->_applicationMock->expects($this->never())->method('loadArea'); $this->_object->startTest($this->_testCaseMock); } + + /** + * Provide test data for testStartTestWithDifferentAreaCodes(). + * + * @return array + */ + public function startTestWithDifferentAreaCodes() + { + return [ + [ + 'area_code' => Area::AREA_GLOBAL, + ], + [ + 'area_code' => Area::AREA_ADMINHTML, + ], + [ + 'area_code' => Area::AREA_FRONTEND, + ], + [ + 'area_code' => Area::AREA_WEBAPI_REST, + ], + [ + 'area_code' => Area::AREA_WEBAPI_SOAP, + ], + [ + 'area_code' => Area::AREA_CRONTAB, + ], + ]; + } } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php index f8f49613c41b4..ee794fc262a4d 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php @@ -3,39 +3,71 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Test; +use Magento\Framework\App\Area; +use Magento\Framework\App\AreaList; use Magento\Framework\App\Bootstrap; +use Magento\Framework\App\ObjectManager\ConfigLoader; use Magento\Framework\App\State; +use Magento\Framework\Autoload\ClassLoaderWrapper; +use Magento\Framework\Config\Scope; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Shell; +use Magento\TestFramework\Application; +/** + * Provide tests for \Magento\TestFramework\Application. + */ class ApplicationTest extends \PHPUnit\Framework\TestCase { /** - * @covers \Magento\TestFramework\Application::getTempDir - * @covers \Magento\TestFramework\Application::getDbInstance() - * @covers \Magento\TestFramework\Application::getInitParams() + * Test subject. + * + * @var Application */ - public function testConstructor() + private $subject; + + /** + * @var string + */ + private $tempDir; + + /** + * @inheritdoc + */ + protected function setUp() { - $shell = $this->createMock(\Magento\Framework\Shell::class); - $autoloadWrapper = $this->getMockBuilder(\Magento\Framework\Autoload\ClassLoaderWrapper::class) + /** @var Shell|\PHPUnit_Framework_MockObject_MockObject $shell */ + $shell = $this->createMock(Shell::class); + /** @var ClassLoaderWrapper|\PHPUnit_Framework_MockObject_MockObject $autoloadWrapper */ + $autoloadWrapper = $this->getMockBuilder(ClassLoaderWrapper::class) ->disableOriginalConstructor()->getMock(); - $tempDir = '/temp/dir'; + $this->tempDir = '/temp/dir'; $appMode = \Magento\Framework\App\State::MODE_DEVELOPER; - $object = new \Magento\TestFramework\Application( + $this->subject = new Application( $shell, - $tempDir, + $this->tempDir, 'config.php', 'global-config.php', '', $appMode, $autoloadWrapper ); + } - $this->assertEquals($tempDir, $object->getTempDir(), 'Temp directory is not set in Application'); + /** + * @covers \Magento\TestFramework\Application::getTempDir + * @covers \Magento\TestFramework\Application::getDbInstance() + * @covers \Magento\TestFramework\Application::getInitParams() + */ + public function testConstructor() + { + $this->assertEquals($this->tempDir, $this->subject->getTempDir(), 'Temp directory is not set in Application'); - $initParams = $object->getInitParams(); + $initParams = $this->subject->getInitParams(); $this->assertInternalType('array', $initParams, 'Wrong initialization parameters type'); $this->assertArrayHasKey( Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS, @@ -49,4 +81,121 @@ public function testConstructor() 'Wrong application mode configured' ); } + + /** + * Test \Magento\TestFramework\Application will correctly load different areas. + * + * @dataProvider loadAreaDataProvider + * + * @param string $areaCode + * @param bool $partialLoad + */ + public function testLoadArea(string $areaCode, bool $partialLoad) + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock */ + $objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $configScope = $this->getMockBuilder(Scope::class) + ->disableOriginalConstructor() + ->getMock(); + $configScope->expects($this->once()) + ->method('setCurrentScope') + ->with($this->identicalTo($areaCode)); + $configLoader = $this->getMockBuilder(ConfigLoader::class) + ->disableOriginalConstructor() + ->getMock(); + $configLoader->expects($this->once()) + ->method('load') + ->with($this->identicalTo($areaCode)) + ->willReturn([]); + $areaList = $this->getMockBuilder(AreaList::class) + ->disableOriginalConstructor() + ->getMock(); + $area = $this->getMockBuilder(Area::class) + ->disableOriginalConstructor() + ->getMock(); + $appState = $this->getMockBuilder(State::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManagerMock->expects($this->once()) + ->method('configure') + ->with($this->identicalTo([])); + if ($partialLoad) { + $objectManagerMock->expects($this->exactly(3)) + ->method('get') + ->willReturnOnConsecutiveCalls( + $configScope, + $configLoader, + $areaList + ); + $areaList->expects($this->once()) + ->method('getArea') + ->with($this->identicalTo($areaCode)) + ->willReturn($area); + $area->expects($this->once()) + ->method('load') + ->with($this->identicalTo(Area::PART_CONFIG)); + } else { + $area->expects($this->once()) + ->method('load'); + $appState->expects($this->once()) + ->method('setAreaCode') + ->with($this->identicalTo($areaCode)); + $areaList->expects($this->once()) + ->method('getArea') + ->with($this->identicalTo($areaCode)) + ->willReturn($area); + $objectManagerMock->expects($this->exactly(5)) + ->method('get') + ->willReturnOnConsecutiveCalls( + $configScope, + $configLoader, + $areaList, + $appState, + $areaList + ); + } + \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManagerMock); + $this->subject->loadArea($areaCode); + + //restore Object Manager to successfully finish the test. + \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); + } + + /** + * Provide test data for testLoadArea(). + * + * @return array + */ + public function loadAreaDataProvider() + { + return [ + [ + 'area_code' => Area::AREA_GLOBAL, + 'partial_load' => true, + ], + [ + 'area_code' => Area::AREA_ADMINHTML, + 'partial_load' => false, + ], + [ + 'area_code' => Area::AREA_FRONTEND, + 'partial_load' => false, + ], + [ + 'area_code' => Area::AREA_WEBAPI_REST, + 'partial_load' => true, + ], + [ + 'area_code' => Area::AREA_WEBAPI_SOAP, + 'partial_load' => true, + ], + [ + 'area_code' => Area::AREA_CRONTAB, + 'partial_load' => true, + ], + ]; + } } From baaff9580dc804f49f22448b372f7adf9bed683b Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 12 Dec 2017 15:40:02 +0200 Subject: [PATCH 4/6] 2907: magento/magento2#2907: Integration Test Annotation magentoAppArea breaks with some valid values --- .../Magento/Test/ApplicationTest.php | 164 +++++++++++------- 1 file changed, 102 insertions(+), 62 deletions(-) diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php index ee794fc262a4d..9e7f6cc8dd7cf 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php @@ -13,6 +13,7 @@ use Magento\Framework\App\State; use Magento\Framework\Autoload\ClassLoaderWrapper; use Magento\Framework\Config\Scope; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Shell; use Magento\TestFramework\Application; @@ -83,26 +84,20 @@ public function testConstructor() } /** - * Test \Magento\TestFramework\Application will correctly load different areas. + * Test \Magento\TestFramework\Application will correctly load specified areas. * * @dataProvider loadAreaDataProvider - * * @param string $areaCode - * @param bool $partialLoad */ - public function testLoadArea(string $areaCode, bool $partialLoad) + public function testLoadArea(string $areaCode) { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock */ - $objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) - ->disableOriginalConstructor() - ->getMock(); $configScope = $this->getMockBuilder(Scope::class) ->disableOriginalConstructor() ->getMock(); $configScope->expects($this->once()) ->method('setCurrentScope') ->with($this->identicalTo($areaCode)); + $configLoader = $this->getMockBuilder(ConfigLoader::class) ->disableOriginalConstructor() ->getMock(); @@ -113,88 +108,133 @@ public function testLoadArea(string $areaCode, bool $partialLoad) $areaList = $this->getMockBuilder(AreaList::class) ->disableOriginalConstructor() ->getMock(); - $area = $this->getMockBuilder(Area::class) - ->disableOriginalConstructor() - ->getMock(); - $appState = $this->getMockBuilder(State::class) + + /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ + $objectManager = $this->getMockBuilder(ObjectManagerInterface::class) ->disableOriginalConstructor() ->getMock(); - $objectManagerMock->expects($this->once()) + $objectManager->expects($this->once()) ->method('configure') ->with($this->identicalTo([])); - if ($partialLoad) { - $objectManagerMock->expects($this->exactly(3)) - ->method('get') - ->willReturnOnConsecutiveCalls( - $configScope, - $configLoader, - $areaList - ); - $areaList->expects($this->once()) - ->method('getArea') - ->with($this->identicalTo($areaCode)) - ->willReturn($area); - $area->expects($this->once()) - ->method('load') - ->with($this->identicalTo(Area::PART_CONFIG)); - } else { - $area->expects($this->once()) - ->method('load'); - $appState->expects($this->once()) - ->method('setAreaCode') + $objectManager->expects($this->exactly(3)) + ->method('get') + ->willReturnOnConsecutiveCalls( + $configScope, + $configLoader, + $areaList + ); + + \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); + try { + \Magento\TestFramework\Helper\Bootstrap::getInstance(); + } catch (LocalizedException $e) { + /** @var \Magento\TestFramework\Helper\Bootstrap|\PHPUnit_Framework_MockObject_MockObject $bootstrap */ + $bootstrap = $this->getMockBuilder(\Magento\TestFramework\Helper\Bootstrap::class) + ->disableOriginalConstructor() + ->getMock(); + $bootstrap->expects($this->once()) + ->method('loadArea') ->with($this->identicalTo($areaCode)); - $areaList->expects($this->once()) - ->method('getArea') - ->with($this->identicalTo($areaCode)) - ->willReturn($area); - $objectManagerMock->expects($this->exactly(5)) - ->method('get') - ->willReturnOnConsecutiveCalls( - $configScope, - $configLoader, - $areaList, - $appState, - $areaList - ); + \Magento\TestFramework\Helper\Bootstrap::setInstance($bootstrap); } - \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManagerMock); + $this->subject->loadArea($areaCode); + } + + /** + * Test \Magento\TestFramework\Application will correctly load specified areas. + * + * @dataProvider partialLoadAreaDataProvider + * @param string $areaCode + */ + public function testPartialLoadArea(string $areaCode) + { + $configScope = $this->getMockBuilder(Scope::class) + ->disableOriginalConstructor() + ->getMock(); + $configScope->expects($this->once()) + ->method('setCurrentScope') + ->with($this->identicalTo($areaCode)); + + $configLoader = $this->getMockBuilder(ConfigLoader::class) + ->disableOriginalConstructor() + ->getMock(); + $configLoader->expects($this->once()) + ->method('load') + ->with($this->identicalTo($areaCode)) + ->willReturn([]); + + $area = $this->getMockBuilder(Area::class) + ->disableOriginalConstructor() + ->getMock(); + $area->expects($this->once()) + ->method('load') + ->with($this->identicalTo(Area::PART_CONFIG)); + + $areaList = $this->getMockBuilder(AreaList::class) + ->disableOriginalConstructor() + ->getMock(); + $areaList->expects($this->once()) + ->method('getArea') + ->with($this->identicalTo($areaCode)) + ->willReturn($area); + + /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ + $objectManager = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManager->expects($this->once()) + ->method('configure') + ->with($this->identicalTo([])); + $objectManager->expects($this->exactly(3)) + ->method('get') + ->willReturnOnConsecutiveCalls( + $configScope, + $configLoader, + $areaList + ); - //restore Object Manager to successfully finish the test. \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); + + $this->subject->loadArea($areaCode); } /** - * Provide test data for testLoadArea(). + * Provide test data for testPartialLoadArea(). * * @return array */ - public function loadAreaDataProvider() + public function partialLoadAreaDataProvider() { return [ [ 'area_code' => Area::AREA_GLOBAL, - 'partial_load' => true, ], [ - 'area_code' => Area::AREA_ADMINHTML, - 'partial_load' => false, + 'area_code' => Area::AREA_WEBAPI_REST, ], [ - 'area_code' => Area::AREA_FRONTEND, - 'partial_load' => false, + 'area_code' => Area::AREA_WEBAPI_SOAP, ], [ - 'area_code' => Area::AREA_WEBAPI_REST, - 'partial_load' => true, + 'area_code' => Area::AREA_CRONTAB, ], + ]; + } + + /** + * Provide test data for testLoadArea(). + * + * @return array + */ + public function loadAreaDataProvider() + { + return [ [ - 'area_code' => Area::AREA_WEBAPI_SOAP, - 'partial_load' => true, + 'area_code' => Area::AREA_ADMINHTML, ], [ - 'area_code' => Area::AREA_CRONTAB, - 'partial_load' => true, + 'area_code' => Area::AREA_FRONTEND, ], ]; } From 6b749c0b2d8cc6952cae0f2037ae41b1a91ac048 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 12 Dec 2017 16:00:31 +0200 Subject: [PATCH 5/6] magento/magento2#2907 --- .../Magento/Test/ApplicationTest.php | 96 +++++++++---------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php index 9e7f6cc8dd7cf..47c3ef64280b9 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php @@ -85,37 +85,59 @@ public function testConstructor() /** * Test \Magento\TestFramework\Application will correctly load specified areas. - * - * @dataProvider loadAreaDataProvider - * @param string $areaCode */ - public function testLoadArea(string $areaCode) + public function testBackEndLoadArea() { - $configScope = $this->getMockBuilder(Scope::class) - ->disableOriginalConstructor() - ->getMock(); - $configScope->expects($this->once()) - ->method('setCurrentScope') - ->with($this->identicalTo($areaCode)); + $configScope = $this->getMockBuilder(Scope::class)->disableOriginalConstructor()->getMock(); + $configScope->expects($this->once())->method('setCurrentScope')->with($this->identicalTo(Area::AREA_ADMINHTML)); - $configLoader = $this->getMockBuilder(ConfigLoader::class) - ->disableOriginalConstructor() - ->getMock(); + $configLoader = $this->getMockBuilder(ConfigLoader::class)->disableOriginalConstructor()->getMock(); $configLoader->expects($this->once()) ->method('load') - ->with($this->identicalTo($areaCode)) + ->with($this->identicalTo(Area::AREA_ADMINHTML)) ->willReturn([]); - $areaList = $this->getMockBuilder(AreaList::class) - ->disableOriginalConstructor() - ->getMock(); + $areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock(); /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ - $objectManager = $this->getMockBuilder(ObjectManagerInterface::class) + $objectManager = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMock(); + $objectManager->expects($this->once())->method('configure')->with($this->identicalTo([])); + $objectManager->expects($this->exactly(3)) + ->method('get') + ->willReturnOnConsecutiveCalls( + $configScope, + $configLoader, + $areaList + ); + + \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); + + $bootstrap = $this->getMockBuilder(\Magento\TestFramework\Helper\Bootstrap::class) ->disableOriginalConstructor() ->getMock(); - $objectManager->expects($this->once()) - ->method('configure') - ->with($this->identicalTo([])); + $bootstrap->expects($this->once())->method('loadArea')->with($this->identicalTo(Area::AREA_ADMINHTML)); + \Magento\TestFramework\Helper\Bootstrap::setInstance($bootstrap); + + $this->subject->loadArea(Area::AREA_ADMINHTML); + } + + /** + * Test \Magento\TestFramework\Application will correctly load specified areas. + */ + public function testFrontEndLoadArea() + { + $configScope = $this->getMockBuilder(Scope::class)->disableOriginalConstructor()->getMock(); + $configScope->expects($this->once())->method('setCurrentScope')->with($this->identicalTo(Area::AREA_FRONTEND)); + + $configLoader = $this->getMockBuilder(ConfigLoader::class)->disableOriginalConstructor()->getMock(); + $configLoader->expects($this->once()) + ->method('load') + ->with($this->identicalTo(Area::AREA_FRONTEND)) + ->willReturn([]); + $areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock(); + + /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ + $objectManager = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMock(); + $objectManager->expects($this->once())->method('configure')->with($this->identicalTo([])); $objectManager->expects($this->exactly(3)) ->method('get') ->willReturnOnConsecutiveCalls( @@ -125,20 +147,7 @@ public function testLoadArea(string $areaCode) ); \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); - try { - \Magento\TestFramework\Helper\Bootstrap::getInstance(); - } catch (LocalizedException $e) { - /** @var \Magento\TestFramework\Helper\Bootstrap|\PHPUnit_Framework_MockObject_MockObject $bootstrap */ - $bootstrap = $this->getMockBuilder(\Magento\TestFramework\Helper\Bootstrap::class) - ->disableOriginalConstructor() - ->getMock(); - $bootstrap->expects($this->once()) - ->method('loadArea') - ->with($this->identicalTo($areaCode)); - \Magento\TestFramework\Helper\Bootstrap::setInstance($bootstrap); - } - - $this->subject->loadArea($areaCode); + $this->subject->loadArea(Area::AREA_FRONTEND); } /** @@ -221,21 +230,4 @@ public function partialLoadAreaDataProvider() ], ]; } - - /** - * Provide test data for testLoadArea(). - * - * @return array - */ - public function loadAreaDataProvider() - { - return [ - [ - 'area_code' => Area::AREA_ADMINHTML, - ], - [ - 'area_code' => Area::AREA_FRONTEND, - ], - ]; - } } From 7be1e58c14db3af2c47af5702292ed19118e1b9c Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 12 Dec 2017 16:30:20 +0200 Subject: [PATCH 6/6] 2907: magento/magento2#2907: Integration Test Annotation magentoAppArea breaks with some valid values --- .../Magento/Test/ApplicationTest.php | 68 ------------------- 1 file changed, 68 deletions(-) diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php index 47c3ef64280b9..50b18c3a86d48 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php @@ -13,7 +13,6 @@ use Magento\Framework\App\State; use Magento\Framework\Autoload\ClassLoaderWrapper; use Magento\Framework\Config\Scope; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Shell; use Magento\TestFramework\Application; @@ -83,73 +82,6 @@ public function testConstructor() ); } - /** - * Test \Magento\TestFramework\Application will correctly load specified areas. - */ - public function testBackEndLoadArea() - { - $configScope = $this->getMockBuilder(Scope::class)->disableOriginalConstructor()->getMock(); - $configScope->expects($this->once())->method('setCurrentScope')->with($this->identicalTo(Area::AREA_ADMINHTML)); - - $configLoader = $this->getMockBuilder(ConfigLoader::class)->disableOriginalConstructor()->getMock(); - $configLoader->expects($this->once()) - ->method('load') - ->with($this->identicalTo(Area::AREA_ADMINHTML)) - ->willReturn([]); - $areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock(); - - /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ - $objectManager = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMock(); - $objectManager->expects($this->once())->method('configure')->with($this->identicalTo([])); - $objectManager->expects($this->exactly(3)) - ->method('get') - ->willReturnOnConsecutiveCalls( - $configScope, - $configLoader, - $areaList - ); - - \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); - - $bootstrap = $this->getMockBuilder(\Magento\TestFramework\Helper\Bootstrap::class) - ->disableOriginalConstructor() - ->getMock(); - $bootstrap->expects($this->once())->method('loadArea')->with($this->identicalTo(Area::AREA_ADMINHTML)); - \Magento\TestFramework\Helper\Bootstrap::setInstance($bootstrap); - - $this->subject->loadArea(Area::AREA_ADMINHTML); - } - - /** - * Test \Magento\TestFramework\Application will correctly load specified areas. - */ - public function testFrontEndLoadArea() - { - $configScope = $this->getMockBuilder(Scope::class)->disableOriginalConstructor()->getMock(); - $configScope->expects($this->once())->method('setCurrentScope')->with($this->identicalTo(Area::AREA_FRONTEND)); - - $configLoader = $this->getMockBuilder(ConfigLoader::class)->disableOriginalConstructor()->getMock(); - $configLoader->expects($this->once()) - ->method('load') - ->with($this->identicalTo(Area::AREA_FRONTEND)) - ->willReturn([]); - $areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock(); - - /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */ - $objectManager = $this->getMockBuilder(ObjectManagerInterface::class)->disableOriginalConstructor()->getMock(); - $objectManager->expects($this->once())->method('configure')->with($this->identicalTo([])); - $objectManager->expects($this->exactly(3)) - ->method('get') - ->willReturnOnConsecutiveCalls( - $configScope, - $configLoader, - $areaList - ); - - \Magento\TestFramework\Helper\Bootstrap::setObjectManager($objectManager); - $this->subject->loadArea(Area::AREA_FRONTEND); - } - /** * Test \Magento\TestFramework\Application will correctly load specified areas. *