Example #1
0
 /**
  * Verify configuration file
  *
  * @param  InputInterface            $input
  * @param  OutputInterface           $output
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadManager($input, $output);
     $this->verifyMigrationDirectory($this->getConfig()->getMigrationPath());
     $envName = $input->getOption('environment');
     if ($envName) {
         if (!$this->getConfig()->hasEnvironment($envName)) {
             throw new \InvalidArgumentException(sprintf('The environment "%s" does not exist', $envName));
         }
         $output->writeln(sprintf('<info>validating environment</info> %s', $envName));
         $environment = new Environment($envName, $this->getConfig()->getEnvironment($envName));
         // validate environment connection
         $environment->getAdapter()->connect();
     }
     $output->writeln('<info>success!</info>');
 }
Example #2
0
 public function testRenameColumn()
 {
     $time = time();
     $this->environment->executeMigration(new InitialMigration($time - 1), MigrationInterface::UP);
     $this->assertNotEmpty($this->adapter->fetchAll("SELECT * FROM ponies WHERE name IS NOT NULL"));
     $this->environment->executeMigration(new RenameMigration($time), MigrationInterface::UP);
     $this->assertEmpty($this->adapter->fetchAll("SELECT * FROM ponies WHERE first_name IS NULL"));
 }
 public function testExecutingAChangeMigrationDown()
 {
     // stub adapter
     $adapterStub = $this->getMock('\\Phinx\\Db\\Adapter\\PdoAdapter', array(), array(array()));
     $adapterStub->expects($this->once())->method('migrated')->will($this->returnArgument(0));
     $this->environment->setAdapter($adapterStub);
     // migration
     $migration = $this->getMock('\\Phinx\\Migration\\AbstractMigration', array('change'), array('20130301080000'));
     $migration->expects($this->once())->method('change');
     $this->environment->executeMigration($migration, MigrationInterface::DOWN);
 }
Example #4
0
 /**
  * Gets the manager class for the given environment.
  *
  * @param string $name Environment Name
  * @throws \InvalidArgumentException
  * @return Environment
  */
 public function getEnvironment($name)
 {
     if (isset($this->environments[$name])) {
         return $this->environments[$name];
     }
     // check the environment exists
     if (!$this->getConfig()->hasEnvironment($name)) {
         throw new \InvalidArgumentException(sprintf('The environment "%s" does not exist', $name));
     }
     // create an environment instance and cache it
     $environment = new Environment($name, $this->getConfig()->getEnvironment($name));
     $this->environments[$name] = $environment;
     $environment->setOutput($this->getOutput());
     return $environment;
 }
Example #5
0
 /**
  * @dataProvider badAdapterProvider
  * @expectedException \RuntimeException
  */
 public function testBadAdapterFactories($adapterName, $adapter)
 {
     $env = new Environment('test-' . $adapterName, array());
     $env->registerAdapter($adapterName, $adapter);
     $env->setOptions(array('adapter' => $adapterName));
     $env->getAdapter();
 }
Example #6
0
 public function testGettingInputObject()
 {
     $this->environment->setInput($this->getMock('\\Symfony\\Component\\Console\\Input\\InputInterface'));
     $inputObject = $this->environment->getInput();
     $this->assertInstanceOf('\\Symfony\\Component\\Console\\Input\\InputInterface', $inputObject);
 }