diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php index 77fdccf9bc594..7359b95ded01c 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php @@ -14,6 +14,11 @@ class IndexerCommandCommonTestSetup extends \PHPUnit_Framework_TestCase */ protected $indexerFactory; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\State + */ + protected $stateMock; + /** * @var \PHPUnit_Framework_MockObject_MockObject|CollectionFactory */ @@ -33,16 +38,13 @@ protected function setUp() { $this->objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $this->objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); - //TODO: temporary fix unit - $stateMock = $this->getMock('Magento\Framework\App\State', [], [], '', false); - $stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml')->willReturnSelf(); - - $this->objectManager->expects($this->once()) + $this->stateMock = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $this->objectManager->expects($this->any()) ->method('get') ->with('Magento\Framework\App\State') - ->willReturn($stateMock); - $this->objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager); + ->willReturn($this->stateMock); $this->collectionFactory = $this->getMockBuilder('Magento\Indexer\Model\Indexer\CollectionFactory') ->disableOriginalConstructor() @@ -54,13 +56,11 @@ protected function setUp() ->getMock(); $this->objectManager - ->expects($this->exactly(2)) + ->expects($this->any()) ->method('create') ->will($this->returnValueMap([ ['Magento\Indexer\Model\Indexer\CollectionFactory', [], $this->collectionFactory], ['Magento\Indexer\Model\IndexerFactory', [], $this->indexerFactory], ])); - - $this->objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager); } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php index 2f6da06042dd6..af2ceeb558197 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php @@ -17,6 +17,12 @@ class IndexerInfoCommandTest extends IndexerCommandCommonTestSetup */ private $command; + protected function setUp() + { + parent::setUp(); + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); + } + public function testExecute() { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); @@ -26,7 +32,6 @@ public function testExecute() $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); - $this->indexerFactory->expects($this->never())->method('create'); $this->command = new IndexerInfoCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); $commandTester->execute([]); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php index 80eb1d9c2f84f..7a7e74fd29a5c 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php @@ -19,6 +19,7 @@ class IndexerReindexCommandTest extends IndexerCommandCommonTestSetup public function testGetOptions() { + $this->stateMock->expects($this->never())->method('setAreaCode'); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); $this->assertSame(2, sizeof($optionsList)); @@ -28,6 +29,7 @@ public function testGetOptions() public function testExecuteAll() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); @@ -44,6 +46,7 @@ public function testExecuteAll() public function testExecuteWithIndex() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('reindexAll'); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); @@ -66,6 +69,7 @@ public function testExecuteWithIndex() public function testExecuteWithLocalizedException() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $localizedException = new \Magento\Framework\Exception\LocalizedException(__('Some Exception Message')); $indexerOne->expects($this->once())->method('reindexAll')->will($this->throwException($localizedException)); @@ -80,6 +84,7 @@ public function testExecuteWithLocalizedException() public function testExecuteWithException() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); $indexerOne->expects($this->once())->method('reindexAll')->will($this->throwException($exception)); @@ -95,6 +100,7 @@ public function testExecuteWithException() public function testExecuteWithExceptionInLoad() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); $indexerOne->expects($this->once())->method('load')->will($this->throwException($exception)); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php index dcd345dc6ffe5..080effaa29227 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php @@ -22,6 +22,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup public function testGetOptions() { + $this->stateMock->expects($this->never())->method('setAreaCode')->with('adminmhtml'); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); $this->assertSame(3, sizeof($optionsList)); @@ -36,6 +37,7 @@ public function testGetOptions() */ public function testExecuteInvalidArgument() { + $this->stateMock->expects($this->never())->method('setAreaCode')->with('adminmhtml'); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); $commandTester->execute([]); @@ -47,6 +49,7 @@ public function testExecuteInvalidArgument() */ public function testExecuteInvalidMode() { + $this->stateMock->expects($this->never())->method('setAreaCode')->with('adminmhtml'); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); $commandTester->execute(['mode' => 'wrong_mode']); @@ -54,6 +57,7 @@ public function testExecuteInvalidMode() public function testExecuteAll() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); @@ -87,6 +91,7 @@ public function testExecuteAll() */ public function testExecuteWithIndex($isScheduled, $previous, $current, $mode, $expectedValue) { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); $indexerOne->expects($this->once())->method('load')->with('id_indexerOne')->willReturn($indexerOne); @@ -147,6 +152,7 @@ public function executeWithIndexDataProvider() public function testExecuteWithLocalizedException() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $localizedException = new \Magento\Framework\Exception\LocalizedException(__('Some Exception Message')); $indexerOne->expects($this->once())->method('setScheduled')->will($this->throwException($localizedException)); @@ -161,6 +167,7 @@ public function testExecuteWithLocalizedException() public function testExecuteWithException() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); $indexerOne->expects($this->once())->method('setScheduled')->will($this->throwException($exception)); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php index 8c7a527ae4392..59e09e048f9ba 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php @@ -19,6 +19,7 @@ class IndexerShowModeCommandTest extends IndexerCommandCommonTestSetup public function testGetOptions() { + $this->stateMock->expects($this->never())->method('setAreaCode')->with('adminmhtml'); $this->command = new IndexerShowModeCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); $this->assertSame(2, sizeof($optionsList)); @@ -28,7 +29,6 @@ public function testGetOptions() public function testExecuteAll() { - $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index b5fd291e330c0..69a456f9858ee 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -19,6 +19,7 @@ class IndexerStatusCommandTest extends IndexerCommandCommonTestSetup public function testExecuteAll() { + $this->stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml'); $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); diff --git a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php index c6c40ab0b301f..c265919451b35 100644 --- a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php +++ b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Log\Test\Unit\Console\Command; +use Magento\Backend\App\Area\FrontNameResolver; use Magento\Log\Console\Command\LogCleanCommand; use Symfony\Component\Console\Tester\CommandTester; use Magento\Framework\App\ObjectManager; @@ -23,10 +24,17 @@ class LogCleanCommandTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->objectManager = $this->getMock('Magento\Framework\App\ObjectManager', [], [], '', false); - $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); - $objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager); - $this->commandTester = new CommandTester(new LogCleanCommand($objectManagerFactory)); + $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false); + $state = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $configLoader->expects($this->once()) + ->method('load') + ->with(FrontNameResolver::AREA_CODE) + ->will($this->returnValue([])); + $state->expects($this->once()) + ->method('setAreaCode') + ->with(FrontNameResolver::AREA_CODE); + $this->commandTester = new CommandTester(new LogCleanCommand($this->objectManager, $configLoader, $state)); } public function testExecute() diff --git a/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php b/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php index a7928b80c4fee..9d306be7acd4f 100644 --- a/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php +++ b/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Log\Test\Unit\Console\Command; +use Magento\Backend\App\Area\FrontNameResolver; use Magento\Log\Console\Command\LogStatusCommand; use Symfony\Component\Console\Tester\CommandTester; @@ -12,20 +13,28 @@ class LogStatusCommandTest extends \PHPUnit_Framework_TestCase { public function testExecute() { - $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); - $objectManager = $this->getMock('Magento\Framework\App\ObjectManager', [], [], '', false); $resourceFactory = $this->getMockBuilder('Magento\Log\Model\Resource\ShellFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $objectManager->expects($this->once())->method('create')->willReturn($resourceFactory); $resource = $this->getMock('Magento\Log\Model\Resource\Shell', [], [], '', false); $resourceFactory->expects($this->once())->method('create')->willReturn($resource); $resource->expects($this->once())->method('getTablesInfo')->willReturn( [['name' => 'log_customer', 'rows' => '1', 'data_length' => '16384', 'index_length' => '1024']] ); - $objectManagerFactory->expects($this->once())->method('create')->willReturn($objectManager); - $commandTester = new CommandTester(new LogStatusCommand($objectManagerFactory)); + $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManager->expects($this->once())->method('create')->willReturn($resourceFactory); + $configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false); + $state = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $configLoader->expects($this->once()) + ->method('load') + ->with(FrontNameResolver::AREA_CODE) + ->will($this->returnValue([])); + $state->expects($this->once()) + ->method('setAreaCode') + ->with(FrontNameResolver::AREA_CODE); + $commandTester = new CommandTester(new LogStatusCommand($objectManager, $configLoader, $state)); + $commandTester->execute([]); $expectedMsg = '-----------------------------------+------------+------------+------------+' . PHP_EOL . 'Table Name | Rows | Data Size | Index Size |' . PHP_EOL