indexIterator = $this->createMock(IndexIteratorFactory::class); $this->sut = new UpdateClassInIndex( $this->indexIterator ); $this->search = $this->createMock(Search::class); $this->logger = $this->createMock(LoggerInterface::class); $serviceLocator = $this->getServiceLocatorMock( [ Search::SERVICE_ID => $this->search, LoggerService::SERVICE_ID => $this->logger ] ); $this->sut->setServiceLocator($serviceLocator); } public function testTaskThereIsNoResourcesToIndex(): void { $indexIterator = $this->createMock(IndexIterator::class); $this->indexIterator->expects($this->once()) ->method('create') ->willReturn( $indexIterator ); $this->search->expects($this->once()) ->method('index') ->with($indexIterator) ->willReturn(0); $this->logger->expects($this->once()) ->method('info') ->with('0 resources have been indexed by oat\tao\model\search\tasks\UpdateClassInIndex'); $report = $this->sut->__invoke( ['https://tao.docker.localhost/ontologies/tao.rdf#i5f478159bc6a0794b51ee1a7f8cf0a4c'] ); $this->assertInstanceOf(Report::class, $report); $this->assertEquals('Zero documents were added/updated in index.', $report->getMessage()); $this->assertEquals(Report::TYPE_INFO, $report->getType()); } public function testTaskThereIsResourcesToIndex(): void { $indexIterator = $this->createMock(IndexIterator::class); $this->indexIterator->expects($this->once()) ->method('create') ->willReturn( $indexIterator ); $this->search->expects($this->once()) ->method('index') ->with($indexIterator) ->willReturn(5); $this->logger->expects($this->once()) ->method('info') ->with('5 resources have been indexed by oat\tao\model\search\tasks\UpdateClassInIndex'); $report = $this->sut->__invoke( ['https://tao.docker.localhost/ontologies/tao.rdf#i5f478159bc6a0794b51ee1a7f8cf0a4c'] ); $this->assertInstanceOf(Report::class, $report); $this->assertEquals('Documents in index were successfully updated.', $report->getMessage()); $this->assertEquals(Report::TYPE_SUCCESS, $report->getType()); } /** * @dataProvider provideInvalidParameters * * @param mixed $parameter * * @throws common_exception_MissingParameter * */ public function testTaskInvalidInvokableParameters($parameter): void { $this->expectException(common_exception_MissingParameter::class); $this->sut->__invoke( $parameter ); } public function provideInvalidParameters(): array { return [ 'Empty Array' => [ [] ], 'String' => [ '' ], 'Null' => [ null ], ]; } }