CounterTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\NewRelicReporting\Test\Unit\Model;
  7. use Magento\NewRelicReporting\Model\Counter;
  8. use Magento\Catalog\Api\ProductManagementInterface;
  9. use Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface;
  10. use Magento\Catalog\Api\CategoryManagementInterface;
  11. use Magento\Customer\Api\CustomerManagementInterface;
  12. use Magento\Store\Api\WebsiteManagementInterface;
  13. use Magento\Store\Api\StoreManagementInterface;
  14. /**
  15. * Class CounterTest
  16. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  17. */
  18. class CounterTest extends \PHPUnit\Framework\TestCase
  19. {
  20. /**
  21. * @var \Magento\NewRelicReporting\Model\Counter
  22. */
  23. protected $model;
  24. /**
  25. * @var ProductManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $productManagement;
  28. /**
  29. * @var ConfigurableProductManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $configurableManagement;
  32. /**
  33. * @var CategoryManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $categoryManagement;
  36. /**
  37. * @var CustomerManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  38. */
  39. protected $customerManagement;
  40. /**
  41. * @var WebsiteManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  42. */
  43. protected $websiteManagement;
  44. /**
  45. * @var StoreManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  46. */
  47. protected $storeManagement;
  48. /**
  49. * Setup
  50. *
  51. * @return void
  52. */
  53. protected function setUp()
  54. {
  55. $this->productManagement = $this->getMockBuilder(\Magento\Catalog\Api\ProductManagementInterface::class)
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->configurableManagement = $this
  59. ->getMockBuilder(\Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface::class)
  60. ->disableOriginalConstructor()
  61. ->getMock();
  62. $this->categoryManagement = $this->getMockBuilder(\Magento\Catalog\Api\CategoryManagementInterface::class)
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $this->customerManagement = $this->getMockBuilder(\Magento\Customer\Api\CustomerManagementInterface::class)
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $this->websiteManagement = $this->getMockBuilder(\Magento\Store\Api\WebsiteManagementInterface::class)
  69. ->disableOriginalConstructor()
  70. ->getMock();
  71. $this->storeManagement = $this->getMockBuilder(\Magento\Store\Api\StoreManagementInterface::class)
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $this->model = new Counter(
  75. $this->productManagement,
  76. $this->configurableManagement,
  77. $this->categoryManagement,
  78. $this->customerManagement,
  79. $this->websiteManagement,
  80. $this->storeManagement
  81. );
  82. }
  83. /**
  84. * Tests all products count will return int
  85. *
  86. * @return void
  87. */
  88. public function testGetAllProductsCount()
  89. {
  90. $this->productManagement->expects($this->once())
  91. ->method('getCount')
  92. ->willReturn(1);
  93. $this->assertInternalType(
  94. 'int',
  95. $this->model->getAllProductsCount()
  96. );
  97. }
  98. /**
  99. * Tests all configurable products count will return int
  100. *
  101. * @return void
  102. */
  103. public function testGetConfigurableCount()
  104. {
  105. $this->configurableManagement->expects($this->once())
  106. ->method('getCount')
  107. ->willReturn(1);
  108. $this->assertInternalType(
  109. 'int',
  110. $this->model->getConfigurableCount()
  111. );
  112. }
  113. /**
  114. * Tests all active products count will return int
  115. *
  116. * @return void
  117. */
  118. public function testGetActiveCatalogSize()
  119. {
  120. $this->productManagement->expects($this->once())
  121. ->method('getCount')
  122. ->with(1)
  123. ->willReturn(1);
  124. $this->assertInternalType(
  125. 'int',
  126. $this->model->getActiveCatalogSize()
  127. );
  128. }
  129. /**
  130. * Tests categories count will return int
  131. *
  132. * @return void
  133. */
  134. public function testGetCategoryCount()
  135. {
  136. $this->categoryManagement->expects($this->once())
  137. ->method('getCount')
  138. ->willReturn(1);
  139. $this->assertInternalType(
  140. 'int',
  141. $this->model->getCategoryCount()
  142. );
  143. }
  144. /**
  145. * Tests customers count will return int
  146. *
  147. * @return void
  148. */
  149. public function testGetCustomerCount()
  150. {
  151. $this->customerManagement->expects($this->once())
  152. ->method('getCount')
  153. ->willReturn(1);
  154. $this->assertInternalType(
  155. 'int',
  156. $this->model->getCustomerCount()
  157. );
  158. }
  159. /**
  160. * Tests websites count will return int
  161. *
  162. * @return void
  163. */
  164. public function testGetWebsiteCount()
  165. {
  166. $this->websiteManagement->expects($this->once())
  167. ->method('getCount')
  168. ->willReturn(1);
  169. $this->assertInternalType(
  170. 'int',
  171. $this->model->getWebsiteCount()
  172. );
  173. }
  174. /**
  175. * Tests stores count will return int
  176. *
  177. * @return void
  178. */
  179. public function testGetStoreViewsCount()
  180. {
  181. $this->storeManagement->expects($this->once())
  182. ->method('getCount')
  183. ->willReturn(1);
  184. $this->assertInternalType(
  185. 'int',
  186. $this->model->getStoreViewsCount()
  187. );
  188. }
  189. }