Skip to content

Commit

Permalink
Fix duplicated magic config.
Browse files Browse the repository at this point in the history
Aliasing connections is a more robust way to dynamically reconfigure
Table classes, and doesn't require as much work.

Also remove FixtureManager::_db it was a pointless reference.
  • Loading branch information
markstory committed Oct 20, 2013
1 parent 2ebf5d7 commit 14615da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
17 changes: 5 additions & 12 deletions Cake/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -41,13 +41,6 @@ class FixtureManager {
*/
protected $_initialized = false;

/**
* Default datasource to use
*
* @var DataSource
*/
protected $_db = null;

/**
* Holds the fixture classes that where instantiated
*
Expand All @@ -69,11 +62,11 @@ class FixtureManager {
* @return void
*/
public function fixturize($test) {
$this->_initDb();
if (empty($test->fixtures) || !empty($this->_processed[get_class($test)])) {
return;
}
$this->_initDb();
$test->db = $this->_db;
$test->db = ConnectionManager::get('test', false);
if (!is_array($test->fixtures)) {
$test->fixtures = array_map('trim', explode(',', $test->fixtures));
}
Expand Down Expand Up @@ -117,8 +110,6 @@ protected function _initDb() {
return;
}
$this->_aliasConnections();
$db = ConnectionManager::get('test', false);
$this->_db = $db;
$this->_initialized = true;
}

Expand Down Expand Up @@ -171,10 +162,12 @@ protected function _loadFixtures($fixtures) {
*/
protected function _setupTable(TestFixture $fixture, Connection $db = null, $drop = true) {
if (!$db) {
$db = $this->_db;
if (!empty($fixture->connection)) {
$db = ConnectionManager::get($fixture->connection, false);
}
if (!$db) {
$db = ConnectionManager::get('test', false);
}
}
if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
return;
Expand Down
3 changes: 0 additions & 3 deletions Cake/TestSuite/Fixture/TestFixture.php
Expand Up @@ -21,7 +21,6 @@
use Cake\Database\Schema\Table;
use Cake\Error;
use Cake\Log\Log;
use Cake\ORM\Table as Repository;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;

Expand Down Expand Up @@ -274,8 +273,6 @@ public function drop(Connection $db) {
* @return boolean on success or if there are no records to insert, or false on failure
*/
public function insert(Connection $db) {
Repository::config($this->table, ['connection' => $db]);

if (isset($this->records) && !empty($this->records)) {
list($fields, $values, $types) = $this->_getRecords();
$query = $db->newQuery()
Expand Down

0 comments on commit 14615da

Please sign in to comment.