From dde0912d1e97862257f97e05bd75a08672dc7504 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 13 Mar 2013 17:52:47 +0100 Subject: [PATCH 1/2] Throw exceptions only when datasource has wrong package, not check for instance of Datasource --- lib/Cake/Model/ConnectionManager.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index a756c75bb..e117fb2c1 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -99,17 +99,16 @@ class ConnectionManager { $conn = self::$_connectionsEnum[$name]; $class = $conn['classname']; - $instance = new $class(self::$config->{$name}); - $instance->configKeyName = $name; - - if (!$instance instanceof Datasource) { + if (strpos(App::location($class), 'Datasource') === false) { throw new MissingDatasourceException(array( 'class' => $class, 'plugin' => null, - 'message' => 'Only classes extending Datasource can be used as datasources.' + 'message' => 'Datasource is not found in Model/Datasource package.' )); } - self::$_dataSources[$name] = $instance; + self::$_dataSources[$name] = new $class(self::$config->{$name}); + self::$_dataSources[$name]->configKeyName = $name; + return self::$_dataSources[$name]; } From 8374eb92cc9445d91102751b7e730804f2886071 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 13 Mar 2013 21:58:55 +0100 Subject: [PATCH 2/2] fix failing tests. test and mocked sources would cause exceptions --- lib/Cake/Model/ConnectionManager.php | 1 - lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php | 3 +++ lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 1 + lib/Cake/Test/Case/Model/ModelWriteTest.php | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index e117fb2c1..4437ec435 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -78,7 +78,6 @@ class ConnectionManager { * * @param string $name The name of the DataSource, as defined in app/Config/database.php * @return DataSource Instance - * @throws MissingDatasourceConfigException * @throws MissingDatasourceException */ public static function getDataSource($name) { diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 1a4da88fe..dc012881f 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -21,6 +21,9 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); App::uses('DataSource', 'Model/Datasource'); App::uses('DboSource', 'Model/Datasource'); +App::uses('DboTestSource', 'Model/Datasource'); +App::uses('DboSecondTestSource', 'Model/Datasource'); +App::uses('MockDataSource', 'Model/Datasource'); require_once dirname(dirname(__FILE__)) . DS . 'models.php'; class MockPDO extends PDO { diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 96b74037a..945f10b93 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -20,6 +20,7 @@ require_once dirname(__FILE__) . DS . 'ModelTestBase.php'; App::uses('DboSource', 'Model/Datasource'); +App::uses('DboMock', 'Model/Datasource'); /** * DboMock class diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index a62716189..e69a9de8a 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -17,6 +17,11 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('MockTransactionDboSource', 'Model/Datasource'); +App::uses('MockTransactionAssociatedDboSource', 'Model/Datasource'); +App::uses('MockManyTransactionDboSource', 'Model/Datasource'); +App::uses('MockAssociatedTransactionDboSource', 'Model/Datasource'); + require_once dirname(__FILE__) . DS . 'ModelTestBase.php'; /** * ModelWriteTest