Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractDataProviderTest.php
Go to the documentation of this file.
1 <?php
7 
15 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
16 
21 abstract class AbstractDataProviderTest extends \PHPUnit\Framework\TestCase
22 {
26  protected $objectManager;
27 
31  protected $requestMock;
32 
37 
42 
46  protected $productMock;
47 
52 
56  protected $collectionMock;
57 
61  abstract protected function getModel();
62 
63  protected function setUp()
64  {
65  $this->objectManager = new ObjectManager($this);
66  $this->requestMock = $this->getMockBuilder(RequestInterface::class)
67  ->getMockForAbstractClass();
68  $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
69  ->getMockForAbstractClass();
70  $this->productLinkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)
71  ->getMockForAbstractClass();
72  $this->productMock = $this->getMockBuilder(ProductInterface::class)
73  ->getMockForAbstractClass();
74  $this->collectionMock = $this->getMockBuilder(Collection::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77  $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
78  ->setMethods(['create'])
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $this->productRepositoryMock->expects($this->any())
83  ->method('getById')
84  ->willReturn($this->productMock);
85  $this->collectionFactoryMock->expects($this->once())
86  ->method('create')
87  ->willReturn($this->collectionMock);
88  }
89 
90  public function testGetCollection()
91  {
92  $this->collectionMock->expects($this->once())
93  ->method('addAttributeToFilter');
94  $this->productLinkRepositoryMock->expects($this->once())
95  ->method('getList')
96  ->willReturn([]);
97  $this->requestMock->expects($this->exactly(2))
98  ->method('getParam')
99  ->willReturn(1);
100 
101  $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
102  }
103 }