mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge branch 'all-tests' of github.com:markstory/cakephp into all-tests
This commit is contained in:
commit
0222717e33
5 changed files with 40 additions and 45 deletions
|
@ -50,7 +50,7 @@ class AllTests extends PHPUnit_Framework_TestSuite {
|
|||
$suite->addTestFile($path . 'all_helpers.test.php');
|
||||
$suite->addTestFile($path . 'all_libs.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_socket.test.php');
|
||||
$suite->addTestFile($path . 'all_test_suite.test.php');;
|
||||
|
|
|
@ -84,7 +84,7 @@ class CakeTestFixtureImportFixture extends CakeTestFixture {
|
|||
*
|
||||
* @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() {
|
||||
$this->criticDb = $this->getMock('DboSource');
|
||||
$this->criticDb->fullDebug = true;
|
||||
|
||||
$dbs = ConnectionManager::enumConnectionObjects();
|
||||
if (!isset($dbs['test'])) {
|
||||
$db = ConnectionManager::getDatasource('test');
|
||||
ConnectionManager::create('test', $db->config);
|
||||
}
|
||||
$this->db = ConnectionManager::getDataSource('test');
|
||||
$this->_backupConfig = $this->db->config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,6 +151,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
*/
|
||||
function tearDown() {
|
||||
unset($this->criticDb);
|
||||
$this->db->config = $this->_backupConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,16 +191,16 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$this->assertEqual(array_keys($Fixture->fields), $expected);
|
||||
|
||||
$config = $db->config;
|
||||
$config['prefix'] = 'fixture_test_';
|
||||
ConnectionManager::create('fixture_test', $config);
|
||||
$config['prefix'] = 'fixture_test_suite_';
|
||||
ConnectionManager::create('fixture_test_suite', $config);
|
||||
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test', 'records' => true);
|
||||
$Fixture->init();
|
||||
$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->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
|
||||
$Fixture->init();
|
||||
|
@ -213,7 +210,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$keys = array_flip(ClassRegistry::keys());
|
||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||
|
||||
$Fixture->drop(ConnectionManager::getDataSource('fixture_test'));
|
||||
$Fixture->drop(ConnectionManager::getDataSource('fixture_test_suite'));
|
||||
$Source->drop($db);
|
||||
}
|
||||
|
||||
|
@ -226,12 +223,15 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$db = ConnectionManager::getDataSource('test');
|
||||
$backPrefix = $db->config['prefix'];
|
||||
$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->insert($db);
|
||||
|
||||
$Fixture =& new CakeTestFixtureImportFixture();
|
||||
$Fixture = new CakeTestFixtureImportFixture();
|
||||
$Fixture->fields = $Fixture->records = $Fixture->table = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
|
||||
|
||||
|
@ -249,16 +249,15 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testInitModelTablePrefix() {
|
||||
$db = ConnectionManager::getDataSource('test');
|
||||
$hasPrefix = !empty($db->config['prefix']);
|
||||
if ($hasPrefix) {
|
||||
$this->markTestSkipped('Cannot run this test, you have a database connection prefix.');
|
||||
$hasPrefix = !empty($this->db->config['prefix']);
|
||||
if ($this->skipIf($hasPrefix, 'Cannot run this test, you have a database connection prefix.')) {
|
||||
return;
|
||||
}
|
||||
$Source =& new CakeTestFixtureTestFixture();
|
||||
$Source->create($db);
|
||||
$Source->insert($db);
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($this->db);
|
||||
$Source->insert($this->db);
|
||||
|
||||
$Fixture =& new CakeTestFixtureTestFixture();
|
||||
$Fixture = new CakeTestFixtureTestFixture();
|
||||
unset($Fixture->table);
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test', 'records' => false);
|
||||
|
@ -268,7 +267,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$keys = array_flip(ClassRegistry::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');
|
||||
$defaultConfig = $defaultDb->config;
|
||||
$testSuiteConfig = $testSuiteDb->config;
|
||||
ConnectionManager::create('new_test', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test');
|
||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($newTestSuiteDb);
|
||||
|
@ -293,7 +292,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
|
||||
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test');
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
|
||||
$Fixture->init();
|
||||
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
|
||||
|
||||
|
@ -317,8 +316,8 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$testSuiteDb = ConnectionManager::getDataSource('test');
|
||||
$defaultConfig = $defaultDb->config;
|
||||
$testSuiteConfig = $testSuiteDb->config;
|
||||
ConnectionManager::create('new_test', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test');
|
||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||
|
||||
$Source = new CakeTestFixtureTestFixture();
|
||||
$Source->create($newTestSuiteDb);
|
||||
|
@ -329,7 +328,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array(
|
||||
'model' => 'FixtureImportTestModel', 'connection' => 'new_test', 'records' => true
|
||||
'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
|
||||
);
|
||||
$Fixture->init();
|
||||
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
|
||||
|
|
|
@ -89,10 +89,12 @@ class CakeFixtureManager {
|
|||
// Try for test DB
|
||||
@$db = ConnectionManager::getDataSource('test');
|
||||
$testDbAvailable = $db->isConnected();
|
||||
} else {
|
||||
throw new MissingConnectionException(__('You need to create a $test datasource connection to start using fixtures'));
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -220,13 +222,7 @@ class CakeFixtureManager {
|
|||
* @return void
|
||||
*/
|
||||
public function unload(CakeTestCase $test) {
|
||||
if (empty($test->fixtures)) {
|
||||
return;
|
||||
}
|
||||
$fixtures = $test->fixtures;
|
||||
if (empty($fixtures)) {
|
||||
return;
|
||||
}
|
||||
$fixtures = !empty($test->fixtures) ? $test->fixtures : array();
|
||||
foreach ($fixtures as $f) {
|
||||
if (isset($this->_loaded[$f])) {
|
||||
$fixture = $this->_loaded[$f];
|
||||
|
|
|
@ -60,7 +60,6 @@ class CakeTestFixture {
|
|||
/**
|
||||
* Initialize the fixture.
|
||||
*
|
||||
* @param object Cake's DBO driver (e.g: DboMysql).
|
||||
*/
|
||||
public function init() {
|
||||
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'])) {
|
||||
ClassRegistry::config(array('ds' => $import['connection']));
|
||||
$model = ClassRegistry::init($import['model']);
|
||||
$db = ConnectionManager::getDataSource($model->useDbConfig);
|
||||
$db->cacheSources = false;
|
||||
App::import('Model', $import['model']);
|
||||
list(, $modelClass) = pluginSplit($import['model']);
|
||||
$model = new $modelClass(null, null, $import['connection']);
|
||||
$db = $model->getDataSource();
|
||||
if (empty($model->tablePrefix)) {
|
||||
$model->tablePrefix = $db->config['prefix'];
|
||||
}
|
||||
$this->fields = $model->schema(true);
|
||||
$this->fields[$model->primaryKey]['key'] = 'primary';
|
||||
$this->table = $db->fullTableName($model, false);
|
||||
|
|
|
@ -102,7 +102,5 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
|
|||
if ($this->_fixtureManager) {
|
||||
$this->_fixtureManager->shutDown();
|
||||
}
|
||||
$this->_fixtureManager = null;
|
||||
$this->sharedFixture = null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue