Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RssTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class RssTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $rss;
17 
22 
26  protected $managerInterface;
27 
31  protected $reviewFactory;
32 
33  protected function setUp()
34  {
35  $this->managerInterface = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
36  $this->reviewFactory = $this->createPartialMock(\Magento\Review\Model\ReviewFactory::class, ['create']);
37 
38  $this->objectManagerHelper = new ObjectManagerHelper($this);
39  $this->rss = $this->objectManagerHelper->getObject(
40  \Magento\Review\Model\Rss::class,
41  [
42  'eventManager' => $this->managerInterface,
43  'reviewFactory' => $this->reviewFactory
44  ]
45  );
46  }
47 
48  public function testGetProductCollection()
49  {
50  $reviewModel = $this->createPartialMock(\Magento\Review\Model\Review::class, [
51  '__wakeUp',
52  'getProductCollection'
53  ]);
54  $productCollection = $this->createPartialMock(
55  \Magento\Review\Model\ResourceModel\Review\Product\Collection::class,
56  [
57  'addStatusFilter',
58  'addAttributeToSelect',
59  'setDateOrder'
60  ]
61  );
62  $reviewModel->expects($this->once())->method('getProductCollection')
63  ->will($this->returnValue($productCollection));
64  $this->reviewFactory->expects($this->once())->method('create')->will($this->returnValue($reviewModel));
65  $productCollection->expects($this->once())->method('addStatusFilter')->will($this->returnSelf());
66  $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
67  $productCollection->expects($this->once())->method('setDateOrder')->will($this->returnSelf());
68  $this->managerInterface->expects($this->once())->method('dispatch')->will($this->returnSelf());
69  $this->assertEquals($productCollection, $this->rss->getProductCollection());
70  }
71 }