[BUGFIX] Improve functional test execution on Windows system 17/36517/3
authorNicole Cordes <typo3@cordes.co>
Sat, 31 Jan 2015 15:18:52 +0000 (16:18 +0100)
committerNicole Cordes <typo3@cordes.co>
Sat, 31 Jan 2015 16:17:19 +0000 (17:17 +0100)
On Windows systems you can execute several commands using '&' like
set typo3DatabaseUsername=root & set typo3DatabasePassword=root.
Unfortunately Windows sets those parameter with a trailing space. This
causes database connections not to work. Therefore the patch adds a trim
on getting system environment variables for database credentials for
functional tests.

Furthermore the PHP versions on Windows throw a warning on setting the
database name when the connection is closed. The warning is caught by
PHPUnit but the database tables aren't initialized correctly. This patch
adds an '@' to mute the warning.

Releases: master, 6.2
Resolves: #64680
Change-Id: If649b5bd440a3bd504f028a3c9c96c9d294d380c
Reviewed-on: http://review.typo3.org/36517
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php

index def55ed..0c570cd 100644 (file)
@@ -264,12 +264,12 @@ class FunctionalTestCaseBootstrapUtility {
         * @return void
         */
        protected function setUpLocalConfiguration(array $configurationToMerge) {
-               $databaseName = getenv('typo3DatabaseName');
-               $databaseHost = getenv('typo3DatabaseHost');
-               $databaseUsername = getenv('typo3DatabaseUsername');
-               $databasePassword = getenv('typo3DatabasePassword');
-               $databasePort = getenv('typo3DatabasePort');
-               $databaseSocket = getenv('typo3DatabaseSocket');
+               $databaseName = trim(getenv('typo3DatabaseName'));
+               $databaseHost = trim(getenv('typo3DatabaseHost'));
+               $databaseUsername = trim(getenv('typo3DatabaseUsername'));
+               $databasePassword = trim(getenv('typo3DatabasePassword'));
+               $databasePort = trim(getenv('typo3DatabasePort'));
+               $databaseSocket = trim(getenv('typo3DatabaseSocket'));
                if ($databaseName || $databaseHost || $databaseUsername || $databasePassword || $databasePort || $databaseSocket) {
                        // Try to get database credentials from environment variables first
                        $originalConfigurationArray = array(
@@ -491,7 +491,8 @@ class FunctionalTestCaseBootstrapUtility {
                }
                $this->databaseName = $GLOBALS['TYPO3_CONF_VARS']['DB']['database'];
                $database->setDatabaseName($this->databaseName);
-               $database->sql_select_db($this->databaseName);
+               // On windows, this still works, but throws a warning, which we need to discard.
+               @$database->sql_select_db($this->databaseName);
                foreach ($database->admin_get_tables() as $table) {
                        $database->admin_query('TRUNCATE ' . $table['Name'] . ';');
                }