engineResolverMock = $this->getMockBuilder(EngineResolverInterface::class) ->getMockForAbstractClass(); $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); $this->model = new ClientResolver( $this->objectManager, ['engineName' => 'engineFactoryClass'], ['engineName' => 'engineOptionClass'], $this->engineResolverMock ); } public function testCreate(): void { $this->engineResolverMock->expects($this->once())->method('getCurrentSearchEngine') ->willReturn('engineName'); $factoryMock = $this->getMockForAbstractClass(ClientFactoryInterface::class); $clientMock = $this->getMockForAbstractClass(ClientInterface::class); $clientOptionsMock = $this->getMockForAbstractClass(ClientOptionsInterface::class); $this->objectManager->expects($this->exactly(2))->method('create') ->willReturnCallback(function ($className) use ($factoryMock, $clientOptionsMock) { if ($className == 'engineFactoryClass') { return $factoryMock; } elseif ($className == 'engineOptionClass') { return $clientOptionsMock; } }); $clientOptionsMock->expects($this->once())->method('prepareClientOptions') ->with([]) ->willReturn(['parameters']); $factoryMock->expects($this->once())->method('create') ->with(['parameters']) ->willReturn($clientMock); $result = $this->model->create(); $this->assertInstanceOf(ClientInterface::class, $result); } public function testCreateExceptionThrown(): void { $this->expectException(InvalidArgumentException::class); $this->objectManager->expects($this->once())->method('create') ->with('engineFactoryClass') ->willReturn('t'); $this->model->create('engineName'); } public function testCreateLogicException(): void { $this->expectException(LogicException::class); $this->model->create('input'); } public function testGetCurrentEngine(): void { $this->engineResolverMock->expects($this->once())->method('getCurrentSearchEngine') ->willReturn('engineName'); $this->assertEquals('engineName', $this->model->getCurrentEngine()); } }