From 360272956484b790ac779a14ed5abdd317b50980 Mon Sep 17 00:00:00 2001 From: Nicole Cordes <typo3@cordes.co> Date: Wed, 2 Apr 2014 00:53:33 +0200 Subject: [PATCH] [BUGFIX] Improve Windows support for functional tests 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 | 4 +-- typo3/sysext/core/Build/FunctionalTests.xml | 2 +- .../core/Build/FunctionalTestsBootstrap.php | 1 + typo3/sysext/core/Build/UnitTests.xml | 4 +-- .../sysext/core/Tests/FunctionalTestCase.php | 30 +++++++++++++++---- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59219b8e87fc..4ee44be4cfb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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"; diff --git a/typo3/sysext/core/Build/FunctionalTests.xml b/typo3/sysext/core/Build/FunctionalTests.xml index 1705aa37fa26..ee538fd09786 100644 --- a/typo3/sysext/core/Build/FunctionalTests.xml +++ b/typo3/sysext/core/Build/FunctionalTests.xml @@ -11,7 +11,7 @@ backupGlobals="true" backupStaticAttributes="false" bootstrap="FunctionalTestsBootstrap.php" - colors="true" + colors="false" convertErrorsToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" diff --git a/typo3/sysext/core/Build/FunctionalTestsBootstrap.php b/typo3/sysext/core/Build/FunctionalTestsBootstrap.php index 8fca56f67cb4..cdecd3902364 100644 --- a/typo3/sysext/core/Build/FunctionalTestsBootstrap.php +++ b/typo3/sysext/core/Build/FunctionalTestsBootstrap.php @@ -53,6 +53,7 @@ if (getenv('TYPO3_PATH_WEB')) { } else { $webRoot = getcwd() . '/'; } +$webRoot = strtr($webRoot, '\\', '/'); if (!defined('ORIGINAL_ROOT')) { define('ORIGINAL_ROOT', $webRoot); diff --git a/typo3/sysext/core/Build/UnitTests.xml b/typo3/sysext/core/Build/UnitTests.xml index 49105b8906c7..7518119a06a5 100644 --- a/typo3/sysext/core/Build/UnitTests.xml +++ b/typo3/sysext/core/Build/UnitTests.xml @@ -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> diff --git a/typo3/sysext/core/Tests/FunctionalTestCase.php b/typo3/sysext/core/Tests/FunctionalTestCase.php index 61c5bdead0ce..6b5d0e77f4ba 100644 --- a/typo3/sysext/core/Tests/FunctionalTestCase.php +++ b/typo3/sysext/core/Tests/FunctionalTestCase.php @@ -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); -- GitLab