From a7c2f26599e57d24b4294f5464014eaff5c71e1c Mon Sep 17 00:00:00 2001 From: KullTC Date: Fri, 27 Feb 2015 15:25:23 +0100 Subject: [PATCH] Make sure default datasource is not used for mock When a non-default datasource is used for a model and no test_ version of that datasource is available, the getMockForModel method used the models standard datasource, rahter than 'test'. --- lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php | 2 +- lib/Cake/TestSuite/CakeTestCase.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php index d6c4fc1f0..d5cee102e 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php @@ -414,7 +414,7 @@ class CakeTestCaseTest extends CakeTestCase { ) ), App::RESET); $Post = $this->getMockForModel('Post'); - + $this->assertEquals('test', $Post->useDbConfig); $this->assertInstanceOf('Post', $Post); $this->assertNull($Post->save(array())); $this->assertNull($Post->find('all')); diff --git a/lib/Cake/TestSuite/CakeTestCase.php b/lib/Cake/TestSuite/CakeTestCase.php index e457a033b..491a0f0aa 100644 --- a/lib/Cake/TestSuite/CakeTestCase.php +++ b/lib/Cake/TestSuite/CakeTestCase.php @@ -732,12 +732,12 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase { $mock = $this->getMock($name, $methods, array($config)); $availableDs = array_keys(ConnectionManager::enumConnectionObjects()); - if ($mock->useDbConfig === 'default') { - $mock->useDbConfig = null; - $mock->setDataSource('test'); - } + if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) { $mock->setDataSource('test_' . $mock->useDbConfig); + } else { + $mock->useDbConfig = 'test'; + $mock->setDataSource('test'); } ClassRegistry::removeObject($name);