Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ClientResolverTest.php
Go to the documentation of this file.
1 <?php
8 
15 
16 class ClientResolverTest extends \PHPUnit\Framework\TestCase
17 {
21  private $model;
22 
26  private $objectManager;
27 
31  private $engineResolverMock;
32 
33  protected function setUp()
34  {
35  $this->engineResolverMock = $this->getMockBuilder(EngineResolverInterface::class)
36  ->getMockForAbstractClass();
37 
38  $this->objectManager = $this->createMock(ObjectManagerInterface::class);
39 
40  $this->model = new ClientResolver(
41  $this->objectManager,
42  ['engineName' => 'engineFactoryClass'],
43  ['engineName' => 'engineOptionClass'],
44  $this->engineResolverMock
45  );
46  }
47 
48  public function testCreate()
49  {
50  $this->engineResolverMock->expects($this->once())->method('getCurrentSearchEngine')
51  ->will($this->returnValue('engineName'));
52 
53  $factoryMock = $this->createMock(ClientFactoryInterface::class);
54 
55  $clientMock = $this->createMock(ClientInterface::class);
56 
57  $clientOptionsMock = $this->createMock(ClientOptionsInterface::class);
58 
59  $this->objectManager->expects($this->exactly(2))->method('create')
60  ->withConsecutive(
61  [$this->equalTo('engineFactoryClass')],
62  [$this->equalTo('engineOptionClass')]
63  )
64  ->willReturnOnConsecutiveCalls(
65  $factoryMock,
66  $clientOptionsMock
67  );
68 
69  $clientOptionsMock->expects($this->once())->method('prepareClientOptions')
70  ->with([])
71  ->will($this->returnValue(['parameters']));
72 
73  $factoryMock->expects($this->once())->method('create')
74  ->with($this->equalTo(['parameters']))
75  ->will($this->returnValue($clientMock));
76 
77  $result = $this->model->create();
78  $this->assertInstanceOf(ClientInterface::class, $result);
79  }
80 
84  public function testCreateExceptionThrown()
85  {
86  $this->objectManager->expects($this->once())->method('create')
87  ->with($this->equalTo('engineFactoryClass'))
88  ->will($this->returnValue('t'));
89 
90  $this->model->create('engineName');
91  }
92 
96  public function testCreateLogicException()
97  {
98  $this->model->create('input');
99  }
100 
101  public function testGetCurrentEngine()
102  {
103  $this->engineResolverMock->expects($this->once())->method('getCurrentSearchEngine')
104  ->will($this->returnValue('engineName'));
105 
106  $this->assertEquals('engineName', $this->model->getCurrentEngine());
107  }
108 }