DiscountsTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Test\Unit\Model\Rss;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. /**
  9. * Class DiscountsTest
  10. * @package Magento\SalesRule\Model\Rss
  11. */
  12. class DiscountsTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\SalesRule\Model\Rss\Discounts
  16. */
  17. protected $discounts;
  18. /**
  19. * @var ObjectManagerHelper
  20. */
  21. protected $objectManagerHelper;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $collectionFactory;
  26. protected function setUp()
  27. {
  28. $this->collectionFactory = $this->createPartialMock(
  29. \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory::class,
  30. ['create']
  31. );
  32. $this->objectManagerHelper = new ObjectManagerHelper($this);
  33. $this->discounts = $this->objectManagerHelper->getObject(
  34. \Magento\SalesRule\Model\Rss\Discounts::class,
  35. [
  36. 'collectionFactory' => $this->collectionFactory
  37. ]
  38. );
  39. }
  40. public function testGetDiscountCollection()
  41. {
  42. $ruleCollection = $this->createPartialMock(\Magento\SalesRule\Model\ResourceModel\Rule\Collection::class, [
  43. 'addWebsiteGroupDateFilter',
  44. 'addFieldToFilter',
  45. 'setOrder',
  46. 'load'
  47. ]);
  48. $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCollection));
  49. $ruleCollection->expects($this->once())->method('addWebsiteGroupDateFilter')->will($this->returnSelf());
  50. $ruleCollection->expects($this->once())->method('addFieldToFilter')->will($this->returnSelf());
  51. $ruleCollection->expects($this->once())->method('setOrder')->will($this->returnSelf());
  52. $ruleCollection->expects($this->once())->method('load')->will($this->returnSelf());
  53. $this->assertEquals($ruleCollection, $this->discounts->getDiscountCollection(1, 1));
  54. }
  55. }