set(ExtensionsManager::SERVICE_ID, $this->getExtensionManagerMock()); $config->set(MigrationsService::SERVICE_ID, $this->getMigrationsServiceMock()); $config->set(PersistenceManager::SERVICE_ID, $this->getSqlMock('unittest')); $config->set(Ontology::SERVICE_ID, $this->getOntologyMock()); $config->set(AssetService::SERVICE_ID, new AssetService()); $config->set('generis/log', new LoggerService([])); $config->set('generis/event', new EventManager()); if (!defined('ROOT_PATH')) { define('ROOT_PATH', ''); } $updater = new UpdateExtensions(); $updater->setServiceLocator(ServiceManager::getServiceManager()); $report = $updater([]); $this->assertInstanceOf(Report::class, $report); $reports = $report->getChildren(); $this->assertCount(6, $reports); $this->assertEquals('foo already up to date', $reports[0]->getMessage()); $this->assertEquals('bar already up to date', $reports[1]->getMessage()); $this->assertEquals('Migrations applied', $reports[2]->getMessage()); } private function getOntologyMock() { $classImplementation = $this->createMock(ClassImplementation::class); /** @var RdfsInterface|MockObject $rdfsInterface */ $rdfsInterface = $this->createConfiguredMock( RdfsInterface::class, ['getClassImplementation' => $classImplementation] ); $ontologyMock = $this->createMock(Ontology::class); $ontologyMock->method('getResource') ->willReturn(new \core_kernel_classes_Resource('foo')); $ontologyMock->method('getRdfsInterface') ->willReturn($rdfsInterface); return $ontologyMock; } private function getMigrationsServiceMock() { $migrationsService = $this->getMockBuilder(MigrationsService::class) ->disableOriginalConstructor() ->getMock(); $migrationsService->method('migrate') ->willReturn(new Report(Report::TYPE_SUCCESS, 'Migrations applied')); return $migrationsService; } private function getExtensionManagerMock() { $fooManifest = $this->getMockBuilder(Manifest::class)->disableOriginalConstructor() ->getMock(); $fooManifest->method('getDependencies') ->willReturn([]); $extensionFoo = $this->getMockBuilder(Extension::class) ->disableOriginalConstructor() ->getMock(); $extensionFoo->method('getId') ->willReturn('foo'); $extensionFoo->method('getName') ->willReturn('foo'); $extensionFoo->method('getDependencies') ->willReturn([]); $extensionFoo->method('getManifest') ->willReturn($fooManifest); $extensionFoo->method('getDir') ->willReturn(dirname(dirname(dirname(__DIR__)))); $barManifest = $this->getMockBuilder(Manifest::class)->disableOriginalConstructor() ->getMock(); $barManifest->method('getDependencies') ->willReturn([]); $extensionBar = $this->getMockBuilder(Extension::class) ->disableOriginalConstructor() ->getMock(); $extensionBar->method('getId') ->willReturn('bar'); $extensionBar->method('getName') ->willReturn('bar'); $extensionBar->method('getDependencies') ->willReturn(['foo' => '*']); $extensionBar->method('getManifest') ->willReturn($barManifest); $extensionBar->method('getDir') ->willReturn(dirname(dirname(dirname(__DIR__)))); $extensionsManagerMock = $this->getMockBuilder(ExtensionsManager::class) ->getMock(); $extensionsManagerMock->method('isInstalled')->willReturn(true); $extensionsManagerMock->method('getInstalledExtensions') ->willReturn([ 'bar' => $extensionBar, 'foo' => $extensionFoo, ]); $extensionsManagerMock->method('getExtensionById') ->willReturnMap([ ['bar', $extensionBar], ['foo', $extensionFoo], ]); return $extensionsManagerMock; } }