public function __call($name, $arguments) { $config_path = Registry::get('config.dir.root') . '/app/Tygh/UpgradeCenter/Migrations/config.migrations.php'; switch ($name) { case 'migrate': $_SERVER['argv'] = array('phinx', 'migrate', '-c' . $config_path, '-edevelopment'); break; case 'rollback': $_SERVER['argv'] = array('phinx', 'rollback', '-c' . $config_path, '-edevelopment'); break; default: return false; } $output = new Output(); $output->setConfig($this->config); $output->setVerbosity(Output::VERBOSITY_VERBOSE); $app = new PhinxApplication('0.4.3'); AdapterFactory::instance()->registerAdapter('mysqli', '\\Tygh\\UpgradeCenter\\Phinx\\MysqliAdapter'); $app->setAutoExit(false); $app->setCatchExceptions(false); try { $exit_code = $app->run(null, $output); } catch (\Exception $e) { // Convert PDOException to DatabaseException if (class_exists('\\PDOException') && $e instanceof \PDOException) { throw new DatabaseException($e->getMessage(), $e->getCode(), $e); } else { throw $e; } } return $exit_code === 0; }
public function testGetAdapterWithExistingPdoInstance() { $adapter = $this->getMockForAbstractClass('\\Phinx\\Db\\Adapter\\PdoAdapter', array(array('foo' => 'bar'))); AdapterFactory::instance()->registerAdapter('pdomock', $adapter); $this->environment->setOptions(array('connection' => new PDOMock())); $options = $this->environment->getAdapter()->getOptions(); $this->assertEquals('pdomock', $options['adapter']); }
public function __call($name, $arguments) { $config_path = Registry::get('config.dir.root') . '/app/Tygh/UpgradeCenter/Migrations/config.migrations.php'; switch ($name) { case 'migrate': $_SERVER['argv'] = array('phinx', 'migrate', '-c' . $config_path, '-edevelopment'); break; case 'rollback': $_SERVER['argv'] = array('phinx', 'rollback', '-c' . $config_path, '-edevelopment'); break; default: return false; } $output = new Output(); $output->setConfig($this->config); $app = new PhinxApplication('0.4.3'); AdapterFactory::instance()->registerAdapter('mysqli', '\\Tygh\\UpgradeCenter\\Phinx\\MysqliAdapter'); $app->setAutoExit(false); $app->run(null, $output); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Wrapper "nope" has not been registered */ public function testGetWrapperFailure() { $this->factory->getWrapper('nope', $this->getAdapterMock()); }
public function setUp() { $this->factory = AdapterFactory::instance(); }
/** * Gets the database adapter. * * @return AdapterInterface */ public function getAdapter() { if (isset($this->adapter)) { return $this->adapter; } if (isset($this->options['connection'])) { if (!$this->options['connection'] instanceof \PDO) { throw new \RuntimeException('The specified connection is not a PDO instance'); } $this->options['adapter'] = $this->options['connection']->getAttribute(\PDO::ATTR_DRIVER_NAME); } if (!isset($this->options['adapter'])) { throw new \RuntimeException('No adapter was specified for environment: ' . $this->getName()); } $adapter = AdapterFactory::instance()->getAdapter($this->options['adapter'], $this->options); if (isset($this->options['wrapper'])) { $adapter = AdapterFactory::instance()->getWrapper($this->options['wrapper'], $adapter); } if ($this->getOutput()) { $adapter->setOutput($this->getOutput()); } // Use the TablePrefixAdapter if table prefix/suffixes are in use if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) { $adapter = AdapterFactory::instance()->getWrapper('prefix', $adapter); } $this->setAdapter($adapter); return $adapter; }
/** * Get database adapter. * * @param array $options * @return \Phinx\Db\Adapter\AdapterInterface */ protected function _setAdapter(array $options) { $adapterFactory = AdapterFactory::instance(); return $adapterFactory->getAdapter($this->_adapterName, $options); }
/** * Get table adapter instance * * @access public * @return \Phinx\Db\Adapter\AdapterInterface */ public function getAdapter() { // PDO Instance $pdo = $this->getConnection()->getPDO(); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $adapterOptions = $this->options + ['connection' => $pdo, 'name' => $this->getDatabaseName()]; $adapterDrive = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); return AdapterFactory::instance()->getAdapter($adapterDrive, $adapterOptions); }
/** * Registers a test adapter * * @param string $className * * @return void */ private function registerTestAdapter($className) { AdapterFactory::instance()->registerAdapter('test', $className); }