Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseCollection.php
Go to the documentation of this file.
1 <?php
7 
16 class BaseCollection extends \PHPUnit\Framework\TestCase
17 {
23  protected function getStoreManager()
24  {
25  $store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
26  ->setMethods(['getId'])
27  ->disableOriginalConstructor()
28  ->getMock();
29  $store->expects($this->once())
30  ->method('getId')
31  ->willReturn(1);
32 
33  $storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
34  ->setMethods(['getStore'])
35  ->disableOriginalConstructor()
36  ->getMockForAbstractClass();
37  $storeManager->expects($this->once())
38  ->method('getStore')
39  ->willReturn($store);
40 
41  return $storeManager;
42  }
43 
49  protected function getUniversalFactory()
50  {
51  $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
52  ->disableOriginalConstructor()
53  ->setMethods(['select'])
54  ->getMockForAbstractClass();
55  $select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $connection->expects($this->any())->method('select')->willReturn($select);
59 
60  $entity = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
61  ->setMethods(['getConnection', 'getTable', 'getDefaultAttributes', 'getEntityTable'])
62  ->disableOriginalConstructor()
63  ->getMock();
64  $entity->expects($this->once())
65  ->method('getConnection')
66  ->willReturn($connection);
67  $entity->expects($this->exactly(2))
68  ->method('getTable')
69  ->willReturnArgument(0);
70  $entity->expects($this->once())
71  ->method('getDefaultAttributes')
72  ->willReturn(['attr1', 'attr2']);
73  $entity->expects($this->once())
74  ->method('getEntityTable')
75  ->willReturn('table');
76 
77  $universalFactory = $this->getMockBuilder(\Magento\Framework\Validator\UniversalFactory::class)
78  ->setMethods(['create'])
79  ->disableOriginalConstructor()
80  ->getMock();
81  $universalFactory->expects($this->once())
82  ->method('create')
83  ->willReturn($entity);
84 
85  return $universalFactory;
86  }
87 }
$storeManager
$entity
Definition: element.phtml:22
$connection
Definition: bulk.php:13