当前位置: 首页>>代码示例>>PHP>>正文


PHP InstallUtil::connectToDatabaseWithConnectionString方法代码示例

本文整理汇总了PHP中InstallUtil::connectToDatabaseWithConnectionString方法的典型用法代码示例。如果您正苦于以下问题:PHP InstallUtil::connectToDatabaseWithConnectionString方法的具体用法?PHP InstallUtil::connectToDatabaseWithConnectionString怎么用?PHP InstallUtil::connectToDatabaseWithConnectionString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InstallUtil的用法示例。


在下文中一共展示了InstallUtil::connectToDatabaseWithConnectionString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: suite

 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;
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:92,代码来源:TestSuite.php


注:本文中的InstallUtil::connectToDatabaseWithConnectionString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。