Example #1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The environment configuration for 'staging' is missing
  */
 public function testGetDefaultEnvironmentWithAMissingEnvironmentEntry()
 {
     // test using a Yaml file with a 'default_database' key, but without a
     // corresponding entry
     $path = __DIR__ . '/_files';
     $config = \Phinx\Config\Config::fromYaml($path . '/missing_environment_entry.yml');
     $config->getDefaultEnvironment();
 }
Example #2
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=');
 }
 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 = 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 #4
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 #5
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);
 }
 /**
  * Loads and returns a phinx configuration
  *
  * @param string $fileName
  *
  * @return ConfigInterface
  */
 private function getConfiguration($fileName)
 {
     return Config::fromYaml(__DIR__ . '/../Fixture/' . $fileName);
 }