searchEngineMock = $this->createMock(Search::class); $this->ontology = $this->createMock(Ontology::class); $this->subject = new GenerisSearchBridge(); $this->subject->withLocalNamespace(self::LOCAL_NAMESPACE); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ Search::SERVICE_ID => $this->searchEngineMock, Ontology::SERVICE_ID => $this->ontology, ] ) ); } public function testSearch(): void { $query = new SearchQuery( 'user input', 'rootClass', 'parentClass', 1, 10, 1 ); $resultSetMock = $this->createMock(ResultSet::class); $this->searchEngineMock ->expects($this->once()) ->method('query') ->with( 'user input', 'parentClass', 1, 10 ) ->willReturn($resultSetMock); $result = $this->subject->search($query); $this->assertEquals($resultSetMock, $result); } public function testSearchByUri(): void { $uri = self::LOCAL_NAMESPACE; $label = 'My Resource label'; $query = new SearchQuery( $uri, 'rootClass', 'parentClass', 1, 10, 1 ); $resultSetMock = new ResultSet( [ [ 'id' => $uri, 'label' => $label, ], ], 1 ); $resource = $this->createMock(core_kernel_classes_Resource::class); $class = $this->createMock(core_kernel_classes_Class::class); $this->ontology ->method('getResource') ->willReturn($resource); $this->ontology ->method('getClass') ->willReturn($class); $resource ->method('exists') ->willReturn(true); $resource ->method('isInstanceOf') ->willReturn(true); $resource ->method('getUri') ->willReturn($uri); $resource ->method('getLabel') ->willReturn($label); $result = $this->subject->search($query); $this->assertEquals($resultSetMock, $result); } }