PageRenderTime 208ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/module-new-relic-reporting/Test/Unit/Model/Cron/ReportCountsTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 197 lines | 128 code | 18 blank | 51 comment | 0 complexity | 5d030758f5964be43e4b67b48dbd0d77 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\NewRelicReporting\Test\Unit\Model\Cron;
  7. use Magento\NewRelicReporting\Model\Cron\ReportCounts;
  8. use Magento\Catalog\Api\ProductManagementInterface;
  9. use Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface;
  10. use Magento\Catalog\Api\CategoryManagementInterface;
  11. /**
  12. * Class ReportCountsTest
  13. *
  14. * @codingStandardsIgnoreFile
  15. */
  16. class ReportCountsTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @var ReportCounts
  20. */
  21. protected $model;
  22. /**
  23. * @var \Magento\NewRelicReporting\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $configMock;
  26. /**
  27. * @var ProductManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $productManagementMock;
  30. /**
  31. * @var ConfigurableProductManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. protected $configurableManagementMock;
  34. /**
  35. * @var CategoryManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  36. */
  37. protected $categoryManagementMock;
  38. /**
  39. * @var \Magento\NewRelicReporting\Model\CountsFactory|\PHPUnit_Framework_MockObject_MockObject
  40. */
  41. protected $countsFactoryMock;
  42. /**
  43. * @var \Magento\NewRelicReporting\Model\Counts|\PHPUnit_Framework_MockObject_MockObject
  44. */
  45. protected $countsModelMock;
  46. /**
  47. * @var \Magento\NewRelicReporting\Model\ResourceModel\Counts\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
  48. */
  49. protected $countsCollectionFactoryMock;
  50. /**
  51. * @var \Magento\NewRelicReporting\Model\ResourceModel\Counts\Collection|\PHPUnit_Framework_MockObject_MockObject
  52. */
  53. protected $countsCollectionMock;
  54. /**
  55. * Setup
  56. *
  57. * @return void
  58. */
  59. public function setUp()
  60. {
  61. $this->configMock = $this->getMockBuilder('Magento\NewRelicReporting\Model\Config')
  62. ->disableOriginalConstructor()
  63. ->setMethods(['isNewRelicEnabled'])
  64. ->getMock();
  65. $this->productManagementMock = $this->getMockBuilder('Magento\Catalog\Api\ProductManagementInterface')
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $this->configurableManagementMock = $this
  69. ->getMockBuilder('Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface')
  70. ->disableOriginalConstructor()
  71. ->getMock();
  72. $this->categoryManagementMock = $this->getMockBuilder('Magento\Catalog\Api\CategoryManagementInterface')
  73. ->disableOriginalConstructor()
  74. ->getMock();
  75. $this->countsFactoryMock = $this->getMockBuilder('Magento\NewRelicReporting\Model\CountsFactory')
  76. ->disableOriginalConstructor()
  77. ->setMethods(['create'])
  78. ->getMock();
  79. $this->countsModelMock = $this->getMockBuilder('Magento\NewRelicReporting\Model\Counts')
  80. ->disableOriginalConstructor()
  81. ->getMock();
  82. $this->countsCollectionFactoryMock = $this
  83. ->getMockBuilder('Magento\NewRelicReporting\Model\ResourceModel\Counts\CollectionFactory')
  84. ->disableOriginalConstructor()
  85. ->setMethods(['create'])
  86. ->getMock();
  87. $collectionClassName = 'Magento\NewRelicReporting\Model\ResourceModel\Counts\Collection';
  88. $this->countsCollectionMock = $this->getMockBuilder($collectionClassName)
  89. ->disableOriginalConstructor()
  90. ->setMethods(['addFieldToFilter', 'addOrder', 'setPageSize', 'getFirstItem'])
  91. ->getMock();
  92. $this->countsFactoryMock->expects($this->any())
  93. ->method('create')
  94. ->willReturn($this->countsModelMock);
  95. $this->countsModelMock->expects($this->any())
  96. ->method('load')
  97. ->willReturnSelf();
  98. $this->countsCollectionFactoryMock->expects($this->any())
  99. ->method('create')
  100. ->willReturn($this->countsCollectionMock);
  101. $this->countsCollectionMock->expects($this->any())
  102. ->method('addFieldToFilter')
  103. ->willReturnSelf();
  104. $this->countsCollectionMock->expects($this->any())
  105. ->method('addOrder')
  106. ->willReturnSelf();
  107. $this->countsCollectionMock->expects($this->any())
  108. ->method('setPageSize')
  109. ->willReturnSelf();
  110. $this->countsCollectionMock->expects($this->any())
  111. ->method('getFirstItem')
  112. ->willReturn($this->countsModelMock);
  113. $this->model = new ReportCounts(
  114. $this->configMock,
  115. $this->productManagementMock,
  116. $this->configurableManagementMock,
  117. $this->categoryManagementMock,
  118. $this->countsFactoryMock,
  119. $this->countsCollectionFactoryMock
  120. );
  121. }
  122. /**
  123. * Test case when module is disabled in config
  124. *
  125. * @return void
  126. */
  127. public function testReportCountsTestsModuleDisabledFromConfig()
  128. {
  129. $this->configMock->expects($this->once())
  130. ->method('isNewRelicEnabled')
  131. ->willReturn(false);
  132. $this->assertSame(
  133. $this->model,
  134. $this->model->report()
  135. );
  136. }
  137. /**
  138. * Test case when module is enabled
  139. *
  140. * @return void
  141. */
  142. public function testReportCountsTest()
  143. {
  144. $this->configMock->expects($this->once())
  145. ->method('isNewRelicEnabled')
  146. ->willReturn(true);
  147. $this->productManagementMock->expects($this->exactly(2))
  148. ->method('getCount')
  149. ->willReturn(2);
  150. $this->configurableManagementMock->expects($this->once())
  151. ->method('getCount')
  152. ->willReturn(2);
  153. $this->categoryManagementMock->expects($this->once())
  154. ->method('getCount')
  155. ->willReturn(2);
  156. $this->countsModelMock->expects($this->any())
  157. ->method('getCount')
  158. ->willReturn(1);
  159. $this->countsModelMock->expects($this->any())
  160. ->method('setEntityId')
  161. ->willReturnSelf();
  162. $this->countsModelMock->expects($this->any())
  163. ->method('setType')
  164. ->willReturnSelf();
  165. $this->countsModelMock->expects($this->any())
  166. ->method('setCount')
  167. ->willReturnSelf();
  168. $this->countsModelMock->expects($this->any())
  169. ->method('setUpdatedAt')
  170. ->willReturnSelf();
  171. $this->countsModelMock->expects($this->any())
  172. ->method('save')
  173. ->willReturnSelf();
  174. $this->assertSame(
  175. $this->model,
  176. $this->model->report()
  177. );
  178. }
  179. }