[BUGFIX] Improve Windows support for functional tests 57/29057/5
authorNicole Cordes <typo3@cordes.co>
Tue, 1 Apr 2014 22:53:33 +0000 (00:53 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 3 May 2014 18:10:54 +0000 (20:10 +0200)
Solve some issues running function tests on windows OS

* Disable colors, this is hardly supported in windows CLI,
  enable in .travis.yml explicitly
* Convert the web root path into a unix styled one to prevent a
  mix between backslashes and forward slashes
* Improve finding the PHP binary as the system constants PHP_BINDIR
  is defined with "C:\php" even if PHP is installed in a different folder
* Improves command line argument escaping for special windows
  requirements.

Resolves: #57524
Releases: 6.2
Change-Id: I80b1652e35b816f8ca93929950d014c45b9535d1
Reviewed-on: https://review.typo3.org/29057
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
.travis.yml
typo3/sysext/core/Build/FunctionalTests.xml
typo3/sysext/core/Build/FunctionalTestsBootstrap.php
typo3/sysext/core/Build/UnitTests.xml
typo3/sysext/core/Tests/FunctionalTestCase.php

index 59219b8..4ee44be 100644 (file)
@@ -40,14 +40,14 @@ script:
   - >
     echo;
     echo "Running unit tests";
-    ./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml
+    ./bin/phpunit --colors -c typo3/sysext/core/Build/UnitTests.xml
   - >
     echo;
     export typo3DatabaseName="typo3";
     export typo3DatabaseHost="localhost";
     export typo3DatabaseUsername="root";
     export typo3DatabasePassword="";
-    grep directory typo3/sysext/core/Build/FunctionalTests.xml | awk '{print $1}' | sed 's%<directory>\(\.\./\)*\(typo3/sysext.*\)</directory>$%\2%g' | parallel --gnu 'echo; echo "Running functional {} tests"; ./bin/phpunit -c typo3/sysext/core/Build/FunctionalTests.xml {}'
+    grep directory typo3/sysext/core/Build/FunctionalTests.xml | awk '{print $1}' | sed 's%<directory>\(\.\./\)*\(typo3/sysext.*\)</directory>$%\2%g' | parallel --gnu 'echo; echo "Running functional {} tests"; ./bin/phpunit --colors -c typo3/sysext/core/Build/FunctionalTests.xml {}'
   - >
     echo;
     echo "Running php lint";
index 1705aa3..ee538fd 100644 (file)
@@ -11,7 +11,7 @@
        backupGlobals="true"
        backupStaticAttributes="false"
        bootstrap="FunctionalTestsBootstrap.php"
-       colors="true"
+       colors="false"
        convertErrorsToExceptions="true"
        convertWarningsToExceptions="true"
        forceCoversAnnotation="false"
index 8fca56f..cdecd39 100644 (file)
@@ -53,6 +53,7 @@ if (getenv('TYPO3_PATH_WEB')) {
 } else {
        $webRoot = getcwd() . '/';
 }
+$webRoot = strtr($webRoot, '\\', '/');
 
 if (!defined('ORIGINAL_ROOT')) {
        define('ORIGINAL_ROOT', $webRoot);
index 49105b8..7518119 100644 (file)
@@ -2,7 +2,7 @@
        backupGlobals="true"
        backupStaticAttributes="false"
        bootstrap="UnitTestsBootstrap.php"
-       colors="true"
+       colors="false"
        convertErrorsToExceptions="true"
        convertWarningsToExceptions="true"
        forceCoversAnnotation="false"
@@ -82,4 +82,4 @@
                        <directory>../../../../typo3/sysext/core/Tests/Integrity/</directory>
                </testsuite>
        </testsuites>
-</phpunit>
\ No newline at end of file
+</phpunit>
index 61c5bde..6b5d0e7 100644 (file)
@@ -345,10 +345,20 @@ abstract class FunctionalTestCase extends BaseTestCase {
                $pageId = (int)$pageId;
                $languageId = (int)$languageId;
 
+               $phpExecutable = 'php';
                if (defined('PHP_BINARY')) {
                        $phpExecutable = PHP_BINARY;
-               } else {
+               } elseif (TYPO3_OS !== 'WIN' && defined('PHP_BINDIR')) {
                        $phpExecutable = rtrim(PHP_BINDIR, '/') . '/php';
+               } else {
+                       foreach(explode(';', $_SERVER['Path']) as $path) {
+                               $path = rtrim(strtr($path, '\\', '/'), '/') . '/';
+                               $phpFile = 'php' . (TYPO3_OS === 'WIN' ? '.exe' : '');
+                               if (file_exists($path . $phpFile) && is_file($path . $phpFile)) {
+                                       $phpExecutable = $path . $phpFile;
+                                       break;
+                               }
+                       }
                }
 
                $additionalParameter = '';
@@ -365,11 +375,19 @@ abstract class FunctionalTestCase extends BaseTestCase {
                        'requestUrl' => 'http://localhost/?id=' . $pageId . '&L=' . $languageId . $additionalParameter,
                );
 
-               $commandParts = array(
-                       escapeshellcmd($phpExecutable),
-                       escapeshellarg(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Framework/Scripts/Request.php'),
-                       escapeshellarg(json_encode($arguments)),
-               );
+               if (TYPO3_OS !== 'WIN') {
+                       $commandParts = array(
+                               escapeshellcmd($phpExecutable),
+                               escapeshellarg(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Framework/Scripts/Request.php'),
+                               escapeshellarg(json_encode($arguments)),
+                       );
+               } else {
+                       $commandParts = array(
+                               escapeshellcmd($phpExecutable),
+                               escapeshellarg(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Framework/Scripts/Request.php'),
+                               strtr(escapeshellarg(strtr(json_encode($arguments), array('&' => '^&', '"' => '"""'))), '   ', '"""'),
+                       );
+               }
 
                $command = trim(implode(' ', $commandParts));
                $response = shell_exec($command);