Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SalableProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class SalableProcessorTest extends \PHPUnit\Framework\TestCase
13 {
14  const STOCK_FLAG = 'has_stock_status_filter';
15 
17  private $objectManager;
18 
20  protected $model;
21 
24 
25  protected function setUp()
26  {
27  $this->objectManager = new ObjectManager($this);
28 
29  $this->stockStatusFactory = $this->getMockBuilder(
30  \Magento\CatalogInventory\Model\ResourceModel\Stock\StatusFactory::class
31  )
32  ->setMethods(['create'])
33  ->disableOriginalConstructor()
34  ->getMock();
35 
36  $this->model = $this->objectManager->getObject(
37  \Magento\ConfigurableProduct\Model\Product\Type\Collection\SalableProcessor::class,
38  [
39  'stockStatusFactory' => $this->stockStatusFactory,
40  ]
41  );
42  }
43 
44  public function testProcess()
45  {
46  $productCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
47  ->setMethods(['addAttributeToFilter'])
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $productCollection->expects($this->once())
52  ->method('addAttributeToFilter')
54  ->will($this->returnSelf());
55 
56  $stockStatusResource = $this->getMockBuilder(\Magento\CatalogInventory\Model\ResourceModel\Stock\Status::class)
57  ->setMethods(['addStockDataToCollection'])
58  ->disableOriginalConstructor()
59  ->getMock();
60  $stockStatusResource->expects($this->once())
61  ->method('addStockDataToCollection')
62  ->with($productCollection, true)
63  ->will($this->returnSelf());
64 
65  $this->stockStatusFactory
66  ->expects($this->once())
67  ->method('create')
68  ->will($this->returnValue($stockStatusResource));
69 
70  $this->model->process($productCollection);
71 
72  $this->assertTrue($productCollection->hasFlag(self::STOCK_FLAG));
73  }
74 }