Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractIndexerCommandCommonSetup.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class AbstractIndexerCommandCommonSetup extends \PHPUnit\Framework\TestCase
13 {
17  protected $configLoaderMock;
18 
22  protected $indexerFactory;
23 
27  protected $stateMock;
28 
32  protected $collectionFactory;
33 
38 
42  protected $objectManager;
43 
48 
49  protected function setUp()
50  {
51  $this->objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class);
52  $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
53  $this->objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager);
54 
55  $this->stateMock = $this->createMock(\Magento\Framework\App\State::class);
56  $this->configLoaderMock = $this->createMock(\Magento\Framework\App\ObjectManager\ConfigLoader::class);
57 
58  $this->collectionFactory = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\CollectionFactory::class)
59  ->disableOriginalConstructor()
60  ->setMethods(['create'])
61  ->getMock();
62 
63  $this->indexerCollectionMock = $this->getMockBuilder(Collection::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66 
67  $this->collectionFactory
68  ->method('create')
69  ->willReturn($this->indexerCollectionMock);
70 
71  $this->indexerFactory = $this->getMockBuilder(\Magento\Framework\Indexer\IndexerInterfaceFactory::class)
72  ->disableOriginalConstructor()
73  ->setMethods(['create'])
74  ->getMock();
75 
76  $this->objectManager->expects($this->any())
77  ->method('get')
78  ->will(
79  $this->returnValueMap(
80  array_merge(
82  [
83  [\Magento\Indexer\Model\Indexer\CollectionFactory::class, $this->collectionFactory],
84  [\Magento\Framework\Indexer\IndexerInterfaceFactory::class, $this->indexerFactory],
85  ]
86  )
87  )
88  );
89  }
90 
96  protected function getObjectManagerReturnValueMap()
97  {
98  return [
99  [\Magento\Framework\App\State::class, $this->stateMock],
100  [\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $this->configLoaderMock]
101  ];
102  }
103 
104  protected function configureAdminArea()
105  {
106  $config = ['test config'];
107  $this->configLoaderMock->expects($this->once())
108  ->method('load')
110  ->will($this->returnValue($config));
111  $this->objectManager->expects($this->once())
112  ->method('configure')
113  ->with($config);
114  $this->stateMock->expects($this->once())
115  ->method('setAreaCode')
117  }
118 
124  protected function getIndexerMock(array $methods = [], array $data = [])
125  {
127  $indexer = $this->getMockBuilder(IndexerInterface::class)
128  ->setMethods(array_merge($methods, ['getId', 'getTitle']))
129  ->getMockForAbstractClass();
130  $indexer->method('getId')
131  ->willReturn($data['indexer_id'] ?? '');
132  $indexer->method('getTitle')
133  ->willReturn($data['title'] ?? '');
134  return $indexer;
135  }
136 
143  protected function initIndexerCollectionByItems(array $items)
144  {
145  $this->indexerCollectionMock
146  ->method('getItems')
147  ->with()
148  ->willReturn($items);
149  }
150 }
$config
Definition: fraud_order.php:17
$methods
Definition: billing.phtml:71
$items