Ejemplo n.º 1
0
 /**
  * @expectedException              \InvalidArgumentException
  * @expectedExceptionMessageRegExp /The file "(.*)" already exists/
  */
 public function testThrowsExceptionWhenConfigFilePresent()
 {
     touch(sys_get_temp_dir() . '/phinx.yml');
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new Init());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('init');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'path' => sys_get_temp_dir()), array('decorated' => false));
 }
Ejemplo n.º 2
0
 protected function migrate()
 {
     $input = new ArgvInput(['phinx', 'migrate', '--environment=memory']);
     $output = new NullOutput();
     $phinx = new Phinx\Console\PhinxApplication();
     $phinx->setAutoExit(false);
     $phinx->run($input, $output);
     /** @var Migrate $migrateCommand */
     $migrateCommand = $phinx->get('migrate');
     $adapter = $migrateCommand->getManager()->getEnvironment('memory')->getAdapter();
     /** @var PDO $pdo */
     $this->phinxPdo = $adapter->getConnection();
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The seed class name "badseedname" is invalid. Please use CamelCase format
  */
 public function testExecuteWithInvalidClassName()
 {
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new SeedCreate());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('seed:create');
     // mock the manager class
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $output));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'name' => 'badseedname'), array('decorated' => false));
 }
Ejemplo n.º 4
0
 public function testDatabaseNameSpecified()
 {
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new Rollback());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('rollback');
     // mock the manager class
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $output));
     $managerStub->expects($this->once())->method('rollback');
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName()));
     $this->assertRegExp('/using database development/', $commandTester->getDisplay());
 }
Ejemplo n.º 5
0
 public function testFormatSpecified()
 {
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new Status());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('status');
     // mock the manager class
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $output));
     $managerStub->expects($this->once())->method('printStatus');
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--format' => 'json'));
     $this->assertRegExp('/using format json/', $commandTester->getDisplay());
 }
Ejemplo n.º 6
0
 public function testExecuteMultipleSeeders()
 {
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new SeedRun());
     // setup dependencies
     $input = new ArrayInput([]);
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('seed:run');
     // mock the manager class
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $input, $output));
     $managerStub->expects($this->exactly(3))->method('seed')->withConsecutive(array($this->identicalTo('development'), $this->identicalTo('One')), array($this->identicalTo('development'), $this->identicalTo('Two')), array($this->identicalTo('development'), $this->identicalTo('Three')));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--seed' => ['One', 'Two', 'Three']), array('decorated' => false));
     $this->assertRegExp('/no environment specified/', $commandTester->getDisplay());
 }
Ejemplo n.º 7
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The migration class name "MyDuplicateMigration" already exists
  */
 public function testExecuteWithDuplicateMigrationNames()
 {
     $application = new \Phinx\Console\PhinxApplication('testing');
     $application->add(new Create());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('create');
     // mock the manager class
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $output));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'name' => 'MyDuplicateMigration'));
     sleep(1.01);
     // need at least a second due to file naming scheme
     $commandTester->execute(array('command' => $command->getName(), 'name' => 'MyDuplicateMigration'));
 }
Ejemplo n.º 8
0
 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 \Phinx\Console\PhinxApplication('0.3.7');
     $app->setAutoExit(false);
     $app->run(null, $output);
 }
Ejemplo n.º 9
0
$_SERVER['PHINX_MIGRATIONS_DIR'] = $mageRoot . 'app/code/local/Elite/migrations';
$_SERVER['PHINX_HOST'] = $dbinfo['host'];
$_SERVER['PHINX_USER'] = $dbinfo['username'];
$_SERVER['PHINX_PASSWORD'] = $dbinfo['password'];
$_SERVER['PHINX_DBNAME'] = $dbinfo['dbname'];
$_SERVER['PHINX_PORT'] = 3306;
use Symfony\Component\Console\Output\Output;
file_put_contents($mageRoot . 'var/vf-upgrade-progress.txt', '');
chmod($mageRoot . 'var/vf-upgrade-progress.txt', 0777);
class BufferedOutput extends Output
{
    protected $buffer;
    public function doWrite($message, $newline)
    {
        global $mageRoot;
        $h = fopen($mageRoot . 'var/vf-upgrade-progress.txt', 'a');
        fwrite($h, $message . ($newline ? PHP_EOL : ''));
        $this->buffer .= $message . ($newline ? PHP_EOL : '');
    }
    public function getBuffer()
    {
        return $this->buffer;
    }
}
ini_set('display_errors', 1);
error_reporting(E_ALL);
$input = new \Symfony\Component\Console\Input\StringInput('migrate -c ' . $mageRoot . 'app/code/local/Elite/phinx.yml -e main');
$output = new BufferedOutput();
$app = new Phinx\Console\PhinxApplication('0.2.8');
$app->setAutoExit(false);
$app->run($input, $output);