Skip to content
Permalink
Browse files

Make fixtures work again.

New style static fixtures now work in MySQL.
  • Loading branch information...
markstory committed May 26, 2013
1 parent 9d985a8 commit 4d40083d9ec52870d09c0e6027f42a1bf5262f6f
Showing with 15 additions and 12 deletions.
  1. +11 −11 lib/Cake/TestSuite/Fixture/FixtureManager.php
  2. +4 −1 lib/Cake/TestSuite/Fixture/TestFixture.php
@@ -22,8 +22,10 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Database\Connection;
use Cake\Model\ConnectionManager;
use Cake\TestSuite\TestCase;
use Cake\TestSuite\Fixture\TestFixture;
use Cake\Utility\ClassRegistry;
use Cake\Utility\Inflector;
@@ -146,24 +148,24 @@ protected function _loadFixtures($fixtures) {
* Runs the drop and create commands on the fixtures if necessary.
*
* @param Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
* @param DataSource $db the datasource instance to use
* @param Connection $db the datasource instance to use
* @param boolean $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable($fixture, $db = null, $drop = true) {
protected function _setupTable(TestFixture $fixture, Connection $db = null, $drop = true) {
if (!$db) {
if (!empty($fixture->useDbConfig)) {
$db = ConnectionManager::getDataSource($fixture->useDbConfig);
} else {
$db = $this->_db;
$db = $this->_db;
if (!empty($fixture->connection)) {
$db = ConnectionManager::getDataSource($fixture->connection);
}
}
if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) {
return;
}
$sources = (array)$db->listTables();
$table = $db->config['prefix'] . $fixture->table;
$schemaCollection = $db->schemaCollection();
$sources = (array)$schemaCollection->listTables();
$table = $fixture->table;
$exists = in_array($table, $sources);
if ($drop && $exists) {
@@ -186,8 +188,6 @@ public function load(TestCase $test) {
if (empty($test->fixtures)) {
return;
}
// TODO Re-enable once fixtures are working.
return;
$fixtures = $test->fixtures;
if (empty($fixtures) || !$test->autoFixtures) {
@@ -197,7 +197,7 @@ public function load(TestCase $test) {
foreach ($fixtures as $f) {
if (!empty($this->_loaded[$f])) {
$fixture = $this->_loaded[$f];
$db = ConnectionManager::getDataSource($fixture->useDbConfig);
$db = ConnectionManager::getDataSource($fixture->connection);
$db->begin();
$this->_setupTable($fixture, $db, $test->dropTables);
$fixture->insert($db);
@@ -156,7 +156,8 @@ protected function _schemaFromFields() {
if ($field === 'constraints' || $field === 'indexes') {
continue;
}
// TODO issue E_USER_NOTICE if a column defines 'key'
// TODO issue E_USER_NOTICE if a column defines 'key'?
// Or handle the case correctly?
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['constraints'])) {
@@ -165,6 +166,8 @@ protected function _schemaFromFields() {
}
}
if (!empty($this->fields['indexes'])) {
// TODO 2.x indexes contains indexes + constraints.
// Should we issue an error or handle the case?
foreach ($this->fields['indexes'] as $name => $data) {
$this->_schema->addIndex($name, $data);
}

0 comments on commit 4d40083

Please sign in to comment.
You can’t perform that action at this time.