Accept user-definded datasource when testing #1078

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

CauanCabral commented Jan 21, 2013

CakePHP override 'ds' option in ClassRegistry::init when test mode is true.
This change keep user-defined option.

Test case added.

@markstory markstory commented on an outdated diff Jan 21, 2013

lib/Cake/Utility/ClassRegistry.php
@@ -151,6 +150,10 @@ public static function init($class, $strict = false) {
$settings['ds'] = $useDbConfig;
}
}
+
+ if(!isset($settings['ds']) || empty($settings['ds'])) {
@markstory

markstory Jan 21, 2013

Owner

Should be if (

@markstory

markstory Jan 21, 2013

Owner

Also you can just use empty($settings['ds']) here. Anyone who makes a datasource with the name of '0' deserves a talking to.

Contributor

CauanCabral commented Jan 22, 2013

Updated, but maybe this is not a good ideia.

CakeFixtureManager also override user-defined datasource, so, initialized data/structure can be placed at a different database/schema. What do you think?

Owner

markstory commented Jan 22, 2013

I don't really understand why you'd be passing the 'ds' into ClassRegistry::init(). It seems like something that should be declared on the class not dynamically changed at runtime.

Contributor

CauanCabral commented Jan 22, 2013

In one application, I've default DB connection using PostgreSQL and another using MongoDB.
When I try run tests of Models, CakePHP load connection default 'test', so, I'm forcing initilize Model with specific connection.
I can't declare connection directly at Model because it's a reutilized plugin.

Owner

lorenzo commented Jan 22, 2013

Since 2.1 we support a magic datasource change by using the test_ prefix. For instance if you use a datasource named mongo in a model then the model will be configured to use test_mongo in your test case. Would that work for you?

Contributor

CauanCabral commented Jan 23, 2013

I did used that option, but are two different scenario, the first it's above, other is when my default connection uses MongoDB. In that case I would like to use it as connection.

So, in my tests cases, I try dynamically check if default source is Mongo, otherwise, I try use another (named test_mongo, like you suggest).

But maybe is better requiring a connection named 'mongo' and 'test_mongo' as plugin dependency.

Contributor

CauanCabral commented Jan 25, 2013

Well, I thought about "convention over configuration" and is better remove that PR.
This would add edge cases to test and unnecessary complexity into core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment