Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DiscountsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class DiscountsTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $discounts;
20 
25 
29  protected $collectionFactory;
30 
31  protected function setUp()
32  {
33  $this->collectionFactory = $this->createPartialMock(
34  \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory::class,
35  ['create']
36  );
37 
38  $this->objectManagerHelper = new ObjectManagerHelper($this);
39  $this->discounts = $this->objectManagerHelper->getObject(
40  \Magento\SalesRule\Model\Rss\Discounts::class,
41  [
42  'collectionFactory' => $this->collectionFactory
43  ]
44  );
45  }
46 
47  public function testGetDiscountCollection()
48  {
49  $ruleCollection = $this->createPartialMock(\Magento\SalesRule\Model\ResourceModel\Rule\Collection::class, [
50  'addWebsiteGroupDateFilter',
51  'addFieldToFilter',
52  'setOrder',
53  'load'
54  ]);
55  $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCollection));
56  $ruleCollection->expects($this->once())->method('addWebsiteGroupDateFilter')->will($this->returnSelf());
57  $ruleCollection->expects($this->once())->method('addFieldToFilter')->will($this->returnSelf());
58  $ruleCollection->expects($this->once())->method('setOrder')->will($this->returnSelf());
59  $ruleCollection->expects($this->once())->method('load')->will($this->returnSelf());
60  $this->assertEquals($ruleCollection, $this->discounts->getDiscountCollection(1, 1));
61  }
62 }