Created
September 22, 2012 14:46
-
-
Save lorenzo/3766399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ParentFixture extends CakeTestFixture { | |
public $import = array(); | |
protected $hasData = false; | |
protected static $truncating = false; | |
protected static $log = array(); | |
public function insert($db) { | |
self::$truncating = false; | |
if ($this->hasData) { | |
return; | |
} | |
parent::insert($db); | |
$this->hasData = true; | |
} | |
public function truncate($db) { | |
if (!self::$truncating) { | |
self::$log = $db->getLog(false, true); | |
self::$truncating = true; | |
} | |
foreach (self::$log['log'] as $i => $q) { | |
if (preg_match('/^UPDATE|^INSERT/i', $q['query'])) { | |
if (strpos($q['query'], $db->fullTableName($this->table, false, false)) !== false) { | |
parent::truncate($db); | |
$this->hasData = false; | |
return; | |
} | |
} else { | |
unset(self::$log['log'][$i]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment