From 6b749c0b2d8cc6952cae0f2037ae41b1a91ac048 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 12 Dec 2017 16:00:31 +0200 Subject: [PATCH] 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, - ], - ]; - } }