/** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return Migration */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { if ($serviceLocator instanceof AbstractPluginManager) { $serviceLocator = $serviceLocator->getServiceLocator(); } $config = $serviceLocator->get('Config'); preg_match(self::FACTORY_PATTERN, $name, $matches) || preg_match(self::FACTORY_PATTERN, $requestedName, $matches); $name = $matches[1]; if (!isset($config['migrations'][$name])) { throw new RuntimeException(sprintf("`%s` does not exist in migrations configuration", $name)); } $migration_config = $config['migrations'][$name]; $adapter_name = isset($migration_config['adapter']) ? $migration_config['adapter'] : 'Zend\\Db\\Adapter\\Adapter'; /** @var $adapter \Zend\Db\Adapter\Adapter */ $adapter = $serviceLocator->get($adapter_name); $output = null; if (isset($migration_config['show_log']) && $migration_config['show_log']) { $console = $serviceLocator->get('console'); $output = new OutputWriter(function ($message) use($console) { $console->write($message . "\n"); }); } /** @var MigrationVersionTable $version_table */ $version_table = $serviceLocator->get('migrations.versiontable.' . $adapter_name); $migration = new Migration($adapter, $migration_config, $version_table, $output); $migration->setServiceLocator($serviceLocator); return $migration; }
/** * @expectedException \ZfSimpleMigrations\Library\MigrationException */ public function test_multi_statement_error_detection() { $this->markTestSkipped('need to implement driver specific features & test if this driver supports multi-row functionality'); try { $this->migration->migrate('02'); } catch (\Exception $e) { $this->migration->migrate('02', true, true); $this->assertEquals('ZfSimpleMigrations\\Library\\MigrationException', get_class($e)); return; } $this->fail(sprintf('expected exception %s', '\\ZfSimpleMigrations\\Library\\MigrationException')); }