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; }
/** * @dataProvider provider */ public function testRun($command, $result) { $app = new \Phinx\Console\PhinxApplication('testing'); $app->setAutoExit(false); // Set autoExit to false when testing $app->setCatchExceptions(false); $appTester = new ApplicationTester($app); $appTester->run(array('command' => $command)); $stream = $appTester->getOutput()->getStream(); rewind($stream); $this->assertRegExp($result, stream_get_contents($stream)); }