Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexSwitcherProxyTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class IndexSwitcherProxyTest extends \PHPUnit\Framework\TestCase
14 {
16  private $model;
17 
19  private $objectManagerMock;
20 
22  private $engineResolverMock;
23 
24  protected function setUp()
25  {
26  $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
27  ->getMockForAbstractClass();
28  $this->engineResolverMock = $this->getMockBuilder(EngineResolverInterface::class)
29  ->getMockForAbstractClass();
30  }
31 
32  public function testSwitchIndex()
33  {
34  $currentHandler = 'current_handler';
35  $currentHandlerClass = IndexSwitcherInterface::class;
36  $handles = [
37  $currentHandler => $currentHandlerClass,
38  ];
39  $dimensions = ['dimension'];
40 
41  $this->engineResolverMock->expects($this->once())
42  ->method('getCurrentSearchEngine')
43  ->willReturn($currentHandler);
44 
45  $indexSwitcherMock = $this->getMockBuilder($currentHandlerClass)
46  ->getMockForAbstractClass();
47 
48  $this->objectManagerMock->expects($this->once())
49  ->method('create')
50  ->with($currentHandlerClass)
51  ->willReturn($indexSwitcherMock);
52 
53  $indexSwitcherMock->expects($this->once())
54  ->method('switchIndex')
55  ->with($dimensions);
56 
57  $this->model = new IndexSwitcherProxy(
58  $this->objectManagerMock,
59  $this->engineResolverMock,
60  $handles
61  );
62 
63  $this->model->switchIndex($dimensions);
64  }
65 
67  {
68  $currentHandler = 'current_handler';
69  $handles = [];
70  $dimensions = ['dimension'];
71 
72  $this->engineResolverMock->expects($this->once())
73  ->method('getCurrentSearchEngine')
74  ->willReturn($currentHandler);
75 
76  $this->objectManagerMock->expects($this->never())
77  ->method('create');
78 
79  $this->model = new IndexSwitcherProxy(
80  $this->objectManagerMock,
81  $this->engineResolverMock,
82  $handles
83  );
84 
85  $this->model->switchIndex($dimensions);
86  }
87 
93  {
94  $currentHandler = 'current_handler';
95  $currentHandlerClass = \stdClass::class;
96  $handles = [
97  $currentHandler => $currentHandlerClass,
98  ];
99  $dimensions = ['dimension'];
100 
101  $this->engineResolverMock->expects($this->once())
102  ->method('getCurrentSearchEngine')
103  ->willReturn($currentHandler);
104 
105  $indexSwitcherMock = $this->getMockBuilder($currentHandlerClass)
106  ->getMockForAbstractClass();
107 
108  $this->objectManagerMock->expects($this->once())
109  ->method('create')
110  ->with($currentHandlerClass)
111  ->willReturn($indexSwitcherMock);
112 
113  $this->model = new IndexSwitcherProxy(
114  $this->objectManagerMock,
115  $this->engineResolverMock,
116  $handles
117  );
118 
119  $this->model->switchIndex($dimensions);
120  }
121 }