protected function initTestDb($bootstrapFile) { Kwf_Test_SeparateDb::createSeparateTestDb($bootstrapFile); $dbName = Kwf_Test_SeparateDb::getDbName(); $this->createCookie('test_special_db=' . $dbName, 'path=/, max_age=60*5'); Kwf_Registry::set('db', Kwf_Test::getTestDb($dbName)); Kwf_Model_Abstract::clearInstances(); }
public static function reload() { $configClass = Kwf_Setup::$configClass; $config = new $configClass(Kwf_Setup::getConfigSection()); $cacheId = 'config_' . str_replace('-', '_', Kwf_Setup::getConfigSection()); Kwf_Config_Cache::getInstance()->save($config, $cacheId); if (extension_loaded('apc')) { $apcCacheId = $cacheId . getcwd(); apc_delete($apcCacheId); apc_delete($apcCacheId . 'mtime'); } Kwf_Config_Web::clearInstances(); Kwf_Registry::set('config', $config); }
public static function reload() { $configClass = Kwf_Setup::$configClass; $config = new $configClass(Kwf_Setup::getConfigSection()); $cacheId = 'config_' . str_replace(array('-', '.'), '_', Kwf_Setup::getConfigSection()); Kwf_Config_Cache::getInstance()->save($config, $cacheId); if (extension_loaded('apc')) { $apcCacheId = $cacheId . getcwd(); apc_delete($apcCacheId); apc_delete($apcCacheId . 'mtime'); if (PHP_SAPI == 'cli') { Kwf_Util_Apc::callClearCacheByCli(array(array('cacheIds' => $apcCacheId . ',' . $apcCacheId . 'mtime'))); } Kwf_Cache_SimpleStatic::clear('config-'); } Kwf_Config_Web::clearInstances(); Kwf_Registry::set('config', $config); }
public static function restoreTestDb() { $dbName = Kwf_Test_SeparateDb::getDbName(); if ($dbName) { $testDb = Kwf_Test::getTestDb(); // alte test-dbs löschen $testDatabases = $testDb->query('SHOW DATABASES')->fetchAll(); foreach ($testDatabases as $testDatabase) { if (preg_match('/^test_[^_]+_([0-9]+)_[0-9]+_[^_]+$/', $testDatabase['Database'], $matches)) { // test-db löschen wenn sie älter als 2 tage is if ((int) $matches[1] < (int) date('Ymd', time() - 2 * 86400)) { $testDb->query('DROP DATABASE ' . $testDatabase['Database']); } } } $testDb->query('DROP DATABASE ' . $dbName); Kwf_Test_SeparateDb::$_dbName = null; Kwf_Registry::set('db', $testDb); } }
/** * @param array possible options: types(=all), output(=false), excludeTypes */ public final function build(array $options) { $typeNames = $options['types']; $output = isset($options['output']) ? $options['output'] : false; $excludeTypes = isset($options['excludeTypes']) ? $options['excludeTypes'] : array(); Kwf_Cache_SimpleStatic::disableFileCache(); Kwf_Events_ModelObserver::getInstance()->disable(); Kwf_Util_MemoryLimit::set(1024 * 2); Kwf_Registry::set('db', false); if ($typeNames == 'all') { $types = $this->getTypes(); } else { if (!is_array($typeNames)) { $typeNames = explode(',', $typeNames); } $types = array(); foreach ($this->getTypes() as $t) { if (in_array($t->getTypeName(), $typeNames)) { $types[] = $t; } } } if (is_string($excludeTypes)) { $excludeTypes = explode(',', $excludeTypes); } foreach ($types as $k => $i) { if (in_array($i->getTypeName(), $excludeTypes)) { unset($types[$k]); } } $maxTypeNameLength = 0; $countSteps = 0; foreach ($types as $type) { $type->setVerbosity($output ? Kwf_Util_Build_Types_Abstract::VERBOSE : Kwf_Util_Build_Types_Abstract::SILENT); $maxTypeNameLength = max($maxTypeNameLength, strlen($type->getTypeName())); $countSteps++; } $progress = null; if (isset($options['progressAdapter'])) { $progress = new Zend_ProgressBar($options['progressAdapter'], 0, $countSteps); } if (!file_exists('build')) { mkdir('build'); } $currentStep = 0; foreach ($types as $type) { $currentStep++; if ($progress) { $progress->next(1, "building " . $type->getTypeName()); } if ($output) { echo "[" . str_repeat(' ', 2 - strlen($currentStep)) . "{$currentStep}/{$countSteps}] "; echo "building " . $type->getTypeName() . "..." . str_repeat('.', $maxTypeNameLength - strlen($type->getTypeName())) . " "; } $t = microtime(true); $type->build($options); if ($output) { if ($type->getSuccess()) { echo "[00;32mOK[00m"; } else { echo " [[01;31mERROR[00m]"; return false; } echo " (" . round((microtime(true) - $t) * 1000) . "ms)"; echo "\n"; } } Kwf_Events_ModelObserver::getInstance()->enable(); return $types; }
public function indexAction() { self::initForTests(); if (!Kwf_Registry::get('config')->server->domain) { throw new Kwf_Exception_Client("Can't run tests; server.domain is not set. Please set in tests/config.local.ini"); } $arguments = array(); $arguments['colors'] = true; $arguments['filter'] = false; if ($this->_getParam('filter')) { $arguments['filter'] = $this->_getParam('filter'); } $arguments['groups'] = array(); if ($this->_getParam('group')) { $arguments['groups'] = explode(',', $this->_getParam('group')); } $arguments['excludeGroups'] = array(); if ($this->_getParam('exclude-group')) { $arguments['excludeGroups'] = explode(',', $this->_getParam('exclude-group')); } $arguments['verbose'] = false; if ($this->_getParam('verbose')) { $arguments['verbose'] = $this->_getParam('verbose'); } if ($this->_getParam('stop-on-failure')) { $arguments['stopOnFailure'] = $this->_getParam('stop-on-failure'); } if ($this->_getParam('log-xml')) { $arguments['xmlLogfile'] = $this->_getParam('log-xml'); } if ($this->_getParam('log-pmd')) { $arguments['pmdXML'] = $this->_getParam('log-pmd'); } if ($this->_getParam('log-metrics')) { $arguments['metricsXML'] = $this->_getParam('log-metrics'); } if ($this->_getParam('coverage-xml')) { $arguments['coverageClover'] = $this->_getParam('coverage-xml'); } if ($this->_getParam('retry-on-error')) { $arguments['retryOnError'] = $this->_getParam('retry-on-error'); } if ($this->_getParam('coverage')) { if (!extension_loaded('tokenizer') || !extension_loaded('xdebug')) { throw new Kwf_ClientException('tokenizer and xdebug extensions must be loaded'); } if (!is_string($this->_getParam('coverage'))) { $arguments['reportDirectory'] = './report'; } else { $arguments['reportDirectory'] = $this->_getParam('coverage'); } } Kwf_Registry::set('testDomain', Kwf_Registry::get('config')->server->domain); Kwf_Registry::set('testServerConfig', Kwf_Registry::get('config')); if ($this->_getParam('report')) { $resultLogger = new Kwf_Test_ResultLogger(true); $arguments['listeners'][] = $resultLogger; } if ($this->_getParam('testdox')) { $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); $arguments['noProgress'] = true; } else { if ($this->_getParam('no-progress')) { $arguments['noProgress'] = true; } } if ($this->_getParam('disable-debug')) { Kwf_Debug::disable(); } //nur temporär deaktiviert, damit ich selenium-verbindungs-probleme besser debuggen kann // PHPUnit_Util_Filter::setFilter(false); $runner = new Kwf_Test_TestRunner(); $suite = new Kwf_Test_TestSuite(); Kwf_Model_Abstract::clearInstances(); $result = $runner->doRun($suite, $arguments); if ($this->_getParam('report')) { $resultLogger->printResult($result); $reportData = array('tests' => $result->count(), 'failures' => $result->failureCount() + $result->errorCount(), 'skipped' => $result->skippedCount(), 'not_implemented' => $result->notImplementedCount(), 'kwf_version' => Kwf_Util_Git::kwf()->getActiveBranch() . ' (' . Kwf_Util_Git::kwf()->revParse('HEAD') . ')'); if (Kwf_Registry::get('config')->application->id != 'kwf') { $reportData['web_version'] = Kwf_Util_Git::web()->getActiveBranch() . ' (' . Kwf_Util_Git::web()->revParse('HEAD') . ')'; } echo "===REPORT==="; echo serialize($reportData); echo "===/REPORT==="; } Kwf_Benchmark::shutDown(); if ($result->wasSuccessful()) { exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } else { if ($result->errorCount() > 0) { exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } else { exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } $this->_helper->viewRenderer->setNoRender(true); }