/**
  * Add aliases for all non test prefixed connections.
  *
  * This allows models to use the test connections without
  * a pile of configuration work.
  *
  * @return void
  * @see \Cake\TestSuite\Fixture\FixtureManager::_aliasConnections()
  */
 protected function _aliasConnections()
 {
     $connections = ConnectionManager::configured();
     ConnectionManager::alias('test', 'default');
     $map = [];
     foreach ($connections as $connection) {
         if (in_array($connection, ['default', 'test', 'debug_kit'])) {
             continue;
         }
         if (isset($map[$connection])) {
             continue;
         }
         if (strpos($connection, 'test_') === 0) {
             $map[$connection] = substr($connection, 5);
         } else {
             $map['test_' . $connection] = $connection;
         }
     }
     foreach ($map as $alias => $connection) {
         ConnectionManager::alias($alias, $connection);
     }
 }
예제 #2
0
 /**
  * Test alias() raises an error when aliasing an undefined connection.
  *
  * @expectedException \Cake\Datasource\Exception\MissingDatasourceConfigException
  * @return void
  */
 public function testAliasError()
 {
     $this->assertNotContains('test_kaboom', ConnectionManager::configured());
     ConnectionManager::alias('test_kaboom', 'other_name');
 }
예제 #3
0
 /**
  * A callback method that is used to inject the PDO object created from phinx into
  * the CakePHP connection. This is needed in case the user decides to use tables
  * from the ORM and executes queries.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input the input object
  * @param \Symfony\Component\Console\Output\OutputInterface $output the output object
  * @return void
  */
 public function bootstrap(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrap($input, $output);
     $name = $this->getConnectionName($input);
     ConnectionManager::alias($name, 'default');
     $connection = ConnectionManager::get($name);
     $manager = $this->getManager();
     if (!$manager instanceof CakeManager) {
         $this->setManager(new CakeManager($this->getConfig(), $output));
     }
     $env = $this->getManager()->getEnvironment('default');
     $adapter = $env->getAdapter();
     if (!$adapter instanceof CakeAdapter) {
         $env->setAdapter(new CakeAdapter($adapter, $connection));
     }
 }
예제 #4
0
 /**
  * Test getMockForModel on secondary datasources.
  *
  * @return void
  */
 public function testGetMockForModelSecondaryDatasource()
 {
     ConnectionManager::alias('test', 'secondary');
     $post = $this->getMockForModel(__NAMESPACE__ . '\\SecondaryPostsTable', ['save']);
     $this->assertEquals('test', $post->connection()->configName());
 }
예제 #5
0
파일: FixtureManager.php 프로젝트: lhas/pep
 /**
  * Add aliases for all non test prefixed connections.
  *
  * This allows models to use the test connections without
  * a pile of configuration work.
  *
  * @return void
  */
 protected function _aliasConnections()
 {
     $connections = ConnectionManager::configured();
     ConnectionManager::alias('test', 'default');
     $map = [];
     foreach ($connections as $connection) {
         if ($connection === 'test' || $connection === 'default') {
             continue;
         }
         if (isset($map[$connection])) {
             continue;
         }
         if (strpos($connection, 'test_') === 0) {
             $map[$connection] = substr($connection, 5);
         } else {
             $map['test_' . $connection] = $connection;
         }
     }
     foreach ($map as $testConnection => $normal) {
         ConnectionManager::alias($testConnection, $normal);
     }
 }
예제 #6
0
 /**
  * Test that get() uses config data set with config()
  *
  * @return void
  */
 public function testGetWithConnectionName()
 {
     ConnectionManager::alias('test', 'testing');
     $result = $this->_locator->get('Articles', ['connectionName' => 'testing']);
     $this->assertEquals('articles', $result->table());
     $this->assertEquals('test', $result->connection()->configName());
 }