Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductLoaderTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
17 class ProductLoaderTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $productLoader;
23 
27  private $productRepository;
28 
32  private $searchCriteriaBuilder;
33 
37  private $productSearchResultsInterface;
38 
42  private $searchCriteria;
43 
47  protected $product;
48 
54  protected function setUp()
55  {
56  $this->productRepository = $this->getMockBuilder(ProductRepositoryInterface::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59  $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62  $this->productSearchResultsInterface = $this->getMockBuilder(ProductSearchResultsInterface::class)
63  ->disableOriginalConstructor()
64  ->getMockForAbstractClass();
65  $this->searchCriteria = $this->getMockBuilder(SearchCriteria::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68  $this->product = $this->getMockBuilder(Product::class)
69  ->disableOriginalConstructor()
70  ->getMock();
71 
72  $this->productLoader = new ProductLoader(
73  $this->productRepository,
74  $this->searchCriteriaBuilder
75  );
76  }
77 
78  public function testGetProducts()
79  {
80  $this->searchCriteriaBuilder->expects($this->once())
81  ->method('addFilter')
82  ->willReturnSelf();
83  $this->searchCriteriaBuilder->expects($this->once())
84  ->method('create')
85  ->willReturn($this->searchCriteria);
86  $this->productRepository->expects($this->once())
87  ->method('getList')
88  ->with($this->searchCriteria)
89  ->willReturn($this->productSearchResultsInterface);
91  $this->productSearchResultsInterface->expects($this->once())
92  ->method('getItems')
93  ->willReturn($iterator);
94 
95  $this->assertSame($iterator, $this->productLoader->getProducts([1]));
96  }
97 }