Skip to content

Commit

Permalink
BUG Fixed major issue with testing dataobjects that implement TestOnl…
Browse files Browse the repository at this point in the history
…y and extend non-TestOnly dataobjects. Database regeneration would incorrectly populate the ClassName column
  • Loading branch information
tractorcow committed May 27, 2013
1 parent 2b9a44e commit 0ee79d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dev/TestRunner.php
Expand Up @@ -92,6 +92,10 @@ public static function use_test_manifest() {
Config::inst()->pushConfigStaticManifest(new SS_ConfigStaticManifest(
BASE_PATH, true, isset($_GET['flush'])
));

// Invalidate classname spec since the test manifest will now pull out new subclasses for each internal class
// (e.g. Member will now have various subclasses of DataObjects that implement TestOnly)
DataObject::clear_classname_spec_cache();
}

public function init() {
Expand Down
10 changes: 9 additions & 1 deletion model/DataObject.php
Expand Up @@ -192,6 +192,14 @@ public static function set_validation_enabled($enable) {
* @var [string] - class => ClassName field definition cache for self::database_fields
*/
private static $classname_spec_cache = array();

/**
* Clear all cached classname specs. It's necessary to clear all cached subclassed names
* for any classes if a new class manifest is generated.
*/
public static function clear_classname_spec_cache() {
self::$classname_spec_cache = array();
}

/**
* Return the complete map of fields on this object, including "Created", "LastEdited" and "ClassName".
Expand All @@ -202,7 +210,7 @@ public static function set_validation_enabled($enable) {
*/
public static function database_fields($class) {
if(get_parent_class($class) == 'DataObject') {
if(!isset(self::$classname_spec_cache[$class])) {
if(empty(self::$classname_spec_cache[$class])) {
$classNames = ClassInfo::subclassesFor($class);

$db = DB::getConn();
Expand Down

0 comments on commit 0ee79d4

Please sign in to comment.