From 76e9ff0f4435bf2b365c08c1f0af393e8ad9f38f Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Mon, 8 Jun 2015 16:44:13 -0500 Subject: [PATCH 01/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added unit tests for the Fixture classes. --- .../Fixtures/CartPriceRulesFixtureTest.php | 102 ++++++++++ .../Fixtures/CatalogPriceRulesFixtureTest.php | 116 +++++++++++ .../Unit/Fixtures/CategoriesFixtureTest.php | 117 +++++++++++ .../Unit/Fixtures/ConfigsApplyFixtureTest.php | 58 ++++++ .../ConfigurableProductsFixtureTest.php | 98 +++++++++ .../Unit/Fixtures/CustomersFixtureTest.php | 75 +++++++ .../Fixtures/EavVariationsFixtureTest.php | 82 ++++++++ .../IndexersStatesApplyFixtureTest.php | 58 ++++++ .../Test/Unit/Fixtures/OrdersFixtureTest.php | 186 ++++++++++++++++++ .../Fixtures/SimpleProductsFixtureTest.php | 100 ++++++++++ .../Test/Unit/Fixtures/StoresFixtureTest.php | 145 ++++++++++++++ .../Unit/Fixtures/TaxRatesFixtureTest.php | 72 +++++++ 12 files changed, 1209 insertions(+) create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php new file mode 100644 index 0000000000000..c214047cec7a6 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -0,0 +1,102 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock->expects($this->once()) + ->method('getRootCategoryId') + ->will($this->returnValue(2)); + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock->expects($this->once()) + ->method('getGroups') + ->will($this->returnValue([$storeMock])); + $websiteMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue('website_id')); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->will($this->returnValue([$websiteMock])); + + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $abstractDbMock->expects($this->any()) + ->method('getAllChildren') + ->will($this->returnValue([1])); + + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock->expects($this->any()) + ->method('getResource') + ->will($this->returnValue($abstractDbMock)); + $categoryMock->expects($this->once()) + ->method('getPath') + ->will($this->returnValue('path/to/file')); + $categoryMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue('category_id')); + + $modelMock = $this->getMockBuilder('\Magento\SalesRule\Model\Rule')->disableOriginalConstructor()->getMock(); + $modelMock->expects($this->once()) + ->method('getIdFieldName') + ->will($this->returnValue('Field Id Name')); + + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($storeManagerMock)); + $objectManagerMock->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls($categoryMock, $modelMock)); + + $this->fixtureModelMock + ->expects($this->exactly(2)) + ->method('getValue') + ->will($this->onConsecutiveCalls(1, 3)); + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + + $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); + $cartPriceFixture->execute(); + } + + public function testGetActionTitle() + { + $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); + $this->assertSame('Generating shopping cart price rules', $cartPriceFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); + $this->assertSame([ + 'cart_price_rules' => 'Cart Price Rules' + ], $cartPriceFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php new file mode 100644 index 0000000000000..d506155b2336e --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -0,0 +1,116 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); + $storeMock + ->expects($this->once()) + ->method('getRootCategoryId') + ->will($this->returnValue(2)); + + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); + $websiteMock + ->expects($this->once()) + ->method('getGroups') + ->will($this->returnValue([$storeMock])); + $websiteMock + ->expects($this->once()) + ->method('getId') + ->will($this->returnValue('website_id')); + + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock + ->expects($this->once()) + ->method('getWebsites') + ->will($this->returnValue([$websiteMock])); + + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass('Magento\Framework\Model\Resource\Db\AbstractDb', [$contextMock], '', true, true, true, ['getAllChildren']); + $abstractDbMock + ->expects($this->any()) + ->method('getAllChildren') + ->will($this->returnValue([1])); + + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); + $categoryMock + ->expects($this->any()) + ->method('getResource') + ->will($this->returnValue($abstractDbMock)); + $categoryMock + ->expects($this->once()) + ->method('getPath') + ->will($this->returnValue('path/to/file')); + $categoryMock + ->expects($this->once()) + ->method('getId') + ->will($this->returnValue('category_id')); + + $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); + $modelMock + ->expects($this->once()) + ->method('getIdFieldName') + ->will($this->returnValue('Field Id Name')); + + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock + ->expects($this->once()) + ->method('create') + ->will($this->returnValue($storeManagerMock)); + $objectManagerMock + ->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls($categoryMock, $modelMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('resetObjectManager'); + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(1)); + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + + $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); + $catalogPriceFixture->execute(); + } + + public function testGetActionTitle() + { + $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); + $this->assertSame('Generating catalog price rules', $catalogPriceFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); + $this->assertSame([ + 'catalog_price_rules' => 'Catalog Price Rules' + ], $catalogPriceFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php new file mode 100644 index 0000000000000..ec704b2cfc522 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -0,0 +1,117 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + public function testExecute() + { + $categoryMock = $this->getMockBuilder('\Magento\Catalog\Model\Category')->disableOriginalConstructor()->setMethods(array( + 'getName', + 'setId', + 'setUrlKey', + 'setUrlPath', + 'setName', + 'setParentId', + 'setPath', + 'setLevel', + 'setAvailableSortBy', + 'setDefaultSortBy', + 'setIsActive', + 'save' + ))->getMock(); + $categoryMock + ->expects($this->once()) + ->method('getName') + ->will($this->returnValue('category_name')); + $categoryMock->expects($this->once()) + ->method('setId') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setUrlKey') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setUrlPath') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setName') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setParentId') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setPath') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setLevel') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setAvailableSortBy') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setDefaultSortBy') + ->willReturnSelf(); + $categoryMock->expects($this->once()) + ->method('setIsActive') + ->willReturnSelf(); + + $groupMock = $this->getMock('\Magento\Store\Model\Group', [], [], '', false); + $groupMock + ->expects($this->once()) + ->method('getRootCategoryId') + ->will($this->returnValue('root_category_id')); + + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock + ->expects($this->once()) + ->method('getGroups') + ->will($this->returnValue([$groupMock])); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock + ->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManagerMock, $categoryMock)); + + $this->fixtureModelMock + ->expects($this->exactly(2)) + ->method('getValue') + ->will($this->onConsecutiveCalls(1, 3)); + $this->fixtureModelMock + ->expects($this->exactly(2)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); + $categoriesFixture->execute(); + } + + public function testGetActionTitle() + { + $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); + $this->assertSame('Generating categories', $categoriesFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); + $this->assertSame([ + 'categories' => 'Categories' + ], $categoriesFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php new file mode 100644 index 0000000000000..ae4a8c3ee6be0 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -0,0 +1,58 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + public function testExecute() + { + $cacheMock = $this->getMockBuilder('\Magento\Framework\App\Cache')->disableOriginalConstructor()->getMock(); + + $valueMock = $this->getMockBuilder('\Magento\Framework\App\Config')->disableOriginalConstructor()->getMock(); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->once()) + ->method('get') + ->will($this->returnValue($cacheMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(['config' => $valueMock])); + $this->fixtureModelMock + ->expects($this->once()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); + $configsApplyFixture->execute(); + } + + public function testGetActionTitle() + { + $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); + $this->assertSame('Config Changes', $configsApplyFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); + $this->assertSame([], $configsApplyFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php new file mode 100644 index 0000000000000..6c9cfe67f26c3 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -0,0 +1,98 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); + + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $abstractDbMock->expects($this->any()) + ->method('getAllChildren') + ->will($this->returnValue([1])); + + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock->expects($this->once()) + ->method('getResource') + ->will($this->returnValue($abstractDbMock)); + $categoryMock->expects($this->any()) + ->method('getName') + ->will($this->returnValue('category_name')); + $categoryMock->expects($this->once()) + ->method('getPath') + ->will($this->returnValue('path/to/category')); + $categoryMock->expects($this->any())->method('load') + ->willReturnSelf(); + + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock->expects($this->once()) + ->method('getRootCategoryId') + ->will($this->returnValue([2])); + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock->expects($this->once()) + ->method('getCode') + ->will($this->returnValue('website_code')); + $websiteMock->expects($this->once()) + ->method('getGroups') + ->will($this->returnValue([$storeMock])); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->will($this->returnValue([$websiteMock])); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + $objectManagerMock->expects($this->once()) + ->method('get') + ->will($this->returnValue($categoryMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(1)); + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); + $configurableProductsFixture->execute(); + } + + public function testGetActionTitle() + { + $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); + $this->assertSame('Generating configurable products', $configurableProductsFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); + $this->assertSame([ + 'configurable_products' => 'Configurable products' + ], $configurableProductsFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php new file mode 100644 index 0000000000000..b81a143bc38d7 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -0,0 +1,75 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); + + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock->expects($this->once()) + ->method('getCode') + ->will($this->returnValue('store_code')); + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock->expects($this->once()) + ->method('getCode') + ->will($this->returnValue('website_code')); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getDefaultStoreView') + ->will($this->returnValue($storeMock)); + $storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->will($this->returnValue([$websiteMock])); + + $objectManagerMode = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMode->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(1)); + $this->fixtureModelMock + ->expects($this->exactly(2)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMode)); + + $customersFixture = new CustomersFixture($this->fixtureModelMock); + $customersFixture->execute(); + } + + public function testGetActionTitle() + { + $customersFixture = new CustomersFixture($this->fixtureModelMock); + $this->assertSame('Generating customers', $customersFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $customersFixture = new CustomersFixture($this->fixtureModelMock); + $this->assertSame([ + 'customers' => 'Customers' + ], $customersFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php new file mode 100644 index 0000000000000..c064ab6a36d4d --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -0,0 +1,82 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $attributeMock = $this->getMockBuilder('Magenot\Catalog\Model\Resource\Eav\Attribute') + ->setMethods(array('setAttributeGroupId', 'addData', 'setAttributeSetId', 'save')) + ->getMock(); + $attributeMock->expects($this->exactly(2)) + ->method('setAttributeSetId') + ->willReturnSelf(); + $attributeMock->expects($this->once()) + ->method('setAttributeGroupId') + ->willReturnSelf(); + + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getStores') + ->will($this->returnValue([$storeMock])); + + $setMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Set')->disableOriginalConstructor()->getMock(); + $setMock->expects($this->once()) + ->method('getDefaultGroupId') + ->will($this->returnValue(2)); + + $cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')->disableOriginalConstructor()->getMock(); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($attributeMock, $storeManagerMock)); + $objectManagerMock->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls($setMock, $cacheMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(1)); + $this->fixtureModelMock + ->expects($this->exactly(4)) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); + + $eavVariationsFixture = new EavVariationsFixture($this->fixtureModelMock); + $eavVariationsFixture->execute(); + } + + public function testGetActionTitle() + { + $eavVariationsFixture = new EavVariationsFixture($this->fixtureModelMock); + $this->assertSame('Generating configurable EAV variations', $eavVariationsFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $eavVariationsFixture = new EavVariationsFixture($this->fixtureModelMock); + $this->assertSame([], $eavVariationsFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php new file mode 100644 index 0000000000000..651531d4dd395 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -0,0 +1,58 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $cacheInterfaceMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')->disableOriginalConstructor()->getMock(); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->once()) + ->method('get') + ->willReturn($cacheInterfaceMock); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(array( + 'indexer' => ['id' => 1] + )); + $this->fixtureModelMock + ->expects($this->once()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); + + $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); + $indexersStatesApplyFixture->execute(); + } + + public function testGetActionTitle() + { + $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); + $this->assertSame('Indexers Mode Changes', $indexersStatesApplyFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); + $this->assertSame([], $indexersStatesApplyFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php new file mode 100644 index 0000000000000..e3a719ce17c44 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -0,0 +1,186 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $adapterInterfaceMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass(); + $adapterInterfaceMock->expects($this->any()) + ->method('getTableName') + ->willReturn('table_name'); + + $resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource')->disableOriginalConstructor()->getMock(); + $resourceMock->expects($this->any()) + ->method('getConnection') + ->willReturn($adapterInterfaceMock); + + + foreach ($this->mockObjectNames as $mockObjectName) { + $mockObject = $this->getMockBuilder($mockObjectName)->disableOriginalConstructor()->getMock(); + $path = explode('\\', $mockObjectName); + $name = array_pop($path); + if (strcasecmp($mockObjectName, 'Magento\Sales\Model\Resource\Order') == 0) { + $mockObject->expects($this->exactly(2)) + ->method('getTable') + ->willReturn(strtolower($name) . '_table_name'); + } else { + $mockObject->expects($this->once()) + ->method('getTable') + ->willReturn(strtolower($name) . '_table_name'); + } + $map = array($mockObjectName, $mockObject); + $this->mockObjects[] = $map; + } + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->setMethods(array('getId', 'getName'))->getMock(); + $websiteMock->expects($this->once()) + ->method('getId') + ->willReturn('website_id'); + $websiteMock->expects($this->once()) + ->method('getName') + ->willReturn('website_name'); + + $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group')->disableOriginalConstructor()->setMethods(array('getName'))->getMock(); + $groupMock->expects($this->once()) + ->method('getName') + ->willReturn('group_name'); + + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->setMethods(array( + 'getStoreId', + 'getWebsite', + 'getGroup', + 'getName', + 'getRootCategoryId' + ))->getMock(); + $storeMock->expects($this->once()) + ->method('getStoreId') + ->willReturn(1); + $storeMock->expects($this->exactly(2)) + ->method('getWebsite') + ->willReturn($websiteMock); + $storeMock->expects($this->once()) + ->method('getGroup') + ->willReturn($groupMock); + $storeMock->expects($this->once()) + ->method('getName') + ->willReturn('store_name'); + $storeMock->expects($this->once()) + ->method('getRootCategoryId') + ->willReturn(1); + + $storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManager->expects($this->once()) + ->method('getStores') + ->willReturn([$storeMock]); + + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $abstractDbMock->expects($this->any()) + ->method('getAllChildren') + ->will($this->returnValue([1])); + + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock->expects($this->once()) + ->method('getResource') + ->willReturn($abstractDbMock); + $categoryMock->expects($this->once()) + ->method('getPath') + ->willReturn('path/to/category'); + $categoryMock->expects($this->any()) + ->method('getName') + ->willReturn('category_name'); + $categoryMock->expects($this->any()) + ->method('load') + ->willReturnSelf(); + $this->mockObjects[] = array('Magento\Catalog\Model\Category', $categoryMock); + + $productMock = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor()->getMock(); + $productMock->expects($this->any()) + ->method('load') + ->willReturnSelf(); + $this->mockObjects[] = array('Magento\Catalog\Model\Product', $productMock); + $this->mockObjects[] = array('Magento\Framework\App\Resource', $resourceMock); + + $selectMock = $this->getMockBuilder('\Magento\Framework\DB\Select')->disableOriginalConstructor()->getMock(); + + $collectionMock = $this->getMockBuilder('\Magento\Catalog\Model\Resource\Product\Collection')->disableOriginalConstructor()->getMock(); + $collectionMock->expects($this->once()) + ->method('getSelect') + ->willReturn($selectMock); + $collectionMock->expects($this->once()) + ->method('getAllIds') + ->willReturn([1, 1]); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock + ->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($this->mockObjects)); + $objectManagerMock + ->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManager, $collectionMock)); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(1); + $this->fixtureModelMock + ->expects($this->any()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); + + $ordersFixture = new OrdersFixture($this->fixtureModelMock); + $ordersFixture->execute(); + } + + public function testGetActionTitle() + { + $ordersFixture = new OrdersFixture($this->fixtureModelMock); + $this->assertSame('Generating orders', $ordersFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $ordersFixture = new OrdersFixture($this->fixtureModelMock); + $this->assertSame([ + 'orders' => 'Orders' + ], $ordersFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php new file mode 100644 index 0000000000000..d6a23f30c9dd9 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -0,0 +1,100 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock->expects($this->once()) + ->method('getRootCategoryId') + ->willReturn(1); + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock->expects($this->once()) + ->method('getCode') + ->willReturn('website_code'); + $websiteMock->expects($this->once()) + ->method('getGroups') + ->willReturn([$storeMock]); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->willReturn([$websiteMock]); + + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); + + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $abstractDbMock->expects($this->any()) + ->method('getAllChildren') + ->will($this->returnValue([1])); + + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock->expects($this->once()) + ->method('getResource') + ->willReturn($abstractDbMock); + $categoryMock->expects($this->once()) + ->method('getPath') + ->willReturn('path/to/category'); + $categoryMock->expects($this->any()) + ->method('load') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('getName') + ->willReturn('category_name'); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + $objectManagerMock->expects($this->once()) + ->method('get') + ->willReturn($categoryMock); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(1); + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getObjectManager') + ->willReturn($objectManagerMock); + + $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); + $simpleProductsFixture->execute(); + } + + public function testGetActionTitle() + { + $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); + $this->assertSame('Generating simple products', $simpleProductsFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); + $this->assertSame([ + 'simple_products' => 'Simple products' + ], $simpleProductsFixture->introduceParamLabels()); + } + +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php new file mode 100644 index 0000000000000..ab9760b103d23 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -0,0 +1,145 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock->expects($this->any()) + ->method('getId') + ->willReturn('website_id'); + $websiteMock->expects($this->once()) + ->method('save'); + + $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group')->disableOriginalConstructor()->getMock(); + $groupMock->expects($this->any()) + ->method('getId') + ->willReturn('group_id'); + $groupMock->expects($this->once()) + ->method('save'); + + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock->expects($this->once()) + ->method('getRootCategoryId') + ->willReturn(1); + $storeMock->expects($this->once()) + ->method('getId') + ->willReturn('store_id'); + $storeMock->expects($this->once()) + ->method('save'); + + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock->expects($this->once()) + ->method('getWebsite') + ->willReturn($websiteMock); + $storeManagerMock->expects($this->once()) + ->method('getGroup') + ->willReturn($groupMock); + $storeManagerMock->expects($this->once()) + ->method('getDefaultStoreView') + ->willReturn($storeMock); + $storeManagerMock->expects($this->once()) + ->method('getStore') + ->willReturn($storeMock); + + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->setMethods(array( + 'setId', + 'setUrlKey', + 'setUrlPath', + 'setName', + 'setParentId', + 'setPath', + 'setLevel', + 'setAvailableSortBy', + 'setDefaultSortBy', + 'setIsActive', + 'getId', + 'save' + ))->getMock(); + $categoryMock->expects($this->once()) + ->method('setId') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setUrlKey') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setUrlPath') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setName') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setParentId') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setPath') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setLevel') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setAvailableSortBy') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setDefaultSortBy') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('setIsActive') + ->willReturnSelf(); + $categoryMock->expects($this->any()) + ->method('getId') + ->willReturn('category_id'); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($storeManagerMock, $categoryMock)); + + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getValue') + ->will($this->onConsecutiveCalls(1, 1, 1)); + $this->fixtureModelMock + ->expects($this->exactly(2)) + ->method('getObjectManager') + ->willReturn($objectManagerMock); + + $storesFixture = new StoresFixture($this->fixtureModelMock); + $storesFixture->execute(); + } + + public function testGetActionTitle() + { + $storesFixture = new StoresFixture($this->fixtureModelMock); + $this->assertSame('Generating websites, stores and store views', $storesFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $storesFixture = new StoresFixture($this->fixtureModelMock); + $this->assertSame([ + 'websites' => 'Websites', + 'store_groups' => 'Store Groups', + 'store_views' => 'Store Views' + ], $storesFixture->introduceParamLabels()); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php new file mode 100644 index 0000000000000..9e416eb4b06bf --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -0,0 +1,72 @@ +fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + } + + public function testExecute() + { + $rateMock = $this->getMockBuilder('Magento\Tax\Model\Calculation\Rate')->disableOriginalConstructor()->setMethods(array( + 'setId', + 'delete' + ))->getMock(); + + $collectionMock = $this->getMockBuilder('Magento\Tax\Model\Resource\Calculation\Rate\Collection')->disableOriginalConstructor()->getMock(); + $collectionMock->expects($this->once()) + ->method('getAllIds') + ->willReturn([1]); + + $csvImportHandlerMock = $this->getMockBuilder('Magento\TaxImportExport\Model\Rate\CsvImportHandler')->disableOriginalConstructor()->getMock(); + + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock->expects($this->exactly(2)) + ->method('get') + ->will($this->onConsecutiveCalls($collectionMock, $rateMock)); + $objectManagerMock->expects($this->once()) + ->method('create') + ->willReturn($csvImportHandlerMock); + + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn('taxRates.file'); + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getObjectManager') + ->willReturn($objectManagerMock); + + $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); + $taxRatesFixture->execute(); + } + + public function testGetActionTitle() + { + $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); + $this->assertSame('Generating tax rates', $taxRatesFixture->getActionTitle()); + } + + public function testIntroduceParamLabels() + { + $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); + $this->assertSame([], $taxRatesFixture->introduceParamLabels()); + } + +} From ca8f8470c77bda2a374883b8dc3c7e68cadc38f9 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 9 Jun 2015 12:00:54 -0500 Subject: [PATCH 02/22] MAGETWO-38383: Increase Unit Test Code Coverage - Edited code style in accordance with acceptance tests --- .../Fixtures/CartPriceRulesFixtureTest.php | 25 +++-- .../Fixtures/CatalogPriceRulesFixtureTest.php | 17 ++-- .../Unit/Fixtures/CategoriesFixtureTest.php | 33 ++++--- .../Unit/Fixtures/ConfigsApplyFixtureTest.php | 8 +- .../ConfigurableProductsFixtureTest.php | 29 ++++-- .../Unit/Fixtures/CustomersFixtureTest.php | 19 +++- .../Fixtures/EavVariationsFixtureTest.php | 22 +++-- .../IndexersStatesApplyFixtureTest.php | 16 +++- .../Test/Unit/Fixtures/OrdersFixtureTest.php | 92 ++++++++++++------- .../Fixtures/SimpleProductsFixtureTest.php | 36 +++++--- .../Test/Unit/Fixtures/StoresFixtureTest.php | 47 ++++++---- .../Unit/Fixtures/TaxRatesFixtureTest.php | 31 +++++-- 12 files changed, 253 insertions(+), 122 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index c214047cec7a6..46240a01f2382 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -18,7 +18,9 @@ class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() @@ -36,18 +38,27 @@ public function testExecute() ->method('getId') ->will($this->returnValue('website_id')); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') + ->disableOriginalConstructor() + ->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') + ->setConstructorArgs([$contextMock]) + ->setMethods(['getAllChildren']) + ->getMockForAbstractClass(); $abstractDbMock->expects($this->any()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') + ->disableOriginalConstructor() + ->getMock(); $categoryMock->expects($this->any()) ->method('getResource') ->will($this->returnValue($abstractDbMock)); @@ -64,7 +75,9 @@ public function testExecute() ->will($this->returnValue('Field Id Name')); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->once()) ->method('create') ->will($this->returnValue($storeManagerMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index d506155b2336e..6776ae71e27e1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -8,7 +8,6 @@ use \Magento\Setup\Fixtures\CatalogPriceRulesFixture; - class CatalogPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase { /** @@ -18,7 +17,9 @@ class CatalogPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() @@ -45,10 +46,14 @@ public function testExecute() ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); - $abstractDbMock = $this->getMockForAbstractClass('Magento\Framework\Model\Resource\Db\AbstractDb', [$contextMock], '', true, true, true, ['getAllChildren']); - $abstractDbMock - ->expects($this->any()) + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') + ->disableOriginalConstructor() + ->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') + ->setConstructorArgs([$contextMock]) + ->setMethods(['getAllChildren']) + ->getMockForAbstractClass(); + $abstractDbMock->expects($this->any()) ->method('getAllChildren') ->will($this->returnValue([1])); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index ec704b2cfc522..44e362aed4608 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -17,24 +17,27 @@ class CategoriesFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { - $categoryMock = $this->getMockBuilder('\Magento\Catalog\Model\Category')->disableOriginalConstructor()->setMethods(array( - 'getName', - 'setId', - 'setUrlKey', - 'setUrlPath', - 'setName', - 'setParentId', - 'setPath', - 'setLevel', - 'setAvailableSortBy', - 'setDefaultSortBy', - 'setIsActive', - 'save' - ))->getMock(); + $categoryMock = $this->getMockBuilder('\Magento\Catalog\Model\Category')->disableOriginalConstructor() + ->setMethods([ + 'getName', + 'setId', + 'setUrlKey', + 'setUrlPath', + 'setName', + 'setParentId', + 'setPath', + 'setLevel', + 'setAvailableSortBy', + 'setDefaultSortBy', + 'setIsActive', + 'save' + ])->getMock(); $categoryMock ->expects($this->once()) ->method('getName') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php index ae4a8c3ee6be0..68f004e0dc14d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -18,7 +18,9 @@ class ConfigsApplyFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { @@ -26,7 +28,9 @@ public function testExecute() $valueMock = $this->getMockBuilder('\Magento\Framework\App\Config')->disableOriginalConstructor()->getMock(); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->once()) ->method('get') ->will($this->returnValue($cacheMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 6c9cfe67f26c3..023ad1532bc2d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -17,20 +17,31 @@ class ConfigurableProductsFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') + ->disableOriginalConstructor() + ->getMock(); - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') + ->disableOriginalConstructor() + ->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') + ->setConstructorArgs([$contextMock]) + ->setMethods(['getAllChildren']) + ->getMockForAbstractClass(); $abstractDbMock->expects($this->any()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') + ->disableOriginalConstructor() + ->getMock(); $categoryMock->expects($this->once()) ->method('getResource') ->will($this->returnValue($abstractDbMock)); @@ -56,12 +67,16 @@ public function testExecute() ->method('getGroups') ->will($this->returnValue([$storeMock])); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->exactly(2)) ->method('create') ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index b81a143bc38d7..4f4f6c49f0e30 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -8,7 +8,8 @@ use \Magento\Setup\Fixtures\CustomersFixture; -class CustomersFixtureTest extends \PHPUnit_Framework_TestCase { +class CustomersFixtureTest extends \PHPUnit_Framework_TestCase +{ /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel */ @@ -16,12 +17,16 @@ class CustomersFixtureTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') + ->disableOriginalConstructor() + ->getMock(); $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once()) @@ -33,7 +38,9 @@ public function testExecute() ->method('getCode') ->will($this->returnValue('website_code')); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getDefaultStoreView') ->will($this->returnValue($storeMock)); @@ -41,7 +48,9 @@ public function testExecute() ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $objectManagerMode = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMode = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMode->expects($this->exactly(2)) ->method('create') ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index c064ab6a36d4d..f31b84b6ac00e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -18,13 +18,15 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { $attributeMock = $this->getMockBuilder('Magenot\Catalog\Model\Resource\Eav\Attribute') - ->setMethods(array('setAttributeGroupId', 'addData', 'setAttributeSetId', 'save')) + ->setMethods(['setAttributeGroupId', 'addData', 'setAttributeSetId', 'save']) ->getMock(); $attributeMock->expects($this->exactly(2)) ->method('setAttributeSetId') @@ -35,19 +37,27 @@ public function testExecute() $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getStores') ->will($this->returnValue([$storeMock])); - $setMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Set')->disableOriginalConstructor()->getMock(); + $setMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Set') + ->disableOriginalConstructor() + ->getMock(); $setMock->expects($this->once()) ->method('getDefaultGroupId') ->will($this->returnValue(2)); - $cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')->disableOriginalConstructor()->getMock(); + $cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface') + ->disableOriginalConstructor() + ->getMock(); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->exactly(2)) ->method('create') ->will($this->onConsecutiveCalls($attributeMock, $storeManagerMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php index 651531d4dd395..0fc1bfd419a1d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -17,14 +17,20 @@ class IndexersStatesApplyFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { - $cacheInterfaceMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')->disableOriginalConstructor()->getMock(); + $cacheInterfaceMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface') + ->disableOriginalConstructor() + ->getMock(); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->once()) ->method('get') ->willReturn($cacheInterfaceMock); @@ -32,9 +38,9 @@ public function testExecute() $this->fixtureModelMock ->expects($this->once()) ->method('getValue') - ->willReturn(array( + ->willReturn([ 'indexer' => ['id' => 1] - )); + ]); $this->fixtureModelMock ->expects($this->once()) ->method('getObjectManager') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index e3a719ce17c44..0b53a11dfea98 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -10,7 +10,7 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase { - private $mockObjectNames = array( + private $mockObjectNames = [ 'Magento\Quote\Model\Resource\Quote', 'Magento\Quote\Model\Resource\Quote\Address', 'Magento\Quote\Model\Resource\Quote\Item', @@ -24,7 +24,7 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase 'Magento\Sales\Model\Resource\Order\Payment', 'Magento\Sales\Model\Resource\Order\Status\History', '\Magento\Eav\Model\Resource\Entity\Store' - ); + ]; private $mockObjects; @@ -35,22 +35,6 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); - } - - public function testExecute() - { - $adapterInterfaceMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass(); - $adapterInterfaceMock->expects($this->any()) - ->method('getTableName') - ->willReturn('table_name'); - - $resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource')->disableOriginalConstructor()->getMock(); - $resourceMock->expects($this->any()) - ->method('getConnection') - ->willReturn($adapterInterfaceMock); - - foreach ($this->mockObjectNames as $mockObjectName) { $mockObject = $this->getMockBuilder($mockObjectName)->disableOriginalConstructor()->getMock(); $path = explode('\\', $mockObjectName); @@ -64,11 +48,39 @@ public function testExecute() ->method('getTable') ->willReturn(strtolower($name) . '_table_name'); } - $map = array($mockObjectName, $mockObject); + $map = [$mockObjectName, $mockObject]; $this->mockObjects[] = $map; } - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->setMethods(array('getId', 'getName'))->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testExecute() + { + $adapterInterfaceMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $adapterInterfaceMock->expects($this->any()) + ->method('getTableName') + ->willReturn('table_name'); + + $resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource') + ->disableOriginalConstructor() + ->getMock(); + $resourceMock->expects($this->any()) + ->method('getConnection') + ->willReturn($adapterInterfaceMock); + + $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website') + ->disableOriginalConstructor() + ->setMethods(['getId', 'getName']) + ->getMock(); $websiteMock->expects($this->once()) ->method('getId') ->willReturn('website_id'); @@ -76,18 +88,21 @@ public function testExecute() ->method('getName') ->willReturn('website_name'); - $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group')->disableOriginalConstructor()->setMethods(array('getName'))->getMock(); + $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group') + ->disableOriginalConstructor() + ->setMethods(['getName']) + ->getMock(); $groupMock->expects($this->once()) ->method('getName') ->willReturn('group_name'); - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->setMethods(array( + $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->setMethods([ 'getStoreId', 'getWebsite', 'getGroup', 'getName', 'getRootCategoryId' - ))->getMock(); + ])->getMock(); $storeMock->expects($this->once()) ->method('getStoreId') ->willReturn(1); @@ -104,18 +119,27 @@ public function testExecute() ->method('getRootCategoryId') ->willReturn(1); - $storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManager->expects($this->once()) ->method('getStores') ->willReturn([$storeMock]); - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') + ->disableOriginalConstructor() + ->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') + ->setConstructorArgs([$contextMock]) + ->setMethods(['getAllChildren']) + ->getMockForAbstractClass(); $abstractDbMock->expects($this->any()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') + ->disableOriginalConstructor() + ->getMock(); $categoryMock->expects($this->once()) ->method('getResource') ->willReturn($abstractDbMock); @@ -128,18 +152,20 @@ public function testExecute() $categoryMock->expects($this->any()) ->method('load') ->willReturnSelf(); - $this->mockObjects[] = array('Magento\Catalog\Model\Category', $categoryMock); + $this->mockObjects[] = ['Magento\Catalog\Model\Category', $categoryMock]; $productMock = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor()->getMock(); $productMock->expects($this->any()) ->method('load') ->willReturnSelf(); - $this->mockObjects[] = array('Magento\Catalog\Model\Product', $productMock); - $this->mockObjects[] = array('Magento\Framework\App\Resource', $resourceMock); + $this->mockObjects[] = ['Magento\Catalog\Model\Product', $productMock]; + $this->mockObjects[] = ['Magento\Framework\App\Resource', $resourceMock]; $selectMock = $this->getMockBuilder('\Magento\Framework\DB\Select')->disableOriginalConstructor()->getMock(); - $collectionMock = $this->getMockBuilder('\Magento\Catalog\Model\Resource\Product\Collection')->disableOriginalConstructor()->getMock(); + $collectionMock = $this->getMockBuilder('\Magento\Catalog\Model\Resource\Product\Collection') + ->disableOriginalConstructor() + ->getMock(); $collectionMock->expects($this->once()) ->method('getSelect') ->willReturn($selectMock); @@ -147,7 +173,9 @@ public function testExecute() ->method('getAllIds') ->willReturn([1, 1]); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock ->expects($this->any()) ->method('get') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index d6a23f30c9dd9..dd5f0d01203d9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -8,8 +8,8 @@ use \Magento\Setup\Fixtures\SimpleProductsFixture; -class SimpleProductsFixtureTest extends \PHPUnit_Framework_TestCase { - +class SimpleProductsFixtureTest extends \PHPUnit_Framework_TestCase +{ /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel */ @@ -17,7 +17,9 @@ class SimpleProductsFixtureTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() @@ -35,20 +37,31 @@ public function testExecute() ->method('getGroups') ->willReturn([$storeMock]); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->willReturn([$websiteMock]); - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')->disableOriginalConstructor()->getMock(); - - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')->disableOriginalConstructor()->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb')->setConstructorArgs([$contextMock])->setMethods(['getAllChildren'])->getMockForAbstractClass(); + $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') + ->disableOriginalConstructor() + ->getMock(); + + $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') + ->disableOriginalConstructor() + ->getMock(); + $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') + ->setConstructorArgs([$contextMock]) + ->setMethods(['getAllChildren']) + ->getMockForAbstractClass(); $abstractDbMock->expects($this->any()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->getMock(); + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') + ->disableOriginalConstructor() + ->getMock(); $categoryMock->expects($this->once()) ->method('getResource') ->willReturn($abstractDbMock); @@ -62,7 +75,9 @@ public function testExecute() ->method('getName') ->willReturn('category_name'); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->exactly(2)) ->method('create') ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); @@ -96,5 +111,4 @@ public function testIntroduceParamLabels() 'simple_products' => 'Simple products' ], $simpleProductsFixture->introduceParamLabels()); } - } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index ab9760b103d23..c061b6de6f57b 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -18,9 +18,15 @@ class StoresFixtureTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } + /** + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ public function testExecute() { $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); @@ -47,7 +53,9 @@ public function testExecute() $storeMock->expects($this->once()) ->method('save'); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager')->disableOriginalConstructor()->getMock(); + $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); $storeManagerMock->expects($this->once()) ->method('getWebsite') ->willReturn($websiteMock); @@ -61,20 +69,23 @@ public function testExecute() ->method('getStore') ->willReturn($storeMock); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category')->disableOriginalConstructor()->setMethods(array( - 'setId', - 'setUrlKey', - 'setUrlPath', - 'setName', - 'setParentId', - 'setPath', - 'setLevel', - 'setAvailableSortBy', - 'setDefaultSortBy', - 'setIsActive', - 'getId', - 'save' - ))->getMock(); + $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') + ->disableOriginalConstructor() + ->setMethods([ + 'setId', + 'setUrlKey', + 'setUrlPath', + 'setName', + 'setParentId', + 'setPath', + 'setLevel', + 'setAvailableSortBy', + 'setDefaultSortBy', + 'setIsActive', + 'getId', + 'save' + ]) + ->getMock(); $categoryMock->expects($this->once()) ->method('setId') ->willReturnSelf(); @@ -109,7 +120,9 @@ public function testExecute() ->method('getId') ->willReturn('category_id'); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->exactly(2)) ->method('create') ->will($this->onConsecutiveCalls($storeManagerMock, $categoryMock)); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 9e416eb4b06bf..7093b8c02b3b4 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -10,7 +10,8 @@ use Magento\Weee\Model\Attribute\Backend\Weee\Tax; use Test\AAaa\test; -class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase { +class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase +{ /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel @@ -19,24 +20,35 @@ class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel')->disableOriginalConstructor()->getMock(); + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); } public function testExecute() { - $rateMock = $this->getMockBuilder('Magento\Tax\Model\Calculation\Rate')->disableOriginalConstructor()->setMethods(array( - 'setId', - 'delete' - ))->getMock(); + $rateMock = $this->getMockBuilder('Magento\Tax\Model\Calculation\Rate') + ->disableOriginalConstructor() + ->setMethods([ + 'setId', + 'delete' + ]) + ->getMock(); - $collectionMock = $this->getMockBuilder('Magento\Tax\Model\Resource\Calculation\Rate\Collection')->disableOriginalConstructor()->getMock(); + $collectionMock = $this->getMockBuilder('Magento\Tax\Model\Resource\Calculation\Rate\Collection') + ->disableOriginalConstructor() + ->getMock(); $collectionMock->expects($this->once()) ->method('getAllIds') ->willReturn([1]); - $csvImportHandlerMock = $this->getMockBuilder('Magento\TaxImportExport\Model\Rate\CsvImportHandler')->disableOriginalConstructor()->getMock(); + $csvImportHandlerMock = $this->getMockBuilder('Magento\TaxImportExport\Model\Rate\CsvImportHandler') + ->disableOriginalConstructor() + ->getMock(); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager')->disableOriginalConstructor()->getMock(); + $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); $objectManagerMock->expects($this->exactly(2)) ->method('get') ->will($this->onConsecutiveCalls($collectionMock, $rateMock)); @@ -68,5 +80,4 @@ public function testIntroduceParamLabels() $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); $this->assertSame([], $taxRatesFixture->introduceParamLabels()); } - } From 440e2d5f65f0dbd58428faa2a73a57f39ea1be6f Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 9 Jun 2015 13:47:09 -0500 Subject: [PATCH 03/22] MAGETWO-38383: Increase Unit Test Code Coverage - Fixed unit tests --- .../Test/Unit/Fixtures/OrdersFixtureTest.php | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index 0b53a11dfea98..c999e4eb9ce54 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -34,6 +34,17 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase private $fixtureModelMock; public function setUp() + { + $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testExecute() { foreach ($this->mockObjectNames as $mockObjectName) { $mockObject = $this->getMockBuilder($mockObjectName)->disableOriginalConstructor()->getMock(); @@ -52,17 +63,6 @@ public function setUp() $this->mockObjects[] = $map; } - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); - } - - /** - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testExecute() - { $adapterInterfaceMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface') ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -154,10 +154,19 @@ public function testExecute() ->willReturnSelf(); $this->mockObjects[] = ['Magento\Catalog\Model\Category', $categoryMock]; - $productMock = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor()->getMock(); + $productMock = $this->getMockBuilder('\Magento\Catalog\Model\Product') + ->disableOriginalConstructor() + ->setMethods(['load', 'getSku', 'getName']) + ->getMock(); $productMock->expects($this->any()) ->method('load') ->willReturnSelf(); + $productMock->expects($this->any()) + ->method('getSku') + ->willReturn('product_sku'); + $productMock->expects($this->any()) + ->method('getName') + ->willReturn('product_name'); $this->mockObjects[] = ['Magento\Catalog\Model\Product', $productMock]; $this->mockObjects[] = ['Magento\Framework\App\Resource', $resourceMock]; From 074dd430a3f679b67d5fa33dedcb5957165b1bdd Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Thu, 11 Jun 2015 11:29:57 -0500 Subject: [PATCH 04/22] MAGETWO-38383: Increase Unit Test Code Coverage - Removed extra newlines - Changed uses of getMockBuilder to getMock - Removed duplicate code - Replaced onConsecutiveCalls to returnValueMaps --- .../Fixtures/CartPriceRulesFixtureTest.php | 70 ++++----- .../Fixtures/CatalogPriceRulesFixtureTest.php | 72 ++++------ .../Unit/Fixtures/CategoriesFixtureTest.php | 50 ++++--- .../Unit/Fixtures/ConfigsApplyFixtureTest.php | 28 ++-- .../ConfigurableProductsFixtureTest.php | 74 +++++----- .../Unit/Fixtures/CustomersFixtureTest.php | 48 ++++--- .../Fixtures/EavVariationsFixtureTest.php | 54 ++++--- .../IndexersStatesApplyFixtureTest.php | 28 ++-- .../Test/Unit/Fixtures/OrdersFixtureTest.php | 135 ++++++++---------- .../Fixtures/SimpleProductsFixtureTest.php | 73 +++++----- .../Test/Unit/Fixtures/StoresFixtureTest.php | 83 +++++------ .../Unit/Fixtures/TaxRatesFixtureTest.php | 44 +++--- 12 files changed, 368 insertions(+), 391 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index 46240a01f2382..431ad680ae2aa 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -10,27 +10,31 @@ class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase { - /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\CartPriceRulesFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new CartPriceRulesFixture($this->fixtureModelMock); } public function testExecute() { - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) ->method('getRootCategoryId') ->will($this->returnValue(2)); - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); $websiteMock->expects($this->once()) ->method('getGroups') ->will($this->returnValue([$storeMock])); @@ -38,28 +42,27 @@ public function testExecute() ->method('getId') ->will($this->returnValue('website_id')); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') - ->disableOriginalConstructor() - ->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') - ->setConstructorArgs([$contextMock]) - ->setMethods(['getAllChildren']) - ->getMockForAbstractClass(); - $abstractDbMock->expects($this->any()) + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass( + '\Magento\Framework\Model\Resource\Db\AbstractDb', + [$contextMock], + '', + true, + true, + true, + ['getAllChildren'] + ); + $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') - ->disableOriginalConstructor() - ->getMock(); - $categoryMock->expects($this->any()) + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); + $categoryMock->expects($this->once()) ->method('getResource') ->will($this->returnValue($abstractDbMock)); $categoryMock->expects($this->once()) @@ -68,48 +71,45 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('getId') ->will($this->returnValue('category_id')); + $valueMap[] = ['Magento\Catalog\Model\Category', $categoryMock,]; - $modelMock = $this->getMockBuilder('\Magento\SalesRule\Model\Rule')->disableOriginalConstructor()->getMock(); + $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); $modelMock->expects($this->once()) ->method('getIdFieldName') ->will($this->returnValue('Field Id Name')); + $valueMap[] = ['Magento\SalesRule\Model\Rule', $modelMock]; - - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->once()) ->method('create') ->will($this->returnValue($storeManagerMock)); $objectManagerMock->expects($this->exactly(2)) ->method('get') - ->will($this->onConsecutiveCalls($categoryMock, $modelMock)); + ->will($this->returnValueMap($valueMap)); + $valueMap[] = ['cart_price_rules', 0, 1]; + $valueMap[] = ['cart_price_rules_floor', 3, 3]; $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getValue') - ->will($this->onConsecutiveCalls(1, 3)); + ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock ->expects($this->exactly(3)) ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - - $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); - $cartPriceFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); - $this->assertSame('Generating shopping cart price rules', $cartPriceFixture->getActionTitle()); + $this->assertSame('Generating shopping cart price rules', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $cartPriceFixture = new CartPriceRulesFixture($this->fixtureModelMock); $this->assertSame([ 'cart_price_rules' => 'Cart Price Rules' - ], $cartPriceFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index 6776ae71e27e1..f5ddca85604d9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -15,82 +15,70 @@ class CatalogPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\CatalogPriceRulesFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new CatalogPriceRulesFixture($this->fixtureModelMock); } public function testExecute() { $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); - $storeMock - ->expects($this->once()) + $storeMock->expects($this->once()) ->method('getRootCategoryId') ->will($this->returnValue(2)); $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); - $websiteMock - ->expects($this->once()) + $websiteMock->expects($this->once()) ->method('getGroups') ->will($this->returnValue([$storeMock])); - $websiteMock - ->expects($this->once()) + $websiteMock->expects($this->once()) ->method('getId') ->will($this->returnValue('website_id')); $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); - $storeManagerMock - ->expects($this->once()) + $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') - ->disableOriginalConstructor() - ->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') - ->setConstructorArgs([$contextMock]) - ->setMethods(['getAllChildren']) - ->getMockForAbstractClass(); - $abstractDbMock->expects($this->any()) + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass('\Magento\Framework\Model\Resource\Db\AbstractDb', [$contextMock], '', true, true, true, ['getAllChildren']); + $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); - $categoryMock - ->expects($this->any()) + $categoryMock->expects($this->once()) ->method('getResource') ->will($this->returnValue($abstractDbMock)); - $categoryMock - ->expects($this->once()) + $categoryMock->expects($this->once()) ->method('getPath') ->will($this->returnValue('path/to/file')); - $categoryMock - ->expects($this->once()) + $categoryMock->expects($this->once()) ->method('getId') ->will($this->returnValue('category_id')); + $valueMap[] = ['Magento\Catalog\Model\Category', $categoryMock]; - $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); - $modelMock - ->expects($this->once()) + $modelMock = $this->getMock('Magento\CatalogRule\Model\Rule', [], [], '', false); + $modelMock->expects($this->once()) ->method('getIdFieldName') ->will($this->returnValue('Field Id Name')); - + $valueMap[] = ['Magento\CatalogRule\Model\Rule', $modelMock]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); - $objectManagerMock - ->expects($this->once()) + $objectManagerMock->expects($this->once()) ->method('create') ->will($this->returnValue($storeManagerMock)); - $objectManagerMock - ->expects($this->exactly(2)) + $objectManagerMock->expects($this->exactly(2)) ->method('get') - ->will($this->onConsecutiveCalls($categoryMock, $modelMock)); + ->will($this->returnValueMap($valueMap)); - $this->fixtureModelMock - ->expects($this->once()) - ->method('resetObjectManager'); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') @@ -100,22 +88,18 @@ public function testExecute() ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - - $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); - $catalogPriceFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); - $this->assertSame('Generating catalog price rules', $catalogPriceFixture->getActionTitle()); + $this->assertSame('Generating catalog price rules', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $catalogPriceFixture = new CatalogPriceRulesFixture($this->fixtureModelMock); $this->assertSame([ 'catalog_price_rules' => 'Catalog Price Rules' - ], $catalogPriceFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index 44e362aed4608..ca431afe6edc0 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -15,16 +15,22 @@ class CategoriesFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\CategoriesFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new CategoriesFixture($this->fixtureModelMock); } public function testExecute() { - $categoryMock = $this->getMockBuilder('\Magento\Catalog\Model\Category')->disableOriginalConstructor() - ->setMethods([ + $categoryMock = $this->getMock( + '\Magento\Catalog\Model\Category', + [ 'getName', 'setId', 'setUrlKey', @@ -37,9 +43,11 @@ public function testExecute() 'setDefaultSortBy', 'setIsActive', 'save' - ])->getMock(); - $categoryMock - ->expects($this->once()) + ], + [], + '', + false); + $categoryMock->expects($this->once()) ->method('getName') ->will($this->returnValue('category_name')); $categoryMock->expects($this->once()) @@ -72,49 +80,47 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('setIsActive') ->willReturnSelf(); + $valueMap[] = ['Magento\Catalog\Model\Category', [], $categoryMock]; $groupMock = $this->getMock('\Magento\Store\Model\Group', [], [], '', false); - $groupMock - ->expects($this->once()) + $groupMock->expects($this->once()) ->method('getRootCategoryId') ->will($this->returnValue('root_category_id')); $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); - $storeManagerMock - ->expects($this->once()) + $storeManagerMock->expects($this->once()) ->method('getGroups') ->will($this->returnValue([$groupMock])); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); - $objectManagerMock - ->expects($this->exactly(2)) + $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManagerMock, $categoryMock)); + ->will($this->returnValueMap($valueMap)); + $valueMap[] = ['categories', 0, 1]; + $valueMap[] = ['categories_nesting_level', 3, 3]; $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getValue') - ->will($this->onConsecutiveCalls(1, 3)); + ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); - $categoriesFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); - $this->assertSame('Generating categories', $categoriesFixture->getActionTitle()); + $this->assertSame('Generating categories', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $categoriesFixture = new CategoriesFixture($this->fixtureModelMock); $this->assertSame([ 'categories' => 'Categories' - ], $categoriesFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php index 68f004e0dc14d..6a9c3788c93ee 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -16,21 +16,24 @@ class ConfigsApplyFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\ConfigsApplyFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new ConfigsApplyFixture($this->fixtureModelMock); } public function testExecute() { - $cacheMock = $this->getMockBuilder('\Magento\Framework\App\Cache')->disableOriginalConstructor()->getMock(); + $cacheMock = $this->getMock('\Magento\Framework\App\Cache', [], [], '', false); - $valueMock = $this->getMockBuilder('\Magento\Framework\App\Config')->disableOriginalConstructor()->getMock(); + $valueMock = $this->getMock('\Magento\Framework\App\Config', [], [], '', false); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->once()) ->method('get') ->will($this->returnValue($cacheMock)); @@ -44,19 +47,16 @@ public function testExecute() ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); - $configsApplyFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); - $this->assertSame('Config Changes', $configsApplyFixture->getActionTitle()); + $this->assertSame('Config Changes', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $configsApplyFixture = new ConfigsApplyFixture($this->fixtureModelMock); - $this->assertSame([], $configsApplyFixture->introduceParamLabels()); + $this->assertSame([], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 023ad1532bc2d..6d1fc16d29525 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -15,51 +15,61 @@ class ConfigurableProductsFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\ConfigurableProductsFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new ConfigurableProductsFixture($this->fixtureModelMock); } public function testExecute() { - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') - ->disableOriginalConstructor() - ->getMock(); - - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') - ->disableOriginalConstructor() - ->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') - ->setConstructorArgs([$contextMock]) - ->setMethods(['getAllChildren']) - ->getMockForAbstractClass(); - $abstractDbMock->expects($this->any()) + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $valueMap[] = [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'catalog_product', 'behavior' => 'replace']], + $importMock + ]; + + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass( + '\Magento\Framework\Model\Resource\Db\AbstractDb', + [$contextMock], + '', + true, + true, + true, + ['getAllChildren'] + ); + $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') - ->disableOriginalConstructor() - ->getMock(); + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); $categoryMock->expects($this->once()) ->method('getResource') ->will($this->returnValue($abstractDbMock)); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->exactly(3)) ->method('getName') ->will($this->returnValue('category_name')); $categoryMock->expects($this->once()) ->method('getPath') ->will($this->returnValue('path/to/category')); - $categoryMock->expects($this->any())->method('load') + $categoryMock->expects($this->exactly(4)) + ->method('load') ->willReturnSelf(); - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) ->method('getRootCategoryId') ->will($this->returnValue([2])); - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); $websiteMock->expects($this->once()) ->method('getCode') ->will($this->returnValue('website_code')); @@ -67,19 +77,16 @@ public function testExecute() ->method('getGroups') ->will($this->returnValue([$storeMock])); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + ->will($this->returnValueMap($valueMap)); $objectManagerMock->expects($this->once()) ->method('get') ->will($this->returnValue($categoryMock)); @@ -93,21 +100,18 @@ public function testExecute() ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); - $configurableProductsFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); - $this->assertSame('Generating configurable products', $configurableProductsFixture->getActionTitle()); + $this->assertSame('Generating configurable products', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $configurableProductsFixture = new ConfigurableProductsFixture($this->fixtureModelMock); $this->assertSame([ 'configurable_products' => 'Configurable products' - ], $configurableProductsFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index 4f4f6c49f0e30..29dc845215728 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -15,45 +15,50 @@ class CustomersFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\CustomersFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new CustomersFixture($this->fixtureModelMock); } public function testExecute() { - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') - ->disableOriginalConstructor() - ->getMock(); + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $valueMap[] = [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'customer_composite', 'behavior' => 'append']], + $importMock + ]; - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) ->method('getCode') ->will($this->returnValue('store_code')); - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); $websiteMock->expects($this->once()) ->method('getCode') ->will($this->returnValue('website_code')); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getDefaultStoreView') ->will($this->returnValue($storeMock)); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; - $objectManagerMode = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - $objectManagerMode->expects($this->exactly(2)) + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock ->expects($this->once()) @@ -62,23 +67,20 @@ public function testExecute() $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getObjectManager') - ->will($this->returnValue($objectManagerMode)); + ->will($this->returnValue($objectManagerMock)); - $customersFixture = new CustomersFixture($this->fixtureModelMock); - $customersFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $customersFixture = new CustomersFixture($this->fixtureModelMock); - $this->assertSame('Generating customers', $customersFixture->getActionTitle()); + $this->assertSame('Generating customers', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $customersFixture = new CustomersFixture($this->fixtureModelMock); $this->assertSame([ 'customers' => 'Customers' - ], $customersFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index f31b84b6ac00e..72a5423985dad 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -16,54 +16,63 @@ class EavVariationsFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\EavVariationsFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new EavVariationsFixture($this->fixtureModelMock); } public function testExecute() { - $attributeMock = $this->getMockBuilder('Magenot\Catalog\Model\Resource\Eav\Attribute') - ->setMethods(['setAttributeGroupId', 'addData', 'setAttributeSetId', 'save']) - ->getMock(); + $attributeMock = $this->getMock( + 'Magento\Catalog\Model\Resource\Eav\Attribute', + [ + 'setAttributeSetId', + 'setAttributeGroupId', + 'save' + ], + [], + '', + false + ); $attributeMock->expects($this->exactly(2)) ->method('setAttributeSetId') ->willReturnSelf(); $attributeMock->expects($this->once()) ->method('setAttributeGroupId') ->willReturnSelf(); + $valueMap[] = ['Magento\Catalog\Model\Resource\Eav\Attribute', [], $attributeMock]; - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getStores') ->will($this->returnValue([$storeMock])); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; - $setMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Set') - ->disableOriginalConstructor() - ->getMock(); + $setMock = $this->getMock('Magento\Eav\Model\Entity\Attribute\Set', [], [], '', false); $setMock->expects($this->once()) ->method('getDefaultGroupId') ->will($this->returnValue(2)); + $valueMap[] = ['Magento\Eav\Model\Entity\Attribute\Set', $setMock]; - $cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface') - ->disableOriginalConstructor() - ->getMock(); + $cacheMock = $this->getMock('Magento\Framework\App\CacheInterface', [], [], '', false); + $valueMap[] = ['Magento\Framework\App\CacheInterface', $cacheMock]; - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($attributeMock, $storeManagerMock)); + ->will($this->returnValueMap($valueMap)); $objectManagerMock->expects($this->exactly(2)) ->method('get') - ->will($this->onConsecutiveCalls($setMock, $cacheMock)); + ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock ->expects($this->once()) @@ -74,8 +83,7 @@ public function testExecute() ->method('getObjectManager') ->will($this->returnValue($objectManagerMock)); - $eavVariationsFixture = new EavVariationsFixture($this->fixtureModelMock); - $eavVariationsFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php index 0fc1bfd419a1d..2b15554348bc9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -15,22 +15,23 @@ class IndexersStatesApplyFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\IndexersStatesApplyFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new IndexersStatesApplyFixture($this->fixtureModelMock); } public function testExecute() { - $cacheInterfaceMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface') - ->disableOriginalConstructor() - ->getMock(); + $cacheInterfaceMock = $this->getMock('Magento\Framework\App\CacheInterface', [], [], '', false); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->once()) ->method('get') ->willReturn($cacheInterfaceMock); @@ -46,19 +47,16 @@ public function testExecute() ->method('getObjectManager') ->willReturn($objectManagerMock); - $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); - $indexersStatesApplyFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); - $this->assertSame('Indexers Mode Changes', $indexersStatesApplyFixture->getActionTitle()); + $this->assertSame('Indexers Mode Changes', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $indexersStatesApplyFixture = new IndexersStatesApplyFixture($this->fixtureModelMock); - $this->assertSame([], $indexersStatesApplyFixture->introduceParamLabels()); + $this->assertSame([], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index c999e4eb9ce54..8dfb98c21136c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -33,11 +33,16 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\OrdersFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new OrdersFixture($this->fixtureModelMock); } /** @@ -47,7 +52,7 @@ public function setUp() public function testExecute() { foreach ($this->mockObjectNames as $mockObjectName) { - $mockObject = $this->getMockBuilder($mockObjectName)->disableOriginalConstructor()->getMock(); + $mockObject = $this->getMock($mockObjectName, [], [], '', false); $path = explode('\\', $mockObjectName); $name = array_pop($path); if (strcasecmp($mockObjectName, 'Magento\Sales\Model\Resource\Order') == 0) { @@ -59,28 +64,20 @@ public function testExecute() ->method('getTable') ->willReturn(strtolower($name) . '_table_name'); } - $map = [$mockObjectName, $mockObject]; - $this->mockObjects[] = $map; + $this->mockObjects[] = [$mockObjectName, $mockObject]; } - $adapterInterfaceMock = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface') - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $adapterInterfaceMock->expects($this->any()) + $adapterInterfaceMock = $this->getMockForAbstractClass('\Magento\Framework\DB\Adapter\AdapterInterface', [], '', true, true, true, []); + $adapterInterfaceMock->expects($this->exactly(14)) ->method('getTableName') ->willReturn('table_name'); - $resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource') - ->disableOriginalConstructor() - ->getMock(); - $resourceMock->expects($this->any()) + $resourceMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false); + $resourceMock->expects($this->exactly(15)) ->method('getConnection') ->willReturn($adapterInterfaceMock); - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website') - ->disableOriginalConstructor() - ->setMethods(['getId', 'getName']) - ->getMock(); + $websiteMock = $this->getMock('\Magento\Store\Model\Website', ['getId', 'getName'], [], '', false); $websiteMock->expects($this->once()) ->method('getId') ->willReturn('website_id'); @@ -88,21 +85,24 @@ public function testExecute() ->method('getName') ->willReturn('website_name'); - $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group') - ->disableOriginalConstructor() - ->setMethods(['getName']) - ->getMock(); + $groupMock = $this->getMock('\Magento\Store\Model\Group', ['getName'], [], '', false); $groupMock->expects($this->once()) ->method('getName') ->willReturn('group_name'); - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->setMethods([ - 'getStoreId', - 'getWebsite', - 'getGroup', - 'getName', - 'getRootCategoryId' - ])->getMock(); + $storeMock = $this->getMock( + '\Magento\Store\Model\Store', + [ + 'getStoreId', + 'getWebsite', + 'getGroup', + 'getName', + 'getRootCategoryId' + ], + [], + '', + false + ); $storeMock->expects($this->once()) ->method('getStoreId') ->willReturn(1); @@ -119,105 +119,94 @@ public function testExecute() ->method('getRootCategoryId') ->willReturn(1); - $storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); - $storeManager->expects($this->once()) + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock->expects($this->once()) ->method('getStores') ->willReturn([$storeMock]); - - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') - ->disableOriginalConstructor() - ->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') - ->setConstructorArgs([$contextMock]) - ->setMethods(['getAllChildren']) - ->getMockForAbstractClass(); - $abstractDbMock->expects($this->any()) + $this->mockObjects[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; + + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass( + '\Magento\Framework\Model\Resource\Db\AbstractDb', + [$contextMock], + '', + true, + true, + true, + ['getAllChildren'] + ); + $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') - ->disableOriginalConstructor() - ->getMock(); + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); $categoryMock->expects($this->once()) ->method('getResource') ->willReturn($abstractDbMock); $categoryMock->expects($this->once()) ->method('getPath') ->willReturn('path/to/category'); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->exactly(2)) ->method('getName') ->willReturn('category_name'); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->exactly(5)) ->method('load') ->willReturnSelf(); $this->mockObjects[] = ['Magento\Catalog\Model\Category', $categoryMock]; - $productMock = $this->getMockBuilder('\Magento\Catalog\Model\Product') - ->disableOriginalConstructor() - ->setMethods(['load', 'getSku', 'getName']) - ->getMock(); - $productMock->expects($this->any()) + $productMock = $this->getMock('\Magento\Catalog\Model\Product', ['load', 'getSku', 'getName'], [], '', false); + $productMock->expects($this->exactly(2)) ->method('load') ->willReturnSelf(); - $productMock->expects($this->any()) + $productMock->expects($this->exactly(2)) ->method('getSku') ->willReturn('product_sku'); - $productMock->expects($this->any()) + $productMock->expects($this->exactly(2)) ->method('getName') ->willReturn('product_name'); $this->mockObjects[] = ['Magento\Catalog\Model\Product', $productMock]; $this->mockObjects[] = ['Magento\Framework\App\Resource', $resourceMock]; - $selectMock = $this->getMockBuilder('\Magento\Framework\DB\Select')->disableOriginalConstructor()->getMock(); + $selectMock = $this->getMock('\Magento\Framework\DB\Select', [], [], '', false); - $collectionMock = $this->getMockBuilder('\Magento\Catalog\Model\Resource\Product\Collection') - ->disableOriginalConstructor() - ->getMock(); + $collectionMock = $this->getMock('\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false); $collectionMock->expects($this->once()) ->method('getSelect') ->willReturn($selectMock); $collectionMock->expects($this->once()) ->method('getAllIds') ->willReturn([1, 1]); + $this->mockObjects[] = ['Magento\Catalog\Model\Resource\Product\Collection', [], $collectionMock]; - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - $objectManagerMock - ->expects($this->any()) + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->exactly(32)) ->method('get') ->will($this->returnValueMap($this->mockObjects)); - $objectManagerMock - ->expects($this->exactly(2)) + $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManager, $collectionMock)); + ->will($this->returnValueMap($this->mockObjects)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') ->willReturn(1); $this->fixtureModelMock - ->expects($this->any()) + ->expects($this->exactly(34)) ->method('getObjectManager') ->willReturn($objectManagerMock); - $ordersFixture = new OrdersFixture($this->fixtureModelMock); - $ordersFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $ordersFixture = new OrdersFixture($this->fixtureModelMock); - $this->assertSame('Generating orders', $ordersFixture->getActionTitle()); + $this->assertSame('Generating orders', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $ordersFixture = new OrdersFixture($this->fixtureModelMock); $this->assertSame([ 'orders' => 'Orders' - ], $ordersFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index dd5f0d01203d9..a87d075c373e8 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -15,21 +15,26 @@ class SimpleProductsFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\SimpleProductsFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new SimpleProductsFixture($this->fixtureModelMock); } public function testExecute() { - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) ->method('getRootCategoryId') ->willReturn(1); - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); $websiteMock->expects($this->once()) ->method('getCode') ->willReturn('website_code'); @@ -37,50 +42,51 @@ public function testExecute() ->method('getGroups') ->willReturn([$storeMock]); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getWebsites') ->willReturn([$websiteMock]); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; + + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $valueMap[] = [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'catalog_product', 'behavior' => 'append']], + $importMock + ]; - $importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import') - ->disableOriginalConstructor() - ->getMock(); - - $contextMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context') - ->disableOriginalConstructor() - ->getMock(); - $abstractDbMock = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\AbstractDb') - ->setConstructorArgs([$contextMock]) - ->setMethods(['getAllChildren']) - ->getMockForAbstractClass(); - $abstractDbMock->expects($this->any()) + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $abstractDbMock = $this->getMockForAbstractClass( + '\Magento\Framework\Model\Resource\Db\AbstractDb', + [$contextMock], + '', + true, + true, + true, + ['getAllChildren'] + ); + $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') - ->disableOriginalConstructor() - ->getMock(); + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); $categoryMock->expects($this->once()) ->method('getResource') ->willReturn($abstractDbMock); $categoryMock->expects($this->once()) ->method('getPath') ->willReturn('path/to/category'); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->exactly(4)) ->method('load') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->exactly(2)) ->method('getName') ->willReturn('category_name'); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManagerMock, $importMock)); + ->will($this->returnValueMap($valueMap)); $objectManagerMock->expects($this->once()) ->method('get') ->willReturn($categoryMock); @@ -94,21 +100,18 @@ public function testExecute() ->method('getObjectManager') ->willReturn($objectManagerMock); - $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); - $simpleProductsFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); - $this->assertSame('Generating simple products', $simpleProductsFixture->getActionTitle()); + $this->assertSame('Generating simple products', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $simpleProductsFixture = new SimpleProductsFixture($this->fixtureModelMock); $this->assertSame([ 'simple_products' => 'Simple products' - ], $simpleProductsFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index c061b6de6f57b..75a161ebd6218 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -16,11 +16,16 @@ class StoresFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\StoresFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new StoresFixture($this->fixtureModelMock); } /** @@ -29,21 +34,21 @@ public function setUp() */ public function testExecute() { - $websiteMock = $this->getMockBuilder('\Magento\Store\Model\Website')->disableOriginalConstructor()->getMock(); - $websiteMock->expects($this->any()) + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); + $websiteMock->expects($this->exactly(2)) ->method('getId') ->willReturn('website_id'); $websiteMock->expects($this->once()) ->method('save'); - $groupMock = $this->getMockBuilder('\Magento\Store\Model\Group')->disableOriginalConstructor()->getMock(); - $groupMock->expects($this->any()) + $groupMock = $this->getMock('\Magento\Store\Model\Group', [], [], '', false); + $groupMock->expects($this->exactly(2)) ->method('getId') ->willReturn('group_id'); $groupMock->expects($this->once()) ->method('save'); - $storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')->disableOriginalConstructor()->getMock(); + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) ->method('getRootCategoryId') ->willReturn(1); @@ -53,9 +58,7 @@ public function testExecute() $storeMock->expects($this->once()) ->method('save'); - $storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $storeManagerMock->expects($this->once()) ->method('getWebsite') ->willReturn($websiteMock); @@ -68,15 +71,13 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getStore') ->willReturn($storeMock); + $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; - $categoryMock = $this->getMockBuilder('Magento\Catalog\Model\Category') - ->disableOriginalConstructor() - ->setMethods([ + $categoryMock = $this->getMock( + 'Magento\Catalog\Model\Category', + [ 'setId', - 'setUrlKey', - 'setUrlPath', 'setName', - 'setParentId', 'setPath', 'setLevel', 'setAvailableSortBy', @@ -84,75 +85,65 @@ public function testExecute() 'setIsActive', 'getId', 'save' - ]) - ->getMock(); + ], + [], + '', + false + ); $categoryMock->expects($this->once()) ->method('setId') ->willReturnSelf(); - $categoryMock->expects($this->any()) - ->method('setUrlKey') - ->willReturnSelf(); - $categoryMock->expects($this->any()) - ->method('setUrlPath') - ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setName') ->willReturnSelf(); - $categoryMock->expects($this->any()) - ->method('setParentId') - ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setPath') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setLevel') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setAvailableSortBy') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setDefaultSortBy') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('setIsActive') ->willReturnSelf(); - $categoryMock->expects($this->any()) + $categoryMock->expects($this->once()) ->method('getId') ->willReturn('category_id'); + $valueMap[] = ['Magento\Catalog\Model\Category', [], $categoryMock]; - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->onConsecutiveCalls($storeManagerMock, $categoryMock)); + ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock ->expects($this->exactly(3)) ->method('getValue') - ->will($this->onConsecutiveCalls(1, 1, 1)); + ->will($this->returnValue(1)); $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getObjectManager') ->willReturn($objectManagerMock); - $storesFixture = new StoresFixture($this->fixtureModelMock); - $storesFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $storesFixture = new StoresFixture($this->fixtureModelMock); - $this->assertSame('Generating websites, stores and store views', $storesFixture->getActionTitle()); + $this->assertSame('Generating websites, stores and store views', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $storesFixture = new StoresFixture($this->fixtureModelMock); $this->assertSame([ 'websites' => 'Websites', 'store_groups' => 'Store Groups', 'store_views' => 'Store Views' - ], $storesFixture->introduceParamLabels()); + ], $this->model->introduceParamLabels()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 7093b8c02b3b4..7f557b3fbad48 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -18,40 +18,35 @@ class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase */ private $fixtureModelMock; + /** + * @var \Magento\Setup\Fixtures\TaxRatesFixture + */ + private $model; + public function setUp() { - $this->fixtureModelMock = $this->getMockBuilder('\Magento\Setup\Fixtures\FixtureModel') - ->disableOriginalConstructor() - ->getMock(); + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); + + $this->model = new TaxRatesFixture($this->fixtureModelMock); } public function testExecute() { - $rateMock = $this->getMockBuilder('Magento\Tax\Model\Calculation\Rate') - ->disableOriginalConstructor() - ->setMethods([ - 'setId', - 'delete' - ]) - ->getMock(); + $rateMock = $this->getMock('Magento\Tax\Model\Calculation\Rate', ['setId', 'delete'], [], '', false); + $valueMap[] = ['Magento\Tax\Model\Calculation\Rate', $rateMock]; - $collectionMock = $this->getMockBuilder('Magento\Tax\Model\Resource\Calculation\Rate\Collection') - ->disableOriginalConstructor() - ->getMock(); + $collectionMock = $this->getMock('Magento\Tax\Model\Resource\Calculation\Rate\Collection', [], [], '', false); $collectionMock->expects($this->once()) ->method('getAllIds') ->willReturn([1]); + $valueMap[] = ['Magento\Tax\Model\Resource\Calculation\Rate\Collection', $collectionMock]; - $csvImportHandlerMock = $this->getMockBuilder('Magento\TaxImportExport\Model\Rate\CsvImportHandler') - ->disableOriginalConstructor() - ->getMock(); + $csvImportHandlerMock = $this->getMock('Magento\TaxImportExport\Model\Rate\CsvImportHandler', [], [], '', false); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('get') - ->will($this->onConsecutiveCalls($collectionMock, $rateMock)); + ->will($this->returnValueMap($valueMap)); $objectManagerMock->expects($this->once()) ->method('create') ->willReturn($csvImportHandlerMock); @@ -65,19 +60,16 @@ public function testExecute() ->method('getObjectManager') ->willReturn($objectManagerMock); - $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); - $taxRatesFixture->execute(); + $this->model->execute(); } public function testGetActionTitle() { - $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); - $this->assertSame('Generating tax rates', $taxRatesFixture->getActionTitle()); + $this->assertSame('Generating tax rates', $this->model->getActionTitle()); } public function testIntroduceParamLabels() { - $taxRatesFixture = new TaxRatesFixture($this->fixtureModelMock); - $this->assertSame([], $taxRatesFixture->introduceParamLabels()); + $this->assertSame([], $this->model->introduceParamLabels()); } } From 8f22d9c219191017aff4972169b1dde61f21d81e Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Thu, 11 Jun 2015 14:05:57 -0500 Subject: [PATCH 05/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added an extra test case --- .../Test/Unit/Fixtures/CartPriceRulesFixtureTest.php | 10 ++++++++++ .../Unit/Fixtures/CatalogPriceRulesFixtureTest.php | 10 ++++++++++ .../Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php | 10 ++++++++++ .../Test/Unit/Fixtures/ConfigsApplyFixtureTest.php | 10 ++++++++++ .../Unit/Fixtures/ConfigurableProductsFixtureTest.php | 10 ++++++++++ .../Setup/Test/Unit/Fixtures/CustomersFixtureTest.php | 10 ++++++++++ .../Test/Unit/Fixtures/EavVariationsFixtureTest.php | 10 ++++++++++ .../Unit/Fixtures/IndexersStatesApplyFixtureTest.php | 10 ++++++++++ .../Setup/Test/Unit/Fixtures/OrdersFixtureTest.php | 10 ++++++++++ .../Test/Unit/Fixtures/SimpleProductsFixtureTest.php | 10 ++++++++++ .../Setup/Test/Unit/Fixtures/StoresFixtureTest.php | 10 ++++++++++ .../Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php | 10 ++++++++++ 12 files changed, 120 insertions(+) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index 431ad680ae2aa..fda4061935535 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -101,6 +101,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating shopping cart price rules', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index f5ddca85604d9..eac3b0016c199 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -91,6 +91,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating catalog price rules', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index ca431afe6edc0..c5a0b8ee72457 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -112,6 +112,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating categories', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php index 6a9c3788c93ee..3f30db224c8ac 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -50,6 +50,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Config Changes', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 6d1fc16d29525..4dd92b6a112f5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -103,6 +103,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating configurable products', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index 29dc845215728..29470069c24ed 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -72,6 +72,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating customers', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index 72a5423985dad..67359bb1282c4 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -86,6 +86,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $eavVariationsFixture = new EavVariationsFixture($this->fixtureModelMock); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php index 2b15554348bc9..72a669d30edea 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -50,6 +50,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Indexers Mode Changes', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index 8dfb98c21136c..572bcd0429a85 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -198,6 +198,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating orders', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index a87d075c373e8..8b18e61cbde0e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -103,6 +103,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating simple products', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index 75a161ebd6218..cd9538fbc921c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -133,6 +133,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->exactly(3)) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating websites, stores and store views', $this->model->getActionTitle()); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 7f557b3fbad48..3b9aa8eca237f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -63,6 +63,16 @@ public function testExecute() $this->model->execute(); } + public function testExecuteEarlyReturn() + { + $this->fixtureModelMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); + + $this->model->execute(); + } + public function testGetActionTitle() { $this->assertSame('Generating tax rates', $this->model->getActionTitle()); From 2e87cc783d700ff3c4d2d3ee1115e19ea4bde258 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Fri, 12 Jun 2015 11:17:19 -0500 Subject: [PATCH 06/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added unit test for FixtureModel --- .../Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 3b9aa8eca237f..86b3609d68d68 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -7,8 +7,6 @@ namespace Magento\Setup\Test\Unit\Fixtures; use \Magento\Setup\Fixtures\TaxRatesFixture; -use Magento\Weee\Model\Attribute\Backend\Weee\Tax; -use Test\AAaa\test; class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase { From e1676358ef9e7265a31fcc84f395d4c0de18c75f Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Fri, 12 Jun 2015 11:17:19 -0500 Subject: [PATCH 07/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added unit test for FixtureModel --- .../Test/Unit/Fixtures/FixtureModelTest.php | 99 +++++++++++++++++++ .../Unit/Fixtures/TaxRatesFixtureTest.php | 2 - 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php new file mode 100644 index 0000000000000..fb155cb6cd20d --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php @@ -0,0 +1,99 @@ +getMock('\Magento\Indexer\Console\Command\IndexerReindexCommand', [], [], '', false); + $fileParserMock = $this->getMock('\Magento\Framework\XML\Parser', [], [], '', false); + + $this->model = new FixtureModel($reindexCommandMock, $fileParserMock); + } + + public function testGetObjectManager() + { + $this->assertInstanceOf('Magento\Framework\ObjectManager\ObjectManager', $this->model->getObjectManager()); + } + + public function testReindex() + { + $outputMock = $this->getMock('\Symfony\Component\Console\Output\OutputInterface', [], [], '', false); + $this->model->reindex($outputMock); + } + + public function testLoadFixtures() + { + // Necessary so that the FixtureModel has an ObjectManager instantiated otherwise this test fails. + $this->model->getObjectManager(); + $this->model->loadFixtures(); + } + + public function testGetParamLabels() + { + $this->assertSame([], $this->model->getParamLabels()); + } + + public function testGetFixtures() + { + $this->assertSame([], $this->model->getFixtures()); + } + + public function testInitObjectManager() + { + $this->assertSame($this->model, $this->model->initObjectManager()); + } + + public function testResetObjectManager() + { + $this->assertSame($this->model, $this->model->resetObjectManager()); + } + + /** + * @expectedException \Exception + */ + public function testLoadConfigException() + { + $this->model->loadConfig('exception.file'); + } + + public function testLoadConfig() + { + $reindexCommandMock = $this->getMock('\Magento\Indexer\Console\Command\IndexerReindexCommand', [], [], '', false); + + $fileParserMock = $this->getMock('\Magento\Framework\XML\Parser', [], [], '', false); + $fileParserMock->expects($this->once()) + ->method('load') + ->willReturnSelf(); + + $this->model = new FixtureModel($reindexCommandMock, $fileParserMock); + $this->model->loadConfig('config.file'); + } + + public function testGetValue() + { + $this->assertSame(null, $this->model->getValue('null_key')); + } +} + +namespace Magento\Setup\Fixtures; + +function is_readable($filename) +{ + if (strpos($filename, 'exception') !== false) { + return false; + } + return true; +} diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 3b9aa8eca237f..86b3609d68d68 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -7,8 +7,6 @@ namespace Magento\Setup\Test\Unit\Fixtures; use \Magento\Setup\Fixtures\TaxRatesFixture; -use Magento\Weee\Model\Attribute\Backend\Weee\Tax; -use Test\AAaa\test; class TaxRatesFixtureTest extends \PHPUnit_Framework_TestCase { From 5af921b80c20297c1d475cd817c024a1b8a644ef Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 16 Jun 2015 10:23:35 -0500 Subject: [PATCH 08/22] MAGETWO-38383: Increase Unit Test Code Coverage - Edited code style --- .../Unit/Fixtures/CatalogPriceRulesFixtureTest.php | 10 +++++++++- .../Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php | 3 ++- .../Setup/Test/Unit/Fixtures/OrdersFixtureTest.php | 10 +++++++++- .../Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php | 8 +++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index eac3b0016c199..7dd2bbde1da1d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -48,7 +48,15 @@ public function testExecute() ->will($this->returnValue([$websiteMock])); $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); - $abstractDbMock = $this->getMockForAbstractClass('\Magento\Framework\Model\Resource\Db\AbstractDb', [$contextMock], '', true, true, true, ['getAllChildren']); + $abstractDbMock = $this->getMockForAbstractClass( + '\Magento\Framework\Model\Resource\Db\AbstractDb', + [$contextMock], + '', + true, + true, + true, + ['getAllChildren'] + ); $abstractDbMock->expects($this->once()) ->method('getAllChildren') ->will($this->returnValue([1])); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index c5a0b8ee72457..b62472dc171e2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -46,7 +46,8 @@ public function testExecute() ], [], '', - false); + false + ); $categoryMock->expects($this->once()) ->method('getName') ->will($this->returnValue('category_name')); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index 572bcd0429a85..f6b54dd0444c8 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -67,7 +67,15 @@ public function testExecute() $this->mockObjects[] = [$mockObjectName, $mockObject]; } - $adapterInterfaceMock = $this->getMockForAbstractClass('\Magento\Framework\DB\Adapter\AdapterInterface', [], '', true, true, true, []); + $adapterInterfaceMock = $this->getMockForAbstractClass( + '\Magento\Framework\DB\Adapter\AdapterInterface', + [], + '', + true, + true, + true, + [] + ); $adapterInterfaceMock->expects($this->exactly(14)) ->method('getTableName') ->willReturn('table_name'); diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 86b3609d68d68..3c204de470829 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -39,7 +39,13 @@ public function testExecute() ->willReturn([1]); $valueMap[] = ['Magento\Tax\Model\Resource\Calculation\Rate\Collection', $collectionMock]; - $csvImportHandlerMock = $this->getMock('Magento\TaxImportExport\Model\Rate\CsvImportHandler', [], [], '', false); + $csvImportHandlerMock = $this->getMock( + 'Magento\TaxImportExport\Model\Rate\CsvImportHandler', + [], + [], + '', + false + ); $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) From 0784387a68bd0a53fe80566e6ab41c3f192fba47 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 16 Jun 2015 10:28:31 -0500 Subject: [PATCH 09/22] MAGETWO-38383: Increase Unit Test Code Coverage - Edited code style --- .../Test/Unit/Fixtures/CartPriceRulesFixtureTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index fda4061935535..4e19456fe7198 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -42,11 +42,6 @@ public function testExecute() ->method('getId') ->will($this->returnValue('website_id')); - $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); - $storeManagerMock->expects($this->once()) - ->method('getWebsites') - ->will($this->returnValue([$websiteMock])); - $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); $abstractDbMock = $this->getMockForAbstractClass( '\Magento\Framework\Model\Resource\Db\AbstractDb', @@ -61,6 +56,11 @@ public function testExecute() ->method('getAllChildren') ->will($this->returnValue([1])); + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->will($this->returnValue([$websiteMock])); + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); $categoryMock->expects($this->once()) ->method('getResource') From 855ea82e94796a5480494bba19a3970714d10291 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 16 Jun 2015 10:52:55 -0500 Subject: [PATCH 10/22] MAGETWO-38383: Increase Unit Test Code Coverage - Edited code style --- .../Test/Unit/Fixtures/FixtureModelTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php index fb155cb6cd20d..931832a902996 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php @@ -8,7 +8,8 @@ use \Magento\Setup\Fixtures\FixtureModel; -class FixtureModelTest extends \PHPUnit_Framework_TestCase { +class FixtureModelTest extends \PHPUnit_Framework_TestCase +{ /** * @var \Magento\Setup\Fixtures\FixtureModel @@ -17,7 +18,13 @@ class FixtureModelTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $reindexCommandMock = $this->getMock('\Magento\Indexer\Console\Command\IndexerReindexCommand', [], [], '', false); + $reindexCommandMock = $this->getMock( + '\Magento\Indexer\Console\Command\IndexerReindexCommand', + [], + [], + '', + false + ); $fileParserMock = $this->getMock('\Magento\Framework\XML\Parser', [], [], '', false); $this->model = new FixtureModel($reindexCommandMock, $fileParserMock); @@ -71,7 +78,13 @@ public function testLoadConfigException() public function testLoadConfig() { - $reindexCommandMock = $this->getMock('\Magento\Indexer\Console\Command\IndexerReindexCommand', [], [], '', false); + $reindexCommandMock = $this->getMock( + '\Magento\Indexer\Console\Command\IndexerReindexCommand', + [], + [], + '', + false + ); $fileParserMock = $this->getMock('\Magento\Framework\XML\Parser', [], [], '', false); $fileParserMock->expects($this->once()) From c569d66e9db8bdafcb1e1ca6b7a08eea379de0a4 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Wed, 17 Jun 2015 10:28:43 -0500 Subject: [PATCH 11/22] MAGETWO-38383: Increase Unit Test Code Coverage - Merged valueMap values into one array. --- .../Unit/Fixtures/CartPriceRulesFixtureTest.php | 16 +++++++++++----- .../Fixtures/CatalogPriceRulesFixtureTest.php | 7 +++++-- .../Test/Unit/Fixtures/CategoriesFixtureTest.php | 16 +++++++++++----- .../Fixtures/ConfigurableProductsFixtureTest.php | 15 +++++++++------ .../Test/Unit/Fixtures/CustomersFixtureTest.php | 15 +++++++++------ .../Unit/Fixtures/EavVariationsFixtureTest.php | 11 +++++++---- .../Test/Unit/Fixtures/OrdersFixtureTest.php | 14 +++++++++----- .../Unit/Fixtures/SimpleProductsFixtureTest.php | 15 +++++++++------ .../Test/Unit/Fixtures/StoresFixtureTest.php | 7 +++++-- .../Test/Unit/Fixtures/TaxRatesFixtureTest.php | 7 +++++-- 10 files changed, 80 insertions(+), 43 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index 4e19456fe7198..60dd0d22dd211 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -71,13 +71,16 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('getId') ->will($this->returnValue('category_id')); - $valueMap[] = ['Magento\Catalog\Model\Category', $categoryMock,]; $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); $modelMock->expects($this->once()) ->method('getIdFieldName') ->will($this->returnValue('Field Id Name')); - $valueMap[] = ['Magento\SalesRule\Model\Rule', $modelMock]; + + $objectValueMap = [ + ['Magento\SalesRule\Model\Rule', $modelMock], + ['Magento\Catalog\Model\Category', $categoryMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->once()) @@ -85,10 +88,13 @@ public function testExecute() ->will($this->returnValue($storeManagerMock)); $objectManagerMock->expects($this->exactly(2)) ->method('get') - ->will($this->returnValueMap($valueMap)); + ->will($this->returnValueMap($objectValueMap)); + + $valueMap = [ + ['cart_price_rules', 0, 1], + ['cart_price_rules_floor', 3, 3] + ]; - $valueMap[] = ['cart_price_rules', 0, 1]; - $valueMap[] = ['cart_price_rules_floor', 3, 3]; $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index 7dd2bbde1da1d..336fde14d3724 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -71,13 +71,16 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('getId') ->will($this->returnValue('category_id')); - $valueMap[] = ['Magento\Catalog\Model\Category', $categoryMock]; $modelMock = $this->getMock('Magento\CatalogRule\Model\Rule', [], [], '', false); $modelMock->expects($this->once()) ->method('getIdFieldName') ->will($this->returnValue('Field Id Name')); - $valueMap[] = ['Magento\CatalogRule\Model\Rule', $modelMock]; + + $valueMap = [ + ['Magento\CatalogRule\Model\Rule', $modelMock], + ['Magento\Catalog\Model\Category', $categoryMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index b62472dc171e2..4b95fa95b8a16 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -81,7 +81,6 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('setIsActive') ->willReturnSelf(); - $valueMap[] = ['Magento\Catalog\Model\Category', [], $categoryMock]; $groupMock = $this->getMock('\Magento\Store\Model\Group', [], [], '', false); $groupMock->expects($this->once()) @@ -92,15 +91,22 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getGroups') ->will($this->returnValue([$groupMock])); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; + + $objectValueMock = [ + ['Magento\Store\Model\StoreManager', [], $storeManagerMock], + ['Magento\Catalog\Model\Category', [], $categoryMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->returnValueMap($valueMap)); + ->will($this->returnValueMap($objectValueMock)); + + $valueMap = [ + ['categories', 0, 1], + ['categories_nesting_level', 3, 3] + ]; - $valueMap[] = ['categories', 0, 1]; - $valueMap[] = ['categories_nesting_level', 3, 3]; $this->fixtureModelMock ->expects($this->exactly(2)) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 4dd92b6a112f5..3f13cc59021f6 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -30,11 +30,6 @@ public function setUp() public function testExecute() { $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); - $valueMap[] = [ - 'Magento\ImportExport\Model\Import', - ['data' => ['entity' => 'catalog_product', 'behavior' => 'replace']], - $importMock - ]; $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); $abstractDbMock = $this->getMockForAbstractClass( @@ -81,7 +76,15 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; + + $valueMap = [ + [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'catalog_product', 'behavior' => 'replace']], + $importMock + ], + ['Magento\Store\Model\StoreManager', [], $storeManagerMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index 29470069c24ed..6ac4d4cc74721 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -30,11 +30,6 @@ public function setUp() public function testExecute() { $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); - $valueMap[] = [ - 'Magento\ImportExport\Model\Import', - ['data' => ['entity' => 'customer_composite', 'behavior' => 'append']], - $importMock - ]; $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $storeMock->expects($this->once()) @@ -53,7 +48,15 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getWebsites') ->will($this->returnValue([$websiteMock])); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; + + $valueMap = [ + [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'customer_composite', 'behavior' => 'append']], + $importMock + ], + ['Magento\Store\Model\StoreManager', [], $storeManagerMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index 67359bb1282c4..127983f24af23 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -47,7 +47,6 @@ public function testExecute() $attributeMock->expects($this->once()) ->method('setAttributeGroupId') ->willReturnSelf(); - $valueMap[] = ['Magento\Catalog\Model\Resource\Eav\Attribute', [], $attributeMock]; $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); @@ -55,16 +54,20 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getStores') ->will($this->returnValue([$storeMock])); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; $setMock = $this->getMock('Magento\Eav\Model\Entity\Attribute\Set', [], [], '', false); $setMock->expects($this->once()) ->method('getDefaultGroupId') ->will($this->returnValue(2)); - $valueMap[] = ['Magento\Eav\Model\Entity\Attribute\Set', $setMock]; $cacheMock = $this->getMock('Magento\Framework\App\CacheInterface', [], [], '', false); - $valueMap[] = ['Magento\Framework\App\CacheInterface', $cacheMock]; + + $valueMap = [ + ['Magento\Catalog\Model\Resource\Eav\Attribute', [], $attributeMock], + ['Magento\Store\Model\StoreManager', [], $storeManagerMock], + ['Magento\Eav\Model\Entity\Attribute\Set', $setMock], + ['Magento\Framework\App\CacheInterface', $cacheMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index f6b54dd0444c8..47d62421e67cd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -131,7 +131,6 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getStores') ->willReturn([$storeMock]); - $this->mockObjects[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); $abstractDbMock = $this->getMockForAbstractClass( @@ -160,7 +159,6 @@ public function testExecute() $categoryMock->expects($this->exactly(5)) ->method('load') ->willReturnSelf(); - $this->mockObjects[] = ['Magento\Catalog\Model\Category', $categoryMock]; $productMock = $this->getMock('\Magento\Catalog\Model\Product', ['load', 'getSku', 'getName'], [], '', false); $productMock->expects($this->exactly(2)) @@ -172,8 +170,6 @@ public function testExecute() $productMock->expects($this->exactly(2)) ->method('getName') ->willReturn('product_name'); - $this->mockObjects[] = ['Magento\Catalog\Model\Product', $productMock]; - $this->mockObjects[] = ['Magento\Framework\App\Resource', $resourceMock]; $selectMock = $this->getMock('\Magento\Framework\DB\Select', [], [], '', false); @@ -184,7 +180,15 @@ public function testExecute() $collectionMock->expects($this->once()) ->method('getAllIds') ->willReturn([1, 1]); - $this->mockObjects[] = ['Magento\Catalog\Model\Resource\Product\Collection', [], $collectionMock]; + + array_push( + $this->mockObjects, + ['Magento\Store\Model\StoreManager', [], $storeManagerMock], + ['Magento\Catalog\Model\Category', $categoryMock], + ['Magento\Catalog\Model\Product', $productMock], + ['Magento\Framework\App\Resource', $resourceMock], + ['Magento\Catalog\Model\Resource\Product\Collection', [], $collectionMock] + ); $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(32)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index 8b18e61cbde0e..cddc212bb2c75 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -46,14 +46,8 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getWebsites') ->willReturn([$websiteMock]); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); - $valueMap[] = [ - 'Magento\ImportExport\Model\Import', - ['data' => ['entity' => 'catalog_product', 'behavior' => 'append']], - $importMock - ]; $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); $abstractDbMock = $this->getMockForAbstractClass( @@ -83,6 +77,15 @@ public function testExecute() ->method('getName') ->willReturn('category_name'); + $valueMap = [ + [ + 'Magento\ImportExport\Model\Import', + ['data' => ['entity' => 'catalog_product', 'behavior' => 'append']], + $importMock + ], + ['Magento\Store\Model\StoreManager', [], $storeManagerMock] + ]; + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('create') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index cd9538fbc921c..e234a82524e7e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -71,7 +71,6 @@ public function testExecute() $storeManagerMock->expects($this->once()) ->method('getStore') ->willReturn($storeMock); - $valueMap[] = ['Magento\Store\Model\StoreManager', [], $storeManagerMock]; $categoryMock = $this->getMock( 'Magento\Catalog\Model\Category', @@ -114,7 +113,11 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('getId') ->willReturn('category_id'); - $valueMap[] = ['Magento\Catalog\Model\Category', [], $categoryMock]; + + $valueMap = [ + ['Magento\Store\Model\StoreManager', [], $storeManagerMock], + ['Magento\Catalog\Model\Category', [], $categoryMock] + ]; $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 3c204de470829..f183c4ea34a19 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -31,13 +31,11 @@ public function setUp() public function testExecute() { $rateMock = $this->getMock('Magento\Tax\Model\Calculation\Rate', ['setId', 'delete'], [], '', false); - $valueMap[] = ['Magento\Tax\Model\Calculation\Rate', $rateMock]; $collectionMock = $this->getMock('Magento\Tax\Model\Resource\Calculation\Rate\Collection', [], [], '', false); $collectionMock->expects($this->once()) ->method('getAllIds') ->willReturn([1]); - $valueMap[] = ['Magento\Tax\Model\Resource\Calculation\Rate\Collection', $collectionMock]; $csvImportHandlerMock = $this->getMock( 'Magento\TaxImportExport\Model\Rate\CsvImportHandler', @@ -47,6 +45,11 @@ public function testExecute() false ); + $valueMap = [ + ['Magento\Tax\Model\Calculation\Rate', $rateMock], + ['Magento\Tax\Model\Resource\Calculation\Rate\Collection', $collectionMock] + ]; + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(2)) ->method('get') From fb5f16e05a80538cedc6a6da4490ba1f5e7f559c Mon Sep 17 00:00:00 2001 From: Fred Sung Date: Tue, 16 Jun 2015 16:59:56 -0500 Subject: [PATCH 12/22] MAGETWO-38402: Stuck in readiness check when PHP setting checking timeout - Add missing variables to examine readiness check completeness. --- setup/pub/magento/setup/readiness-check.js | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/pub/magento/setup/readiness-check.js b/setup/pub/magento/setup/readiness-check.js index fa6da9344a549..b4aefc1abf0cc 100644 --- a/setup/pub/magento/setup/readiness-check.js +++ b/setup/pub/magento/setup/readiness-check.js @@ -105,6 +105,7 @@ angular.module('readiness-check', []) $scope.isCompleted = function() { return $scope.version.processed + && $scope.settings.processed && $scope.extensions.processed && $scope.permissions.processed; }; From 0a6b86ef75b9c57cc012d8ea83c978b50f6e231d Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Wed, 17 Jun 2015 13:17:31 -0500 Subject: [PATCH 13/22] MAGETWO-38383: Increase Unit Test Code Coverage - Corrected assertions for failing unit tests. --- .../Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 3f13cc59021f6..0a99247b31838 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -80,7 +80,7 @@ public function testExecute() $valueMap = [ [ 'Magento\ImportExport\Model\Import', - ['data' => ['entity' => 'catalog_product', 'behavior' => 'replace']], + ['data' => ['entity' => 'catalog_product', 'behavior' => 'append']], $importMock ], ['Magento\Store\Model\StoreManager', [], $storeManagerMock] diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index cddc212bb2c75..e93da37446403 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -70,10 +70,10 @@ public function testExecute() $categoryMock->expects($this->once()) ->method('getPath') ->willReturn('path/to/category'); - $categoryMock->expects($this->exactly(4)) + $categoryMock->expects($this->exactly(5)) ->method('load') ->willReturnSelf(); - $categoryMock->expects($this->exactly(2)) + $categoryMock->expects($this->exactly(3)) ->method('getName') ->willReturn('category_name'); From 207da596cf69f1107e0e253b538794d046cbddb7 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Wed, 17 Jun 2015 16:56:58 -0500 Subject: [PATCH 14/22] MAGETWO-38383: Increase Unit Test Code Coverage -Added comment to explain why a built-in PHP function was overwritten. --- .../Setup/Test/Unit/Fixtures/FixtureModelTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php index 931832a902996..353dd2bcf06bd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php @@ -103,6 +103,15 @@ public function testGetValue() namespace Magento\Setup\Fixtures; +/** + * Overriding the built-in PHP function since it cannot be mocked-> + * + * The method is used in FixtureModel. loadConfig in an if statement. By overriding this method we are able to test + * both of the possible cases based on the return value of is_readable. + * + * @param $filename + * @return bool + */ function is_readable($filename) { if (strpos($filename, 'exception') !== false) { From 38484c9f0a7ccb08aeb04ef848e8e4a5de83d845 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Thu, 18 Jun 2015 11:30:22 -0500 Subject: [PATCH 15/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added an extra assertion - Removed test methods that were of no value --- .../Test/Unit/Fixtures/FixtureModelTest.php | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php index 353dd2bcf06bd..95a290f6f5960 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php @@ -41,35 +41,9 @@ public function testReindex() $this->model->reindex($outputMock); } - public function testLoadFixtures() - { - // Necessary so that the FixtureModel has an ObjectManager instantiated otherwise this test fails. - $this->model->getObjectManager(); - $this->model->loadFixtures(); - } - - public function testGetParamLabels() - { - $this->assertSame([], $this->model->getParamLabels()); - } - - public function testGetFixtures() - { - $this->assertSame([], $this->model->getFixtures()); - } - - public function testInitObjectManager() - { - $this->assertSame($this->model, $this->model->initObjectManager()); - } - - public function testResetObjectManager() - { - $this->assertSame($this->model, $this->model->resetObjectManager()); - } - /** * @expectedException \Exception + * @expectedExceptionMessage Profile configuration file `exception.file` is not readable or does not exists. */ public function testLoadConfigException() { From 6dda9790094f01e0c2aa52832679174ff1c5fe85 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Thu, 18 Jun 2015 11:41:52 -0500 Subject: [PATCH 16/22] MAGETWO-38383: Increase Unit Test Code Coverage - Changed method names --- .../Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php | 2 +- .../Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php | 2 +- .../Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php | 2 +- .../Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php | 2 +- .../src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php | 2 +- .../Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php | 2 +- .../src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php | 2 +- .../Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index 60dd0d22dd211..a8a129f48cda9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -107,7 +107,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index 336fde14d3724..06e6c9502c59f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -102,7 +102,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index 4b95fa95b8a16..96b1a6f55ec03 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -119,7 +119,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php index 3f30db224c8ac..22bff7a8bd2cd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -50,7 +50,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 0a99247b31838..8a99a88f4b2c8 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -106,7 +106,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index 6ac4d4cc74721..68ba5651304b6 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -75,7 +75,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index 127983f24af23..2854a4d153ec2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -89,7 +89,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php index 72a669d30edea..5e06aaf61d677 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -50,7 +50,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index 47d62421e67cd..d97e1085e6eed 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -210,7 +210,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index e93da37446403..f26c416848b72 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -106,7 +106,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index e234a82524e7e..2cec584560505 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -136,7 +136,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->exactly(3)) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index f183c4ea34a19..0e1442dc3785f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -70,7 +70,7 @@ public function testExecute() $this->model->execute(); } - public function testExecuteEarlyReturn() + public function testNoFixtureConfigValue() { $this->fixtureModelMock ->expects($this->once()) From 72ec3746d8da12e2fec388da7dac5aa3e312e4e1 Mon Sep 17 00:00:00 2001 From: Fred Sung Date: Mon, 22 Jun 2015 18:42:45 -0500 Subject: [PATCH 17/22] MAGETWO-38402: Stuck in readiness check when PHP setting checking timeout - Add error event handler and timeout value for $http.get() - progress.phtml layout update to display error message when error event has been triggered. --- setup/pub/magento/setup/readiness-check.js | 38 +++- .../setup/readiness-check/progress.phtml | 162 ++++++++++-------- 2 files changed, 123 insertions(+), 77 deletions(-) diff --git a/setup/pub/magento/setup/readiness-check.js b/setup/pub/magento/setup/readiness-check.js index b4aefc1abf0cc..1b421e191b8e2 100644 --- a/setup/pub/magento/setup/readiness-check.js +++ b/setup/pub/magento/setup/readiness-check.js @@ -23,6 +23,13 @@ angular.module('readiness-check', []) $rootScope.checkingInProgress = function() { return $scope.progressCounter > 0; }; + $scope.requestFailedHandler = function(obj) { + obj.processed = true; + obj.isRequestError = true; + $scope.hasErrors = true; + $rootScope.hasErrors = true; + $scope.stopProgress(); + } $scope.completed = false; $scope.hasErrors = false; @@ -30,22 +37,26 @@ angular.module('readiness-check', []) $scope.version = { visible: false, processed: false, - expanded: false + expanded: false, + isRequestError: false }; $scope.settings = { visible: false, processed: false, - expanded: false + expanded: false, + isRequestError: false }; $scope.extensions = { visible: false, processed: false, - expanded: false + expanded: false, + isRequestError: false }; $scope.permissions = { visible: false, processed: false, - expanded: false + expanded: false, + isRequestError: false }; $scope.items = { @@ -60,6 +71,9 @@ angular.module('readiness-check', []) angular.extend($scope.version, data); $scope.updateOnProcessed($scope.version.responseType); $scope.stopProgress(); + }, + fail: function() { + $scope.requestFailedHandler($scope.version); } }, 'php-settings': { @@ -73,6 +87,9 @@ angular.module('readiness-check', []) angular.extend($scope.settings, data); $scope.updateOnProcessed($scope.settings.responseType); $scope.stopProgress(); + }, + fail: function() { + $scope.requestFailedHandler($scope.settings); } }, 'php-extensions': { @@ -86,6 +103,9 @@ angular.module('readiness-check', []) angular.extend($scope.extensions, data); $scope.updateOnProcessed($scope.extensions.responseType); $scope.stopProgress(); + }, + fail: function() { + $scope.requestFailedHandler($scope.extensions); } }, 'file-permissions': { @@ -99,6 +119,9 @@ angular.module('readiness-check', []) angular.extend($scope.permissions, data); $scope.updateOnProcessed($scope.permissions.responseType); $scope.stopProgress(); + }, + fail: function() { + $scope.requestFailedHandler($scope.permissions); } } }; @@ -134,8 +157,11 @@ angular.module('readiness-check', []) }; $scope.query = function(item) { - return $http.get(item.url) - .success(function(data) { item.process(data) }); + return $http.get(item.url, {timeout: 3000}) + .success(function(data) { item.process(data) }) + .error(function(data, status) { + item.fail(); + }); }; $scope.progress = function() { diff --git a/setup/view/magento/setup/readiness-check/progress.phtml b/setup/view/magento/setup/readiness-check/progress.phtml index 38f17626b0349..ae1f6acaa1dd9 100644 --- a/setup/view/magento/setup/readiness-check/progress.phtml +++ b/setup/view/magento/setup/readiness-check/progress.phtml @@ -67,17 +67,22 @@

PHP Version Check

-

- Your PHP version is {{version.data.current}}. The required PHP version is {{version.data.required}}. - - Show detail - Hide detail - -

-

- Download and install PHP version {{version.data.required}} from www.php.net using this PHP Documentation. -

-

If you need more help please call your hosting provider.

+
+

Server failed to respond. Please try again.

+
+
+

+ Your PHP version is {{version.data.current}}. The required PHP version is {{version.data.required}}. + + Show detail + Hide detail + +

+

+ Download and install PHP version {{version.data.required}} from www.php.net using this PHP Documentation. +

+

If you need more help please call your hosting provider.

+
@@ -110,17 +115,22 @@
-

PHP Settings Check

+
+

PHP Settings Check

-
-
-

Need Help?

- PHP Documentation +
+

Server failed to respond. Please try again.

-
-

- {{setting.message}} -

+
+
+

Need Help?

+ PHP Documentation +
+
+

+ {{setting.message}} +

+
@@ -178,32 +188,37 @@

PHP Extensions Check

-

- {{extensions.data.missing.length}} missing PHP extensions. - - Show detail - Hide detail - -

-

- The best way to resolve this is to install the correct missing extensions. The exact fix depends on our server, your host, and other system variables. -
- Our PHP Extension Help can get you started. -

-

- If you need more help, please call your hosting provider. -

-
    -
  • - - - PHP Extension {{name}}. -
  • -
+
+

Server failed to respond. Please try again.

+
+
+

+ {{extensions.data.missing.length}} missing PHP extensions. + + Show detail + Hide detail + +

+

+ The best way to resolve this is to install the correct missing extensions. The exact fix depends on our server, your host, and other system variables. +
+ Our PHP Extension Help can get you started. +

+

+ If you need more help, please call your hosting provider. +

+
    +
  • + + + PHP Extension {{name}}. +
  • +
+
@@ -256,32 +271,37 @@

File Permission Check

-

- {{permissions.data.required.length - permissions.data.current.length}} file permission not met. - - Show detail - Hide detail - -

-

- The best way to resolve this is to allow write permissions for the following Magento directories. The exact fix depends on your server, your host, and other system variables. -
- Our File Permission Help can get you started. -

-

- If you need more help, please call your hosting provider. -

+
+

Server failed to respond. Please try again.

+
+
+

+ {{permissions.data.required.length - permissions.data.current.length}} file permission not met. + + Show detail + Hide detail + +

+

+ The best way to resolve this is to allow write permissions for the following Magento directories. The exact fix depends on your server, your host, and other system variables. +
+ Our File Permission Help can get you started. +

+

+ If you need more help, please call your hosting provider. +

-
    -
  • - - - "{{name}}" writable directory permission. -
  • -
+
    +
  • + + + "{{name}}" writable directory permission. +
  • +
+
From e5f1a51d5dab2f3f67a49dd1677f8c109244eb36 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Tue, 23 Jun 2015 15:27:04 -0500 Subject: [PATCH 18/22] MAGETWO-38974: Base-url placeholder - Implemented a check for the {{base_url}} placeholder --- .../Setup/Console/Command/InstallStoreConfigurationCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php index 425ed23f6e179..2837e078a3e51 100644 --- a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php @@ -178,6 +178,9 @@ public function validate(InputInterface $input) switch ($key) { case StoreConfigurationDataMapper::KEY_BASE_URL: /** @var Validator $url */ + if (strcmp($value, '{{base_url}}') == 0) { + break; + } $url = $this->objectManager->get('Magento\Framework\Url\Validator'); if (!$url->isValid($value)) { $errorMsgs = $url->getMessages(); From bae9a0738a216360f4c7048b2a970fb54424c093 Mon Sep 17 00:00:00 2001 From: Fred Sung Date: Tue, 23 Jun 2015 17:38:20 -0500 Subject: [PATCH 19/22] MAGETWO-38402: Stuck in readiness check when PHP setting checking timeout - Added missing semicolon. --- setup/pub/magento/setup/readiness-check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pub/magento/setup/readiness-check.js b/setup/pub/magento/setup/readiness-check.js index 1b421e191b8e2..840fe52343831 100644 --- a/setup/pub/magento/setup/readiness-check.js +++ b/setup/pub/magento/setup/readiness-check.js @@ -29,7 +29,7 @@ angular.module('readiness-check', []) $scope.hasErrors = true; $rootScope.hasErrors = true; $scope.stopProgress(); - } + }; $scope.completed = false; $scope.hasErrors = false; From 2c667a932129533a7d7fe1e85b03a2c0104d825c Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Fri, 26 Jun 2015 09:20:43 -0500 Subject: [PATCH 20/22] MAGETWO-38383: Increase Unit Test Code Coverage - Added missing parameter type - Changed class variables to local variables - Fixed tests to properly test methods' actions --- .../Fixtures/CartPriceRulesFixtureTest.php | 13 ++++ .../Fixtures/CatalogPriceRulesFixtureTest.php | 13 ++++ .../Unit/Fixtures/CategoriesFixtureTest.php | 13 ++++ .../Unit/Fixtures/ConfigsApplyFixtureTest.php | 12 ++++ .../ConfigurableProductsFixtureTest.php | 14 ++++ .../Unit/Fixtures/CustomersFixtureTest.php | 14 ++++ .../Fixtures/EavVariationsFixtureTest.php | 13 ++++ .../Test/Unit/Fixtures/FixtureModelTest.php | 2 +- .../IndexersStatesApplyFixtureTest.php | 12 ++++ .../Test/Unit/Fixtures/OrdersFixtureTest.php | 72 +++++++++++++------ .../Fixtures/SimpleProductsFixtureTest.php | 14 ++++ .../Test/Unit/Fixtures/StoresFixtureTest.php | 18 +++++ .../Unit/Fixtures/TaxRatesFixtureTest.php | 18 +++++ 13 files changed, 205 insertions(+), 23 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index a8a129f48cda9..54d8046c80dff 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -109,6 +109,19 @@ public function testExecute() public function testNoFixtureConfigValue() { + $ruleMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); + $ruleMock->expects($this->never())->method('save'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('get') + ->with($this->equalTo('Magento\SalesRule\Model\Rule')) + ->willReturn($ruleMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php index 06e6c9502c59f..be8a7f156a43c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php @@ -104,6 +104,19 @@ public function testExecute() public function testNoFixtureConfigValue() { + $ruleMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); + $ruleMock->expects($this->never())->method('save'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('get') + ->with($this->equalTo('Magento\SalesRule\Model\Rule')) + ->willReturn($ruleMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php index 96b1a6f55ec03..30d4bb4e8737c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php @@ -121,6 +121,19 @@ public function testExecute() public function testNoFixtureConfigValue() { + $categoryMock = $this->getMock('\Magento\Catalog\Model\Category', [], [], '', false); + $categoryMock->expects($this->never())->method('save'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\Catalog\Model\Category')) + ->willReturn($categoryMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php index 22bff7a8bd2cd..93d56f2742b64 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php @@ -52,6 +52,18 @@ public function testExecute() public function testNoFixtureConfigValue() { + $configMock = $this->getMock('\Magento\Framework\App\Config\ValueInterface', [], [], '', false); + $configMock->expects($this->never())->method('save'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->willReturn($configMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php index 8a99a88f4b2c8..f0cd86010b237 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php @@ -108,6 +108,20 @@ public function testExecute() public function testNoFixtureConfigValue() { + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $importMock->expects($this->never())->method('validateSource'); + $importMock->expects($this->never())->method('importSource'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\ImportExport\Model\Import')) + ->willReturn($importMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php index 68ba5651304b6..6761be9e0dbd5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php @@ -77,6 +77,20 @@ public function testExecute() public function testNoFixtureConfigValue() { + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $importMock->expects($this->never())->method('validateSource'); + $importMock->expects($this->never())->method('importSource'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\ImportExport\Model\Import')) + ->willReturn($importMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php index 2854a4d153ec2..3e8e08002842f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php @@ -91,6 +91,19 @@ public function testExecute() public function testNoFixtureConfigValue() { + $attributeMock = $this->getMock('Magento\Catalog\Model\Resource\Eav\Attribute', [], [], '', false); + $attributeMock->expects($this->never())->method('save'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\Catalog\Model\Resource\Eav\Attribute')) + ->willReturn($attributeMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php index 95a290f6f5960..4ac088271bfad 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php @@ -83,7 +83,7 @@ public function testGetValue() * The method is used in FixtureModel. loadConfig in an if statement. By overriding this method we are able to test * both of the possible cases based on the return value of is_readable. * - * @param $filename + * @param string $filename * @return bool */ function is_readable($filename) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php index 5e06aaf61d677..6d31626bc3733 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php @@ -52,6 +52,18 @@ public function testExecute() public function testNoFixtureConfigValue() { + $cacheInterfaceMock = $this->getMock('Magento\Framework\App\CacheInterface', [], [], '', false); + $cacheInterfaceMock->expects($this->never())->method('clean'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('get') + ->willReturn($cacheInterfaceMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php index d97e1085e6eed..2775d218af70e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php @@ -10,23 +10,6 @@ class OrdersFixtureTest extends \PHPUnit_Framework_TestCase { - private $mockObjectNames = [ - 'Magento\Quote\Model\Resource\Quote', - 'Magento\Quote\Model\Resource\Quote\Address', - 'Magento\Quote\Model\Resource\Quote\Item', - 'Magento\Quote\Model\Resource\Quote\Item\Option', - 'Magento\Quote\Model\Resource\Quote\Payment', - 'Magento\Quote\Model\Resource\Quote\Address\Rate', - 'Magento\Reports\Model\Resource\Event', - 'Magento\Sales\Model\Resource\Order', - 'Magento\Sales\Model\Resource\Order\Grid', - 'Magento\Sales\Model\Resource\Order\Item', - 'Magento\Sales\Model\Resource\Order\Payment', - 'Magento\Sales\Model\Resource\Order\Status\History', - '\Magento\Eav\Model\Resource\Entity\Store' - ]; - - private $mockObjects; /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel @@ -51,7 +34,24 @@ public function setUp() */ public function testExecute() { - foreach ($this->mockObjectNames as $mockObjectName) { + $mockObjectNames = [ + 'Magento\Quote\Model\Resource\Quote', + 'Magento\Quote\Model\Resource\Quote\Address', + 'Magento\Quote\Model\Resource\Quote\Item', + 'Magento\Quote\Model\Resource\Quote\Item\Option', + 'Magento\Quote\Model\Resource\Quote\Payment', + 'Magento\Quote\Model\Resource\Quote\Address\Rate', + 'Magento\Reports\Model\Resource\Event', + 'Magento\Sales\Model\Resource\Order', + 'Magento\Sales\Model\Resource\Order\Grid', + 'Magento\Sales\Model\Resource\Order\Item', + 'Magento\Sales\Model\Resource\Order\Payment', + 'Magento\Sales\Model\Resource\Order\Status\History', + '\Magento\Eav\Model\Resource\Entity\Store' + ]; + $mockObjects = []; + + foreach ($mockObjectNames as $mockObjectName) { $mockObject = $this->getMock($mockObjectName, [], [], '', false); $path = explode('\\', $mockObjectName); $name = array_pop($path); @@ -64,7 +64,7 @@ public function testExecute() ->method('getTable') ->willReturn(strtolower($name) . '_table_name'); } - $this->mockObjects[] = [$mockObjectName, $mockObject]; + $mockObjects[] = [$mockObjectName, $mockObject]; } $adapterInterfaceMock = $this->getMockForAbstractClass( @@ -182,7 +182,7 @@ public function testExecute() ->willReturn([1, 1]); array_push( - $this->mockObjects, + $mockObjects, ['Magento\Store\Model\StoreManager', [], $storeManagerMock], ['Magento\Catalog\Model\Category', $categoryMock], ['Magento\Catalog\Model\Product', $productMock], @@ -193,10 +193,10 @@ public function testExecute() $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $objectManagerMock->expects($this->exactly(32)) ->method('get') - ->will($this->returnValueMap($this->mockObjects)); + ->will($this->returnValueMap($mockObjects)); $objectManagerMock->expects($this->exactly(2)) ->method('create') - ->will($this->returnValueMap($this->mockObjects)); + ->will($this->returnValueMap($mockObjects)); $this->fixtureModelMock ->expects($this->once()) @@ -212,6 +212,34 @@ public function testExecute() public function testNoFixtureConfigValue() { + $adapterInterfaceMock = $this->getMockForAbstractClass( + '\Magento\Framework\DB\Adapter\AdapterInterface', + [], + '', + true, + true, + true, + [] + ); + $adapterInterfaceMock->expects($this->never()) + ->method('query'); + + $resourceMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false); + $resourceMock->expects($this->never()) + ->method('getConnection') + ->with($this->equalTo('write')) + ->willReturn($adapterInterfaceMock); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('get') + ->with($this->equalTo('Magento\Framework\App\Resource')) + ->willReturn($resourceMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManagerMock') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php index f26c416848b72..497a60768893c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/SimpleProductsFixtureTest.php @@ -108,6 +108,20 @@ public function testExecute() public function testNoFixtureConfigValue() { + $importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false); + $importMock->expects($this->never())->method('validateSource'); + $importMock->expects($this->never())->method('importSource'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\ImportExport\Model\Import')) + ->willReturn($importMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->will($this->returnValue($objectManagerMock)); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php index 2cec584560505..07cd715489eab 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/StoresFixtureTest.php @@ -138,6 +138,24 @@ public function testExecute() public function testNoFixtureConfigValue() { + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); + $storeMock->expects($this->never())->method('save'); + + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock->expects($this->never()) + ->method('getDefaultStoreView') + ->willReturn($storeMock); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->with($this->equalTo('Magento\Store\Model\StoreManager')) + ->willReturn($storeManagerMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->exactly(3)) ->method('getValue') diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php index 0e1442dc3785f..1b7547afbd5e8 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/TaxRatesFixtureTest.php @@ -72,6 +72,24 @@ public function testExecute() public function testNoFixtureConfigValue() { + $csvImportHandlerMock = $this->getMock( + 'Magento\TaxImportExport\Model\Rate\CsvImportHandler', + [], + [], + '', + false + ); + $csvImportHandlerMock->expects($this->never())->method('importFromCsvFile'); + + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); + $objectManagerMock->expects($this->never()) + ->method('create') + ->willReturn($csvImportHandlerMock); + + $this->fixtureModelMock + ->expects($this->never()) + ->method('getObjectManager') + ->willReturn($objectManagerMock); $this->fixtureModelMock ->expects($this->once()) ->method('getValue') From b8fda57f4021bb91584fb6f17ab54dfcf51d8db6 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Fri, 26 Jun 2015 09:50:37 -0500 Subject: [PATCH 21/22] MAGETWO-38383: Increase Unit Test Code Coverage -Removed unnecessary is_readable check --- setup/src/Magento/Setup/Fixtures/FixtureModel.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/setup/src/Magento/Setup/Fixtures/FixtureModel.php b/setup/src/Magento/Setup/Fixtures/FixtureModel.php index f414e1a2884b3..a51eb57d44e42 100644 --- a/setup/src/Magento/Setup/Fixtures/FixtureModel.php +++ b/setup/src/Magento/Setup/Fixtures/FixtureModel.php @@ -105,11 +105,6 @@ public function reindex(OutputInterface $output) */ public function loadFixtures() { - if (!is_readable(__DIR__)) { - throw new \Exception( - 'Fixtures set directory `' . __DIR__ . '` is not readable or does not exists.' - ); - } $files = glob(__DIR__ . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN); foreach ($files as $file) { From 20e1959dd784bd6f7b20e8732a139a8041b6de92 Mon Sep 17 00:00:00 2001 From: Ian Daszkowski Date: Mon, 6 Jul 2015 15:33:28 -0500 Subject: [PATCH 22/22] MAGETWO-39478: Contribution Task -Fixed unit test --- .../Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php index 54d8046c80dff..fc6914f44ad5a 100644 --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -132,7 +132,7 @@ public function testNoFixtureConfigValue() public function testGetActionTitle() { - $this->assertSame('Generating shopping cart price rules', $this->model->getActionTitle()); + $this->assertSame('Generating Cart Price Rules', $this->model->getActionTitle()); } public function testIntroduceParamLabels()