Skip to content

Commit 14615da

Browse files
committed
Fix duplicated magic config.
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.
1 parent 2ebf5d7 commit 14615da

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

Cake/TestSuite/Fixture/FixtureManager.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ class FixtureManager {
4141
*/
4242
protected $_initialized = false;
4343

44-
/**
45-
* Default datasource to use
46-
*
47-
* @var DataSource
48-
*/
49-
protected $_db = null;
50-
5144
/**
5245
* Holds the fixture classes that where instantiated
5346
*
@@ -69,11 +62,11 @@ class FixtureManager {
6962
* @return void
7063
*/
7164
public function fixturize($test) {
65+
$this->_initDb();
7266
if (empty($test->fixtures) || !empty($this->_processed[get_class($test)])) {
7367
return;
7468
}
75-
$this->_initDb();
76-
$test->db = $this->_db;
69+
$test->db = ConnectionManager::get('test', false);
7770
if (!is_array($test->fixtures)) {
7871
$test->fixtures = array_map('trim', explode(',', $test->fixtures));
7972
}
@@ -117,8 +110,6 @@ protected function _initDb() {
117110
return;
118111
}
119112
$this->_aliasConnections();
120-
$db = ConnectionManager::get('test', false);
121-
$this->_db = $db;
122113
$this->_initialized = true;
123114
}
124115

@@ -171,10 +162,12 @@ protected function _loadFixtures($fixtures) {
171162
*/
172163
protected function _setupTable(TestFixture $fixture, Connection $db = null, $drop = true) {
173164
if (!$db) {
174-
$db = $this->_db;
175165
if (!empty($fixture->connection)) {
176166
$db = ConnectionManager::get($fixture->connection, false);
177167
}
168+
if (!$db) {
169+
$db = ConnectionManager::get('test', false);
170+
}
178171
}
179172
if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
180173
return;

Cake/TestSuite/Fixture/TestFixture.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Cake\Database\Schema\Table;
2222
use Cake\Error;
2323
use Cake\Log\Log;
24-
use Cake\ORM\Table as Repository;
2524
use Cake\Utility\Hash;
2625
use Cake\Utility\Inflector;
2726

@@ -274,8 +273,6 @@ public function drop(Connection $db) {
274273
* @return boolean on success or if there are no records to insert, or false on failure
275274
*/
276275
public function insert(Connection $db) {
277-
Repository::config($this->table, ['connection' => $db]);
278-
279276
if (isset($this->records) && !empty($this->records)) {
280277
list($fields, $values, $types) = $this->_getRecords();
281278
$query = $db->newQuery()

0 commit comments

Comments
 (0)