'mockSql', NewSqlOntology::OPTION_READABLE_MODELS => [2,3], NewSqlOntology::OPTION_WRITEABLE_MODELS => [2], NewSqlOntology::OPTION_NEW_TRIPLE_MODEL => 2, ]); return $this->setupOntology($model); } /** * @return core_kernel_persistence_smoothsql_SmoothModel */ protected function getOntologyMock() { $model = new core_kernel_persistence_smoothsql_SmoothModel([ core_kernel_persistence_smoothsql_SmoothModel::OPTION_PERSISTENCE => 'mockSql', core_kernel_persistence_smoothsql_SmoothModel::OPTION_READABLE_MODELS => [2,3], core_kernel_persistence_smoothsql_SmoothModel::OPTION_WRITEABLE_MODELS => [2], core_kernel_persistence_smoothsql_SmoothModel::OPTION_NEW_TRIPLE_MODEL => 2, ]); return $this->setupOntology($model); } /** * @return Ontology */ private function setupOntology(Ontology $onto) { $eventAggregator = new EventAggregator(['numberOfAggregatedEvents' => 10]); $persistenceManagerWithSqlMock = $this->getPersistenceManagerWithSqlMock('mockSql'); $session = new \common_session_AnonymousSession(); $serviceLocatorMock = $this->getServiceLocatorMock([ Ontology::SERVICE_ID => $onto, PersistenceManager::SERVICE_ID => $persistenceManagerWithSqlMock, UserLanguageServiceInterface::SERVICE_ID => $this->getUserLanguageServiceMock('xx_XX'), SessionService::SERVICE_ID => $this->getSessionServiceMock($session), EventManager::SERVICE_ID => new EventManager(), LoggerService::SERVICE_ID => $this->prophesize(LoggerInterface::class)->reveal(), UriProvider::SERVICE_ID => new Bin2HexUriProvider([Bin2HexUriProvider::OPTION_NAMESPACE => 'http://ontology.mock/bin2hex#']), SimpleCache::SERVICE_ID => new NoCache(), DriverConfigurationFeeder::SERVICE_ID => new DriverConfigurationFeeder(), EventAggregator::SERVICE_ID => $eventAggregator ]); $eventAggregator->setServiceLocator($serviceLocatorMock); $session->setServiceLocator($serviceLocatorMock); $onto->setServiceLocator($serviceLocatorMock); $persistenceManagerWithSqlMock->setServiceLocator($serviceLocatorMock); // setup schema $schemas = $persistenceManagerWithSqlMock->getSqlSchemas(); if ($onto instanceof SchemaProviderInterface) { $onto->provideSchema($schemas); } $persistenceManagerWithSqlMock->applySchemas($schemas); return $onto; } /** * @param string $sqlId * @return PersistenceManager */ protected function getPersistenceManagerWithSqlMock($sqlId) { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('sqlite not found, tests skipped.'); } $pm = new PersistenceManager([ PersistenceManager::OPTION_PERSISTENCES => [ $sqlId => [ 'driver' => 'dbal', 'connection' => [ 'url' => 'sqlite:///:memory:' ] ] ] ]); return $pm; } /** * @param common_session_Session $session * @return SessionService */ protected function getSessionServiceMock(common_session_Session $session) { $prophet = $this->prophesize(SessionService::class); $prophet->getCurrentUser()->willReturn($session->getUser()); $prophet->getCurrentSession()->willReturn($session); return $prophet->reveal(); } /** * @param string $lang * @return UserLanguageServiceInterface */ protected function getUserLanguageServiceMock($lang = 'en_US') { $prophet = $this->prophesize(UserLanguageServiceInterface::class); $prophet->getDefaultLanguage()->willReturn($lang); $prophet->getInterfaceLanguage(Argument::any())->willReturn($lang); return $prophet->reveal(); } }