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 function setUp() { parent::setUp(); if (!Kwf_Registry::get('config')->amazon || !Kwf_Registry::get('config')->amazon->key) { $this->markTestSkipped(); } sleep(1); Kwf_Model_Abstract::clearInstances(); }
public function tearDown() { Kwf_Events_ModelObserver::getInstance()->setSkipFnF(true); Kwf_Component_Data_Root::reset(); Kwf_Component_Cache::clearInstance(); Kwf_Model_Abstract::clearInstances(); Kwf_Events_Dispatcher::clearCache(); Kwf_Events_Subscriber::clearInstances(); Kwf_Component_PagesMetaModel::clearInstance(); Kwf_Trl::getInstance()->unsetTrlElements(); }
/** * Muss im Test separat aufgerufen werden wenn für den Test eine eigene DB * benötigt wird */ public static function createSeparateTestDb($bootstrapFile) { if (substr($bootstrapFile, 0, 1) != '/') { throw new Kwf_Exception("First argument 'bootstrapFile' must be an absolute path to the file"); } $section = preg_replace('/[^a-zA-Z0-9]/', '', Kwf_Registry::get('config')->getSectionName()); Kwf_Test_SeparateDb::$_dbName = 'test_' . $section . date('_Ymd_His_') . substr(uniqid(), -5); $testDb = Kwf_Test::getTestDb(); $testDb->query('CREATE DATABASE ' . Kwf_Test_SeparateDb::getDbName()); Kwf_Registry::set('db', Kwf_Test::getTestDb(Kwf_Test_SeparateDb::getDbName())); $ret = null; passthru('mysql ' . Kwf_Test_SeparateDb::getDbName() . ' < ' . $bootstrapFile, $ret); if ($ret != 0) { throw new Kwf_Exception("bootstrap file could not be processed through mysql"); } Kwf_Model_Abstract::clearInstances(); }
private function _executeUpdatesAction($method) { $ret = true; foreach ($this->_updates as $update) { Kwf_Model_Abstract::clearInstances(); //wegen eventueller meta-data-caches die sich geändert haben Kwf_Component_Generator_Abstract::clearInstances(); Kwf_Component_Data_Root::reset(); if ($this->_progressBar && $method == 'update') { $this->_progressBar->next(1, $update->getUniqueName()); } $e = false; try { if (!$this->_verbose) { ob_start(); //update script should not output anything, if it still does discard it } $update->{$method}(); if (!$this->_verbose) { ob_end_clean(); } } catch (Exception $e) { if (!$this->_verbose) { ob_end_clean(); } if ($this->_debug) { throw $e; } $this->_errors[] = array('name' => $update->getUniqueName(), 'message' => $e->getMessage()); if ($this->_verbose) { echo "\n[31mError:[0m\n"; echo $e->getMessage() . "\n\n"; flush(); } $ret = false; } } return $ret; }
/** * @group slow */ public function testFindFeeds() { Kwf_Model_Abstract::clearInstances(); $m = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Feed_Feeds'); /* $feeds = $m->findFeeds('http://www.prosalzburg.at'); $this->assertEquals(1, count($feeds)); $feeds = array_keys($feeds); $this->assertEquals('http://www.prosalzburg.at/news/feed', $feeds[0]); */ $feeds = $m->findFeeds('http://www.heise.de'); $this->assertEquals(2, count($feeds)); $feeds = array_keys($feeds); $this->assertEquals('http://www.heise.de/newsticker/heise-atom.xml', $feeds[0]); }
public function runAction() { $debug = $this->_getParam('debug'); if (file_exists('temp/shutdown-maintenance')) { unlink('temp/shutdown-maintenance'); } $lastDailyRun = null; if (file_exists('temp/maintenance-daily-run')) { $lastDailyRun = file_get_contents('temp/maintenance-daily-run'); if ($debug) { echo "last daily run: " . date('Y-m-d H:i:s', $lastDailyRun) . "\n"; } } $lastHourlyRun = null; if (file_exists('temp/maintenance-hourly-run')) { $lastHourlyRun = file_get_contents('temp/maintenance-hourly-run'); if ($debug) { echo "last hourly run: " . date('Y-m-d H:i:s', $lastHourlyRun) . "\n"; } } $dailyMaintenanceWindowStart = "01:00"; //don't set before 00:00 $dailyMaintenanceWindowEnd = "05:00"; $nextDailyRun = null; $lastMinutelyRun = null; while (true) { if (!$nextDailyRun) { if ($lastDailyRun && $lastDailyRun > strtotime($dailyMaintenanceWindowStart)) { //today already run //maintenance window of tomorrow $nextDailyRun = rand(strtotime("tomorrow {$dailyMaintenanceWindowStart}"), strtotime("tomorrow {$dailyMaintenanceWindowEnd}")); } else { //not yet run or today not yet run if (time() < strtotime($dailyMaintenanceWindowEnd)) { //window not yet over for today //maintenance window of today $nextDailyRun = rand(max(time(), strtotime($dailyMaintenanceWindowStart)), strtotime($dailyMaintenanceWindowEnd)); } else { //maintenance window of tomorrow $nextDailyRun = rand(strtotime("tomorrow {$dailyMaintenanceWindowStart}"), strtotime("tomorrow {$dailyMaintenanceWindowEnd}")); } } if ($debug) { echo "Next daily run: " . date('Y-m-d H:i:s', $nextDailyRun) . "\n"; } } Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_SECONDS, $debug); if (!$lastMinutelyRun || time() - $lastMinutelyRun > 60) { $lastMinutelyRun = time(); Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_MINUTELY, $debug); //discard connection to database to reconnect on next job run //avoids problems with auto closed connections due to inactivity if (function_exists('gc_collect_cycles()')) { Kwf_Model_Abstract::clearAllRows(); Kwf_Model_Abstract::clearInstances(); gc_collect_cycles(); Kwf_Registry::getInstance()->offsetUnset('db'); Kwf_Registry::getInstance()->offsetUnset('dao'); } } Kwf_Component_Data_Root::getInstance()->freeMemory(); if (!$lastHourlyRun || time() - $lastHourlyRun > 3600) { if ($debug) { echo date('Y-m-d H:i:s') . " execute hourly jobs\n"; } $lastHourlyRun = time(); file_put_contents('temp/maintenance-hourly-run', $lastHourlyRun); Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_HOURLY, $debug); } Kwf_Component_Data_Root::getInstance()->freeMemory(); if (time() > $nextDailyRun) { if ($debug) { echo date('Y-m-d H:i:s') . " execute daily jobs\n"; } $lastDailyRun = time(); file_put_contents('temp/maintenance-daily-run', $lastDailyRun); $nextDailyRun = null; Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_DAILY, $debug); } sleep(10); } }
private function _createModelInstance() { Kwf_Model_Abstract::clearInstances(); return Kwf_Model_Abstract::getInstance('Kwf_Model_RowCache_RowCacheModel'); }
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); }