Merge branch 'all-tests' of github.com:markstory/cakephp into all-tests

This commit is contained in:
mark_story 2010-09-25 22:34:10 -04:00
commit 0222717e33
5 changed files with 40 additions and 45 deletions

View file

@ -50,7 +50,7 @@ class AllTests extends PHPUnit_Framework_TestSuite {
$suite->addTestFile($path . 'all_helpers.test.php'); $suite->addTestFile($path . 'all_helpers.test.php');
$suite->addTestFile($path . 'all_libs.test.php'); $suite->addTestFile($path . 'all_libs.test.php');
$suite->addTestFile($path . 'all_localization.test.php'); $suite->addTestFile($path . 'all_localization.test.php');
//$suite->addTestFile($path . 'all_model.test.php'); $suite->addTestFile($path . 'all_model.test.php');
$suite->addTestFile($path . 'all_routing.test.php'); $suite->addTestFile($path . 'all_routing.test.php');
$suite->addTestFile($path . 'all_socket.test.php'); $suite->addTestFile($path . 'all_socket.test.php');
$suite->addTestFile($path . 'all_test_suite.test.php');; $suite->addTestFile($path . 'all_test_suite.test.php');;

View file

@ -84,7 +84,7 @@ class CakeTestFixtureImportFixture extends CakeTestFixture {
* *
* @var mixed * @var mixed
*/ */
public $import = array('table' => 'fixture_tests', 'connection' => 'fixture_test'); public $import = array('table' => 'fixture_tests', 'connection' => 'fixture_test_suite');
} }
/** /**
@ -139,12 +139,8 @@ class CakeTestFixtureTest extends CakeTestCase {
function setUp() { function setUp() {
$this->criticDb = $this->getMock('DboSource'); $this->criticDb = $this->getMock('DboSource');
$this->criticDb->fullDebug = true; $this->criticDb->fullDebug = true;
$this->db = ConnectionManager::getDataSource('test');
$dbs = ConnectionManager::enumConnectionObjects(); $this->_backupConfig = $this->db->config;
if (!isset($dbs['test'])) {
$db = ConnectionManager::getDatasource('test');
ConnectionManager::create('test', $db->config);
}
} }
/** /**
@ -155,6 +151,7 @@ class CakeTestFixtureTest extends CakeTestCase {
*/ */
function tearDown() { function tearDown() {
unset($this->criticDb); unset($this->criticDb);
$this->db->config = $this->_backupConfig;
} }
/** /**
@ -194,16 +191,16 @@ class CakeTestFixtureTest extends CakeTestCase {
$this->assertEqual(array_keys($Fixture->fields), $expected); $this->assertEqual(array_keys($Fixture->fields), $expected);
$config = $db->config; $config = $db->config;
$config['prefix'] = 'fixture_test_'; $config['prefix'] = 'fixture_test_suite_';
ConnectionManager::create('fixture_test', $config); ConnectionManager::create('fixture_test_suite', $config);
$Fixture->fields = $Fixture->records = null; $Fixture->fields = $Fixture->records = null;
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test', 'records' => true); $Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test', 'records' => true);
$Fixture->init(); $Fixture->init();
$this->assertEqual(count($Fixture->records), count($Source->records)); $this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture->create(ConnectionManager::getDataSource('fixture_test')); $Fixture->create(ConnectionManager::getDataSource('fixture_test_suite'));
$Fixture =& new CakeTestFixtureImportFixture(); $Fixture = new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null; $Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test'); $Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
$Fixture->init(); $Fixture->init();
@ -213,7 +210,7 @@ class CakeTestFixtureTest extends CakeTestCase {
$keys = array_flip(ClassRegistry::keys()); $keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys)); $this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Fixture->drop(ConnectionManager::getDataSource('fixture_test')); $Fixture->drop(ConnectionManager::getDataSource('fixture_test_suite'));
$Source->drop($db); $Source->drop($db);
} }
@ -226,12 +223,15 @@ class CakeTestFixtureTest extends CakeTestCase {
$db = ConnectionManager::getDataSource('test'); $db = ConnectionManager::getDataSource('test');
$backPrefix = $db->config['prefix']; $backPrefix = $db->config['prefix'];
$db->config['prefix'] = 'cake_fixture_test_'; $db->config['prefix'] = 'cake_fixture_test_';
ConnectionManager::create('fixture_test_suite', $db->config);
$newDb = ConnectionManager::getDataSource('fixture_test_suite');
$newDb->config['prefix'] = 'cake_fixture_test_';
$Source =& new CakeTestFixtureTestFixture(); $Source = new CakeTestFixtureTestFixture();
$Source->create($db); $Source->create($db);
$Source->insert($db); $Source->insert($db);
$Fixture =& new CakeTestFixtureImportFixture(); $Fixture = new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null; $Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test'); $Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
@ -249,16 +249,15 @@ class CakeTestFixtureTest extends CakeTestCase {
* @return void * @return void
*/ */
function testInitModelTablePrefix() { function testInitModelTablePrefix() {
$db = ConnectionManager::getDataSource('test'); $hasPrefix = !empty($this->db->config['prefix']);
$hasPrefix = !empty($db->config['prefix']); if ($this->skipIf($hasPrefix, 'Cannot run this test, you have a database connection prefix.')) {
if ($hasPrefix) { return;
$this->markTestSkipped('Cannot run this test, you have a database connection prefix.');
} }
$Source =& new CakeTestFixtureTestFixture(); $Source = new CakeTestFixtureTestFixture();
$Source->create($db); $Source->create($this->db);
$Source->insert($db); $Source->insert($this->db);
$Fixture =& new CakeTestFixtureTestFixture(); $Fixture = new CakeTestFixtureTestFixture();
unset($Fixture->table); unset($Fixture->table);
$Fixture->fields = $Fixture->records = null; $Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test', 'records' => false); $Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test', 'records' => false);
@ -268,7 +267,7 @@ class CakeTestFixtureTest extends CakeTestCase {
$keys = array_flip(ClassRegistry::keys()); $keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys)); $this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($db); $Source->drop($this->db);
} }
/** /**
@ -282,8 +281,8 @@ class CakeTestFixtureTest extends CakeTestCase {
$testSuiteDb = ConnectionManager::getDataSource('test'); $testSuiteDb = ConnectionManager::getDataSource('test');
$defaultConfig = $defaultDb->config; $defaultConfig = $defaultDb->config;
$testSuiteConfig = $testSuiteDb->config; $testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix']))); ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb = ConnectionManager::getDataSource('new_test'); $newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
$Source = new CakeTestFixtureTestFixture(); $Source = new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb); $Source->create($newTestSuiteDb);
@ -293,7 +292,7 @@ class CakeTestFixtureTest extends CakeTestCase {
$Fixture = new CakeTestFixtureDefaultImportFixture(); $Fixture = new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null; $Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test'); $Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
$Fixture->init(); $Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created')); $this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
@ -317,8 +316,8 @@ class CakeTestFixtureTest extends CakeTestCase {
$testSuiteDb = ConnectionManager::getDataSource('test'); $testSuiteDb = ConnectionManager::getDataSource('test');
$defaultConfig = $defaultDb->config; $defaultConfig = $defaultDb->config;
$testSuiteConfig = $testSuiteDb->config; $testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix']))); ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb = ConnectionManager::getDataSource('new_test'); $newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
$Source = new CakeTestFixtureTestFixture(); $Source = new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb); $Source->create($newTestSuiteDb);
@ -329,7 +328,7 @@ class CakeTestFixtureTest extends CakeTestCase {
$Fixture = new CakeTestFixtureDefaultImportFixture(); $Fixture = new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null; $Fixture->fields = $Fixture->records = null;
$Fixture->import = array( $Fixture->import = array(
'model' => 'FixtureImportTestModel', 'connection' => 'new_test', 'records' => true 'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
); );
$Fixture->init(); $Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created')); $this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));

View file

@ -89,10 +89,12 @@ class CakeFixtureManager {
// Try for test DB // Try for test DB
@$db = ConnectionManager::getDataSource('test'); @$db = ConnectionManager::getDataSource('test');
$testDbAvailable = $db->isConnected(); $testDbAvailable = $db->isConnected();
} else {
throw new MissingConnectionException(__('You need to create a $test datasource connection to start using fixtures'));
} }
if (!$testDbAvailable) { if (!$testDbAvailable) {
throw new MissingConnectionException(__('You need to create a $test datasource connection to start using fixtures')); throw new MissingConnectionException(__('Unable to connect to the $test datasource'));
} }
$this->_db = $db; $this->_db = $db;
@ -220,13 +222,7 @@ class CakeFixtureManager {
* @return void * @return void
*/ */
public function unload(CakeTestCase $test) { public function unload(CakeTestCase $test) {
if (empty($test->fixtures)) { $fixtures = !empty($test->fixtures) ? $test->fixtures : array();
return;
}
$fixtures = $test->fixtures;
if (empty($fixtures)) {
return;
}
foreach ($fixtures as $f) { foreach ($fixtures as $f) {
if (isset($this->_loaded[$f])) { if (isset($this->_loaded[$f])) {
$fixture = $this->_loaded[$f]; $fixture = $this->_loaded[$f];

View file

@ -60,7 +60,6 @@ class CakeTestFixture {
/** /**
* Initialize the fixture. * Initialize the fixture.
* *
* @param object Cake's DBO driver (e.g: DboMysql).
*/ */
public function init() { public function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) { if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
@ -70,10 +69,13 @@ class CakeTestFixture {
); );
if (isset($import['model']) && App::import('Model', $import['model'])) { if (isset($import['model']) && App::import('Model', $import['model'])) {
ClassRegistry::config(array('ds' => $import['connection'])); App::import('Model', $import['model']);
$model = ClassRegistry::init($import['model']); list(, $modelClass) = pluginSplit($import['model']);
$db = ConnectionManager::getDataSource($model->useDbConfig); $model = new $modelClass(null, null, $import['connection']);
$db->cacheSources = false; $db = $model->getDataSource();
if (empty($model->tablePrefix)) {
$model->tablePrefix = $db->config['prefix'];
}
$this->fields = $model->schema(true); $this->fields = $model->schema(true);
$this->fields[$model->primaryKey]['key'] = 'primary'; $this->fields[$model->primaryKey]['key'] = 'primary';
$this->table = $db->fullTableName($model, false); $this->table = $db->fullTableName($model, false);

View file

@ -102,7 +102,5 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
if ($this->_fixtureManager) { if ($this->_fixtureManager) {
$this->_fixtureManager->shutDown(); $this->_fixtureManager->shutDown();
} }
$this->_fixtureManager = null;
$this->sharedFixture = null;
} }
} }