/** * Given an installSettingsForm, run the install including the schema creation and default data load. This is * used by the interactice install and the command line install. * @param object $form * @param object $messageStreamer */ public static function runInstallation($form, &$messageStreamer) { assert('$form instanceof InstallSettingsForm'); assert('$messageStreamer instanceof MessageStreamer'); if (defined('IS_TEST')) { $perInstanceFilename = "perInstanceTest.php"; $debugFilename = "debugTest.php"; } else { @set_time_limit(1200); $perInstanceFilename = "perInstance.php"; $debugFilename = "debug.php"; } $messageStreamer->add(Zurmo::t('InstallModule', 'Connecting to Database.')); InstallUtil::connectToDatabase($form->databaseType, $form->databaseHostname, $form->databaseName, $form->databaseUsername, $form->databasePassword, $form->databasePort); ForgetAllCacheUtil::forgetAllCaches(); $messageStreamer->add(Zurmo::t('InstallModule', 'Dropping existing tables.')); InstallUtil::dropAllTables(); $messageStreamer->add(Zurmo::t('InstallModule', 'Creating super user.')); InstallUtil::createSuperUser('super', $form->superUserPassword); $messageLogger = new MessageLogger($messageStreamer); Yii::app()->custom->runBeforeInstallationAutoBuildDatabase($messageLogger); $messageStreamer->add(Zurmo::t('InstallModule', 'Starting database schema creation.')); $startTime = microtime(true); $messageStreamer->add('debugOn:' . BooleanUtil::boolToString(YII_DEBUG)); $messageStreamer->add('phpLevelCaching:' . BooleanUtil::boolToString(PHP_CACHING_ON)); $messageStreamer->add('memcacheLevelCaching:' . BooleanUtil::boolToString(MEMCACHE_ON)); InstallUtil::autoBuildDatabase($messageLogger); $endTime = microtime(true); $messageStreamer->add(Zurmo::t('InstallModule', 'Total autobuild time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3)))); if (SHOW_QUERY_DATA) { $messageStreamer->add(PageView::getTotalAndDuplicateQueryCountContent()); $messageStreamer->add(PageView::makeNonHtmlDuplicateCountAndQueryContent()); } $messageStreamer->add(Zurmo::t('InstallModule', 'Database schema creation complete.')); $messageStreamer->add(Zurmo::t('InstallModule', 'Rebuilding Permissions.')); ReadPermissionsOptimizationUtil::rebuild(); $messageStreamer->add(Zurmo::t('InstallModule', 'Freezing database.')); InstallUtil::freezeDatabase(); $messageStreamer->add(Zurmo::t('InstallModule', 'Writing Configuration File.')); InstallUtil::writeConfiguration(INSTANCE_ROOT, $form->databaseType, $form->databaseHostname, $form->databaseName, $form->databaseUsername, $form->databasePassword, $form->databasePort, $form->memcacheHostname, (int) $form->memcachePortNumber, true, Yii::app()->language, $perInstanceFilename, $debugFilename, $form->hostInfo, $form->scriptUrl, $form->submitCrashToSentry); $messageStreamer->add(Zurmo::t('InstallModule', 'Setting up default data.')); DefaultDataUtil::load($messageLogger); Yii::app()->custom->runAfterInstallationDefaultDataLoad($messageLogger); // Send notification to super admin to delete test.php file in case if this // installation is used in production mode. $message = new NotificationMessage(); $message->textContent = Zurmo::t('InstallModule', 'If this website is in production mode, please remove the app/test.php file.'); $rules = new RemoveApiTestEntryScriptFileNotificationRules(); NotificationsUtil::submit($message, $rules); // If minify is disabled, inform user that they should fix issues and enable minify $setIncludePathServiceHelper = new SetIncludePathServiceHelper(); if (!$setIncludePathServiceHelper->runCheckAndGetIfSuccessful()) { $message = new NotificationMessage(); $message->textContent = Zurmo::t('InstallModule', 'Minify has been disabled due to a system issue. Try to resolve the problem and re-enable Minify.'); $rules = new EnableMinifyNotificationRules(); NotificationsUtil::submit($message, $rules); } InstallUtil::setZurmoTokenAndWriteToPerInstanceFile(INSTANCE_ROOT); ZurmoPasswordSecurityUtil::setPasswordSaltAndWriteToPerInstanceFile(INSTANCE_ROOT); $messageStreamer->add(Zurmo::t('InstallModule', 'Installation Complete.')); }
public static function suite() { global $argv, $freeze; PhpUnitServiceUtil::checkVersion(); $usage = "\n" . " Usage: phpunit [phpunit options] TestSuite.php <All|Framework|Misc|moduleName|TestClassName> [custom options]\n" . "\n" . " All Run all tests.\n" . " Framework Run the tests in app/protected/extensions/framework/tests/unit.\n" . " Misc Run the tests in app/protected/tests/unit.\n" . " moduleName Run the tests in app/protected/modules/moduleName/tests/unit.\n" . " TestClassName Run the tests in TestClassName.php, wherever that happens to be.\n" . "\n" . " Custom Options:\n" . "\n" . " --only-walkthroughs For the specified test, only includes tests under a walkthroughs directory.\n" . " --exclude-walkthroughs For the specified test, exclude tests under a walkthroughs directory.\n" . " --only-benchmarks For the specified test, only includes tests under a benchmarks directory.\n" . " --exclude-benchmarks For the specified test, exclude tests under a benchmarks directory.\n" . " --reuse-schema Reload a previously auto build database. (Will auto build if there is no\n" . " previous one. The auto built schema is dumped to the system temp dir in\n" . " autobuild.sql.)\n" . " --no-freeze Don't auto build and freeze the database.\n" . "\n" . " Examples:\n" . "\n" . " phpunit --verbose TestSuite.php accounts (Run the tests in the Accounts module.)\n" . " phpunit TestSuite.php RedBeanModelTest (Run the tests in RedBeanModelTest.php.)\n" . "\n" . " Note:\n" . "\n" . " Framework and Misc tests run only when -no-freeze is specified.\n" . "\n" . " To run specific tests use the phpunit --filter <regex> option.\n" . " phpunit has its own options. Check phpunit --help.\n\n"; // Not Coding Standard $onlyWalkthroughs = self::customOptionSet('--only-walkthroughs', $argv); $excludeWalkthroughs = self::customOptionSet('--exclude-walkthroughs', $argv); $onlyBenchmarks = self::customOptionSet('--only-benchmarks', $argv); $excludeBenchmarks = self::customOptionSet('--exclude-benchmarks', $argv); $reuse = self::customOptionSet('--reuse-schema', $argv); $freeze = !self::customOptionSet('--no-freeze', $argv); if ($freeze == true && FORCE_NO_FREEZE == true) { echo "\n\nBecause forceNoFreeze is set to TRUE in debugTest, you cannot run unit tests in frozen mode\n\n"; // Not Coding Standard exit; } if ($argv[count($argv) - 2] != 'TestSuite.php') { echo $usage; exit; } if ($onlyWalkthroughs && $onlyBenchmarks) { echo $usage; echo "It doesn't have sense to select both \"--only-walkthroughs\" and \"--only-benchmarks\" options. \n\n"; exit; } $whatToTest = $argv[count($argv) - 1]; $includeUnitTests = !$onlyWalkthroughs && !$onlyBenchmarks; $includeWalkthroughs = !$excludeWalkthroughs && !$onlyBenchmarks; $includeBenchmarks = !$excludeBenchmarks && !$onlyWalkthroughs; echo "Testing with database: '" . Yii::app()->db->connectionString . '\', ' . 'username: \'' . Yii::app()->db->username . "'.\n"; if ($freeze && !$reuse) { if (!is_writable(sys_get_temp_dir())) { echo "\n\nTemp directory must be writable to store reusable schema\n"; // Not Coding Standard echo "Temp directory: " . sys_get_temp_dir() . "\n\n"; // Not Coding Standard exit; } InstallUtil::connectToDatabaseWithConnectionString(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); echo "Auto building database schema...\n"; InstallUtil::dropAllTables(); Yii::app()->user->userModel = InstallUtil::createSuperUser('super', 'super'); $messageLogger = new MessageLogger(); InstallUtil::autoBuildDatabase($messageLogger); $messageLogger->printMessages(); ReadPermissionsOptimizationUtil::rebuild(); assert('RedBeanDatabase::isSetup()'); echo "Saving auto built schema...\n"; $schemaFile = sys_get_temp_dir() . '/autobuilt.sql'; $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches); // Not Coding Standard assert('$success == 1'); $databaseName = $matches[1]; $systemOutput = system('mysqldump -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' ' . $databaseName . " > {$schemaFile}"); if ($systemOutput != null) { echo 'Dumping schema using system command. Output: ' . $systemOutput . "\n\n"; } InstallUtil::close(); echo "Database closed.\n"; assert('!RedBeanDatabase::isSetup()'); } $suite = new PHPUnit_Framework_TestSuite(); $suite->setName("{$whatToTest} Tests"); if (!$freeze) { self::buildAndAddSuiteFromDirectory($suite, 'Framework', COMMON_ROOT . '/protected/core/tests/unit', $whatToTest, true, false, $includeBenchmarks); } $moduleDirectoryName = COMMON_ROOT . '/protected/modules'; if (is_dir($moduleDirectoryName)) { $moduleNames = scandir($moduleDirectoryName); foreach ($moduleNames as $moduleName) { if ($moduleName != '.' && $moduleName != '..') { $moduleUnitTestDirectoryName = "{$moduleDirectoryName}/{$moduleName}/tests/unit"; self::buildAndAddSuiteFromDirectory($suite, $moduleName, $moduleUnitTestDirectoryName, $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks); } } } if (!$freeze) { self::buildAndAddSuiteFromDirectory($suite, 'Misc', COMMON_ROOT . '/protected/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks); self::buildAndAddSuiteFromDirectory($suite, 'Commands', COMMON_ROOT . '/protected/commands/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks); //////////////////////////////////////////////////////////////////////////////// // Temporary - See Readme.txt in the notSupposedToBeHere directory. self::buildAndAddSuiteFromDirectory($suite, 'BadDependencies', COMMON_ROOT . '/protected/tests/unit/notSupposedToBeHere', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks); //////////////////////////////////////////////////////////////////////////////// } if ($suite->count() == 0) { echo $usage; echo " No tests found for '{$whatToTest}'.\n\n"; exit; } return $suite; }