HelperTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\ResourceModel;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. /**
  9. * Class HelperTest
  10. */
  11. class HelperTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $resourceHelper;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $appResource;
  21. /**
  22. * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $connectionMock;
  25. /**
  26. * @var \Magento\Sales\Model\ResourceModel\Helper
  27. */
  28. private $helper;
  29. /**
  30. * Initialization
  31. */
  32. protected function setUp()
  33. {
  34. $objectManager = new ObjectManagerHelper($this);
  35. $this->appResource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  36. $this->resourceHelper = $this->createMock(\Magento\Reports\Model\ResourceModel\Helper::class);
  37. $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
  38. $this->helper = $objectManager->getObject(
  39. \Magento\Sales\Model\ResourceModel\Helper::class,
  40. [
  41. 'resource' => $this->appResource,
  42. 'reportsResourceHelper' => $this->resourceHelper
  43. ]
  44. );
  45. }
  46. /**
  47. * @param string $aggregation
  48. * @param array $aggregationAliases
  49. * @param string $expectedType
  50. *
  51. * @dataProvider getBestsellersReportUpdateRatingPosProvider
  52. */
  53. public function testGetBestsellersReportUpdateRatingPos($aggregation, $aggregationAliases, $expectedType)
  54. {
  55. $mainTable = 'main_table';
  56. $aggregationTable = 'aggregation_table';
  57. $this->resourceHelper->expects($this->once())->method('updateReportRatingPos')->with(
  58. $this->connectionMock,
  59. $expectedType,
  60. 'qty_ordered',
  61. $mainTable,
  62. $aggregationTable
  63. );
  64. $this->appResource->expects($this->once())
  65. ->method('getConnection')
  66. ->with('sales')
  67. ->willReturn($this->connectionMock);
  68. $this->helper->getBestsellersReportUpdateRatingPos(
  69. $aggregation,
  70. $aggregationAliases,
  71. $mainTable,
  72. $aggregationTable
  73. );
  74. }
  75. /**
  76. * @return array
  77. */
  78. public function getBestsellersReportUpdateRatingPosProvider()
  79. {
  80. return [
  81. ['alias', ['monthly' => 'alias', 'daily' => 'alias2', 'yearly' => 'alias3'], 'month'],
  82. ['alias', ['monthly' => 'alias2', 'daily' => 'alias', 'yearly' => 'alias3'], 'day'],
  83. ['alias', ['monthly' => 'alias2', 'daily' => 'alias2', 'yearly' => 'alias'], 'year'],
  84. ];
  85. }
  86. }