/**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Could not find a default environment
  */
 public function testGetDefaultEnvironmentOverridenFailedToFind()
 {
     // set empty env var
     putenv('PHINX_ENVIRONMENT=');
     $config = new Config(array());
     $config->getDefaultEnvironment();
 }
 /**
  * @covers \Phinx\Config\Config::replaceTokens
  * @covers \Phinx\Config\Config::recurseArrayForTokens
  */
 public function testReplaceTokensRecursive()
 {
     $config = new Config(array('folding' => array('some-var-1' => 'includes/%%PHINX_TEST_VAR_1%%', 'some-var-2' => 'includes/%%NON_PHINX_TEST_VAR_1%%', 'some-var-3' => 'includes/%%PHINX_TEST_VAR_2%%', 'some-var-4' => 123456)));
     $folding = $config->offsetGet('folding');
     $this->assertContains(static::$server['PHINX_TEST_VAR_1'] . '', $folding['some-var-1']);
     $this->assertNotContains(static::$server['NON_PHINX_TEST_VAR_1'] . '', $folding['some-var-2']);
     $this->assertContains(static::$server['PHINX_TEST_VAR_2'] . '', $folding['some-var-3']);
 }
Example #3
0
 /**
  * @covers \Phinx\Config\Config::getDefaultEnvironment
  */
 public function testGetDefaultEnvironmentMethod()
 {
     $path = __DIR__ . '/_files';
     // test using a Yaml file without the 'default_database' key.
     // (it should default to the first one).
     $config = Config::fromYaml($path . '/no_default_database_key.yml');
     $this->assertEquals('production', $config->getDefaultEnvironment());
     // test using environment variable PHINX_ENVIRONMENT
     // (it should return the configuration specified in the environment)
     putenv('PHINX_ENVIRONMENT=externally-specified-environment');
     $config = Config::fromYaml($path . '/no_default_database_key.yml');
     $this->assertEquals('externally-specified-environment', $config->getDefaultEnvironment());
     putenv('PHINX_ENVIRONMENT=');
 }
Example #4
0
 /**
  * Gets an array of the database migrations.
  *
  * @throws \InvalidArgumentException
  * @return AbstractMigration[]
  */
 public function getMigrations()
 {
     if (empty($this->_migrations)) {
         $fileNames = [];
         $versions = [];
         $phpFiles = glob($this->_config->getMigrationPath() . DIRECTORY_SEPARATOR . '*.php');
         foreach ($phpFiles as $filePath) {
             if (Util::isValidMigrationFileName(basename($filePath))) {
                 $version = Util::getVersionFromFileName(basename($filePath));
                 if (isset($versions[$version])) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion()));
                 }
                 //  Convert the filename to a class name.
                 $class = Util::mapFileNameToClassName(basename($filePath));
                 if (isset($fileNames[$class])) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Migration "%s" has the same name as "%s"', basename($filePath), $fileNames[$class]));
                 }
                 $fileNames[$class] = basename($filePath);
                 // Load the migration file.
                 /** @noinspection PhpIncludeInspection */
                 require_once $filePath;
                 if (!class_exists($class)) {
                     throw new \InvalidArgumentException(__d('union_dev', 'Could not find class "%s" in file "%s"', $class, $filePath));
                 }
                 //  Instantiate migration class.
                 $migration = new $class($version);
                 if (!$migration instanceof AbstractMigration) {
                     throw new \InvalidArgumentException(__d('union_dev', 'The class "%s" in file "%s" must extend \\Phinx\\Migration\\AbstractMigration', $class, $filePath));
                 }
                 $versions[$version] = $migration;
             }
         }
         ksort($versions);
         $this->_migrations = $versions;
     }
     return $this->_migrations;
 }
Example #5
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Phinx\Config\Config;
use Phamily\Framework\Util\DatabaseConfigAdapter;
$config = Config::fromYaml(__DIR__ . '/../phinx.yml');
$envName = getenv("PHAMILY_TEST_ENV");
$envConfig = $config->getEnvironment($envName);
echo "tests run with env: '{$envName}'";
$dbConfigAdapter = new DatabaseConfigAdapter();
$zendAdaptedConfig = $dbConfigAdapter->adaptPhinxToZend($envConfig);
\Phamily\tests\DbTest::setConfig($zendAdaptedConfig);
Example #6
0
 /**
  * Parse the config file and load it into the config object
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \InvalidArgumentException
  * @return void
  */
 protected function loadConfig(InputInterface $input, OutputInterface $output)
 {
     $configFilePath = $this->locateConfigFile($input);
     $output->writeln('<info>using config file</info> .' . str_replace(getcwd(), '', realpath($configFilePath)));
     $parser = $input->getOption('parser');
     // If no parser is specified try to determine the correct one from the file extension.  Defaults to YAML
     if (null === $parser) {
         $extension = pathinfo($configFilePath, PATHINFO_EXTENSION);
         switch (strtolower($extension)) {
             case 'json':
                 $parser = 'json';
                 break;
             case 'php':
                 $parser = 'php';
                 break;
             case 'yml':
             default:
                 $parser = 'yaml';
         }
     }
     switch (strtolower($parser)) {
         case 'json':
             $config = Config::fromJson($configFilePath);
             break;
         case 'php':
             $config = Config::fromPhp($configFilePath);
             break;
         case 'yaml':
             $config = Config::fromYaml($configFilePath);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('\'%s\' is not a valid parser.', $parser));
     }
     $output->writeln('<info>using config parser</info> ' . $parser);
     $this->setConfig($config);
 }
Example #7
0
 public function testGetAliasValidAliasRequest()
 {
     $config = new \Phinx\Config\Config(array('aliases' => array('Short' => 'Some\\Long\\Classname')));
     $this->assertEquals('Some\\Long\\Classname', $config->getAlias('Short'));
 }
Example #8
0
 /**
  * @covers \Phinx\Config\Config::getMigrationBaseClassName
  */
 public function testGetMigrationBaseClassNameGetsAlternativeBaseClassWithNamespace()
 {
     $config = new Config(array('migration_base_class' => 'Phinx\\Migration\\AlternativeAbstractMigration'));
     $this->assertEquals('Phinx\\Migration\\AlternativeAbstractMigration', $config->getMigrationBaseClassName(false));
 }
Example #9
0
 /**
  * @covers \Phinx\Config\Config::fromJson
  * @expectedException \RuntimeException
  */
 public function testFromJSONInvalidJson()
 {
     $path = __DIR__ . '/_files';
     Config::fromJson($path . '/invalid.json');
 }
Example #10
0
 /**
  * Checks if base class is returned correctly when specified without
  * a namespace.
  *
  * @covers \Phinx\Config\Config::getMigrationBaseClassName
  */
 public function testGetMigrationBaseClassNameNoNamespaceNoDrop()
 {
     $config = new Config(array('migration_base_class' => 'BaseMigration'));
     $this->assertEquals('BaseMigration', $config->getMigrationBaseClassName(false));
 }
Example #11
0
 /**
  * @covers \Phinx\Config\Config::getSeedPath
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage Seeds path missing from config file
  */
 public function testGetSeedPathThrowsException()
 {
     $config = new \Phinx\Config\Config(array());
     $this->assertEquals('db/seeds', $config->getSeedPath());
 }
Example #12
0
 /**
  * Normal behavior
  */
 public function testGetMigrationPath()
 {
     $config = new Config($this->getConfigArray());
     $this->assertEquals($this->getMigrationPath(), $config->getMigrationPath());
 }
Example #13
0
 /**
  * @expectedException \RuntimeException
  */
 public function testFromPHPMethodWithoutArray()
 {
     $path = __DIR__ . '/_files';
     $config = \Phinx\Config\Config::fromPHP($path . '/config_without_array.php');
     $this->assertEquals('dev', $config->getDefaultEnvironment());
 }
 public function testConfigReplacesTokensWithEnvVariables()
 {
     $_SERVER['PHINX_DBHOST'] = 'localhost';
     $_SERVER['PHINX_DBNAME'] = 'productionapp';
     $_SERVER['PHINX_DBUSER'] = '******';
     $_SERVER['PHINX_DBPASS'] = '******';
     $_SERVER['PHINX_DBPORT'] = '1234';
     $path = __DIR__ . '/_files';
     $config = \Phinx\Config\Config::fromYaml($path . '/external_variables.yml');
     $env = $config->getEnvironment($config->getDefaultEnvironment());
     $this->assertEquals('localhost', $env['host']);
     $this->assertEquals('productionapp', $env['name']);
     $this->assertEquals('root', $env['user']);
     $this->assertEquals('ds6xhj1', $env['pass']);
     $this->assertEquals('1234', $env['port']);
 }
Example #15
0
 /**
  * @covers \Phinx\Config\Config::fromPhp
  * @covers \Phinx\Config\Config::getDefaultEnvironment
  * @expectedException \RuntimeException
  */
 public function testFromJSONMethodWithoutJSON()
 {
     $path = __DIR__ . '/_files';
     $config = Config::fromPhp($path . '/empty.json');
     $this->assertEquals('dev', $config->getDefaultEnvironment());
 }
 /**
  * Loads and returns a phinx configuration
  *
  * @param string $fileName
  *
  * @return ConfigInterface
  */
 private function getConfiguration($fileName)
 {
     return Config::fromYaml(__DIR__ . '/../Fixture/' . $fileName);
 }