dataProvider = $this->getMockBuilder(SuggestedQueriesInterface::class) ->disableOriginalConstructor() ->setMethods(['getItems', 'isResultsCountEnabled']) ->getMockForAbstractClass(); $this->searchQueryMock = $this->getMockBuilder(QueryInterface::class) ->disableOriginalConstructor() ->setMethods(['getQueryText']) ->getMockForAbstractClass(); $this->queryFactoryMock = $this->getMockBuilder(QueryFactoryInterface::class) ->disableOriginalConstructor() ->setMethods(['get']) ->getMockForAbstractClass(); $this->queryFactoryMock->expects($this->once()) ->method('get') ->willReturn($this->searchQueryMock); $this->contextMock = $this->getMockBuilder(TemplateContext::class) ->disableOriginalConstructor() ->getMock(); $this->block = $this->getMockBuilder(SearchData::class) ->setConstructorArgs( [ $this->contextMock, $this->dataProvider, $this->queryFactoryMock, 'Test Title', [], ] ) ->setMethods(['getUrl']) ->getMockForAbstractClass(); } public function testGetSuggestions(): void { $value = [1, 2, 3, 100500]; $this->dataProvider->expects($this->once()) ->method('getItems') ->with($this->searchQueryMock) ->willReturn($value); $actualValue = $this->block->getItems(); $this->assertEquals($value, $actualValue); } public function testGetLink(): void { $searchQueryMock = 'Some test search query'; $expectedResult = '?q=Some+test+search+query'; $actualResult = $this->block->getLink($searchQueryMock); $this->assertEquals($expectedResult, $actualResult); } public function testIsShowResultsCount(): void { $value = 'qwertyasdfzxcv'; $this->dataProvider->expects($this->once()) ->method('isResultsCountEnabled') ->willReturn($value); $this->assertEquals($value, $this->block->isShowResultsCount()); } }