* @license PHP License * @package WB * @subpackage unittest */ /** * Helper class for UnitTests that require SQL support * * * @version 0.2.0 * @package WB * @subpackage unittest */ class WBUnitTest_SQLUte { /** * source SQL dump * * Use mysql client to source in SQL * * @param string $file file name of calling class * @param string $name sql file's name extension e.g. "construct" or "destruct" */ public static function source( $file, $name = 'construct' ) { // flush cache WBClass::load('WBDatasource_TableMicroCache'); WBDatasource_TableMicroCache::flushAll(); self::sourceSQL(WBParam::get('wb/dir/base') . '/test/unit', $name); self::sourceSQL(dirname($file), basename($file, '.php') . '.' . $name); } private static function sourceSQL($dir, $name) { $conf = WBClass::create( 'WBConfig' ); $conf->load('config'); $cmd = 'mysql -u %s --password="%s" %s < %s/sql/%s.sql'; $cmd = sprintf($cmd , $conf->get('db/user') , $conf->get('db/password') , $conf->get('db/database') , $dir , $name); exec($cmd, $out, $ret); if (0 < $ret) { echo 'Failed to execute SQL: "' . $dir . '/sql/' . $name . '.sql"!'; die("\n"); } } }