PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/magento2-base/setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 262 lines | 239 code | 9 blank | 14 comment | 0 complexity | 5bb532807b1a87ad0aab7613f4db31b0 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Test\Unit\Fixtures;
  7. use \Magento\Setup\Fixtures\OrdersFixture;
  8. class OrdersFixtureTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel
  12. */
  13. private $fixtureModelMock;
  14. /**
  15. * @var \Magento\Setup\Fixtures\OrdersFixture
  16. */
  17. private $model;
  18. public function setUp()
  19. {
  20. $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false);
  21. $this->model = new OrdersFixture($this->fixtureModelMock);
  22. }
  23. /**
  24. *
  25. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  26. */
  27. public function testExecute()
  28. {
  29. $mockObjectNames = [
  30. 'Magento\Quote\Model\ResourceModel\Quote',
  31. 'Magento\Quote\Model\ResourceModel\Quote\Address',
  32. 'Magento\Quote\Model\ResourceModel\Quote\Item',
  33. 'Magento\Quote\Model\ResourceModel\Quote\Item\Option',
  34. 'Magento\Quote\Model\ResourceModel\Quote\Payment',
  35. 'Magento\Quote\Model\ResourceModel\Quote\Address\Rate',
  36. 'Magento\Reports\Model\ResourceModel\Event',
  37. 'Magento\Sales\Model\ResourceModel\Order',
  38. 'Magento\Sales\Model\ResourceModel\Order\Grid',
  39. 'Magento\Sales\Model\ResourceModel\Order\Item',
  40. 'Magento\Sales\Model\ResourceModel\Order\Payment',
  41. 'Magento\Sales\Model\ResourceModel\Order\Status\History',
  42. '\Magento\Eav\Model\ResourceModel\Entity\Store'
  43. ];
  44. $mockObjects = [];
  45. foreach ($mockObjectNames as $mockObjectName) {
  46. $mockObject = $this->getMock($mockObjectName, ['getTable'], [], '', false);
  47. $path = explode('\\', $mockObjectName);
  48. $name = array_pop($path);
  49. if (strcasecmp($mockObjectName, 'Magento\Sales\Model\ResourceModel\Order') == 0) {
  50. $mockObject->expects($this->exactly(2))
  51. ->method('getTable')
  52. ->willReturn(strtolower($name) . '_table_name');
  53. } else {
  54. $mockObject->expects($this->once())
  55. ->method('getTable')
  56. ->willReturn(strtolower($name) . '_table_name');
  57. }
  58. $mockObjects[] = [$mockObjectName, $mockObject];
  59. }
  60. $connectionInterfaceMock = $this->getMockForAbstractClass(
  61. '\Magento\Framework\DB\Adapter\AdapterInterface',
  62. [],
  63. '',
  64. true,
  65. true,
  66. true,
  67. []
  68. );
  69. $connectionInterfaceMock->expects($this->exactly(14))
  70. ->method('getTableName')
  71. ->willReturn('table_name');
  72. $resourceMock = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
  73. $resourceMock->expects($this->exactly(15))
  74. ->method('getConnection')
  75. ->willReturn($connectionInterfaceMock);
  76. $websiteMock = $this->getMock('\Magento\Store\Model\Website', ['getId', 'getName'], [], '', false);
  77. $websiteMock->expects($this->once())
  78. ->method('getId')
  79. ->willReturn('website_id');
  80. $websiteMock->expects($this->once())
  81. ->method('getName')
  82. ->willReturn('website_name');
  83. $groupMock = $this->getMock('\Magento\Store\Model\Group', ['getName'], [], '', false);
  84. $groupMock->expects($this->once())
  85. ->method('getName')
  86. ->willReturn('group_name');
  87. $storeMock = $this->getMock(
  88. '\Magento\Store\Model\Store',
  89. [
  90. 'getStoreId',
  91. 'getWebsite',
  92. 'getGroup',
  93. 'getName',
  94. 'getRootCategoryId'
  95. ],
  96. [],
  97. '',
  98. false
  99. );
  100. $storeMock->expects($this->once())
  101. ->method('getStoreId')
  102. ->willReturn(1);
  103. $storeMock->expects($this->exactly(2))
  104. ->method('getWebsite')
  105. ->willReturn($websiteMock);
  106. $storeMock->expects($this->once())
  107. ->method('getGroup')
  108. ->willReturn($groupMock);
  109. $storeMock->expects($this->once())
  110. ->method('getName')
  111. ->willReturn('store_name');
  112. $storeMock->expects($this->once())
  113. ->method('getRootCategoryId')
  114. ->willReturn(1);
  115. $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false);
  116. $storeManagerMock->expects($this->once())
  117. ->method('getStores')
  118. ->willReturn([$storeMock]);
  119. $contextMock = $this->getMock('\Magento\Framework\Model\ResourceModel\Db\Context', [], [], '', false);
  120. $abstractDbMock = $this->getMockForAbstractClass(
  121. '\Magento\Framework\Model\ResourceModel\Db\AbstractDb',
  122. [$contextMock],
  123. '',
  124. true,
  125. true,
  126. true,
  127. ['getAllChildren']
  128. );
  129. $abstractDbMock->expects($this->once())
  130. ->method('getAllChildren')
  131. ->will($this->returnValue([1]));
  132. $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false);
  133. $categoryMock->expects($this->once())
  134. ->method('getResource')
  135. ->willReturn($abstractDbMock);
  136. $categoryMock->expects($this->once())
  137. ->method('getPath')
  138. ->willReturn('path/to/category');
  139. $categoryMock->expects($this->exactly(2))
  140. ->method('getName')
  141. ->willReturn('category_name');
  142. $categoryMock->expects($this->exactly(5))
  143. ->method('load')
  144. ->willReturnSelf();
  145. $productMock = $this->getMock('\Magento\Catalog\Model\Product', ['load', 'getSku', 'getName'], [], '', false);
  146. $productMock->expects($this->exactly(2))
  147. ->method('load')
  148. ->willReturnSelf();
  149. $productMock->expects($this->exactly(2))
  150. ->method('getSku')
  151. ->willReturn('product_sku');
  152. $productMock->expects($this->exactly(2))
  153. ->method('getName')
  154. ->willReturn('product_name');
  155. $selectMock = $this->getMock('\Magento\Framework\DB\Select', [], [], '', false);
  156. $collectionMock = $this->getMock('\Magento\Catalog\Model\ResourceModel\Product\Collection', [], [], '', false);
  157. $collectionMock->expects($this->once())
  158. ->method('getSelect')
  159. ->willReturn($selectMock);
  160. $collectionMock->expects($this->once())
  161. ->method('getAllIds')
  162. ->willReturn([1, 1]);
  163. array_push(
  164. $mockObjects,
  165. ['Magento\Store\Model\StoreManager', [], $storeManagerMock],
  166. ['Magento\Catalog\Model\Category', $categoryMock],
  167. ['Magento\Catalog\Model\Product', $productMock],
  168. ['Magento\Framework\App\ResourceConnection', $resourceMock],
  169. ['Magento\Catalog\Model\ResourceModel\Product\Collection', [], $collectionMock]
  170. );
  171. $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
  172. $objectManagerMock->expects($this->exactly(32))
  173. ->method('get')
  174. ->will($this->returnValueMap($mockObjects));
  175. $objectManagerMock->expects($this->exactly(2))
  176. ->method('create')
  177. ->will($this->returnValueMap($mockObjects));
  178. $this->fixtureModelMock
  179. ->expects($this->once())
  180. ->method('getValue')
  181. ->willReturn(1);
  182. $this->fixtureModelMock
  183. ->expects($this->exactly(34))
  184. ->method('getObjectManager')
  185. ->willReturn($objectManagerMock);
  186. $this->model->execute();
  187. }
  188. public function testNoFixtureConfigValue()
  189. {
  190. $connectionMock = $this->getMockForAbstractClass(
  191. '\Magento\Framework\DB\Adapter\AdapterInterface',
  192. [],
  193. '',
  194. true,
  195. true,
  196. true,
  197. []
  198. );
  199. $connectionMock->expects($this->never())
  200. ->method('query');
  201. $resourceMock = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
  202. $resourceMock->expects($this->never())
  203. ->method('getConnection')
  204. ->with($this->equalTo('write'))
  205. ->willReturn($connectionMock);
  206. $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
  207. $objectManagerMock->expects($this->never())
  208. ->method('get')
  209. ->with($this->equalTo('Magento\Framework\App\ResourceConnection'))
  210. ->willReturn($resourceMock);
  211. $this->fixtureModelMock
  212. ->expects($this->never())
  213. ->method('getObjectManagerMock')
  214. ->willReturn($objectManagerMock);
  215. $this->fixtureModelMock
  216. ->expects($this->once())
  217. ->method('getValue')
  218. ->willReturn(false);
  219. $this->model->execute();
  220. }
  221. public function testGetActionTitle()
  222. {
  223. $this->assertSame('Generating orders', $this->model->getActionTitle());
  224. }
  225. public function testIntroduceParamLabels()
  226. {
  227. $this->assertSame([
  228. 'orders' => 'Orders'
  229. ], $this->model->introduceParamLabels());
  230. }
  231. }