[TASK] Use composer for unit and functional tests in travis 95/29495/7
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 15 Apr 2014 23:05:38 +0000 (01:05 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 19 Apr 2014 21:23:27 +0000 (23:23 +0200)
The patch uses composer based dependency handling and other
stuff pushing travis-ci tests to the next level:

- phpunit registered as "dev" requirement in composer.json
- vfsStream registered as "dev" requirement in composer.json
- cms-composer-installers is not released stable and adapted
  in composer.json for successful dependency resolving via
  composer
- cloning travis-integration repository is obsolete by inlining
  scripts in .travis.yml
- cloning ext:phpunit is obsolete, native phpunit by composer
  is used now
- it is possible to set functional test suite database credentials
  with environment variables, used in .travis.yml
- redis cache backend tests are enabled on travis-ci again
- use existing php modules of travis-ci environment speeds up build

With phpunit from composer, the command to run tests is
./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml
More documentation about that can be found at
http://wiki.typo3.org/Unit_Testing_TYPO3

Change-Id: I4d524e8e0249ca22f34fc48b7209d60d72e5e921
Resolves: #57971
Related: #51436
Releases: 6.2
Reviewed-on: https://review.typo3.org/29495
Reviewed-by: Wouter Wolters
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
.travis.yml
composer.json
typo3/sysext/core/Build/FunctionalTestsBootstrap.php
typo3/sysext/core/Build/UnitTestsBootstrap.php
typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php

index 9bc3f94..59219b8 100644 (file)
@@ -8,27 +8,52 @@ php:
 env:
   - DB=mysql
 
+services:
+  - memcached
+  - redis-server
+
 notifications:
   irc:
     - "irc.freenode.net#typo3-cms"
   email:
     - typo3-team-core@lists.typo3.org
 
-services:
-  - memcached
-
 before_script:
+  - >
+    if [[ "$TRAVIS_PHP_VERSION" != "5.5" ]]; then
+        echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
+        echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
+        echo "apc.slam_defense=0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
+    fi
+  - >
+    if [[ "$TRAVIS_PHP_VERSION" != "5.5" ]]; then
+        pecl install igbinary > /dev/null;
+    fi
+  - echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
+  - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
   - sudo apt-get install parallel
-  - git clone --single-branch --branch master --depth 1 git://github.com/typo3-ci/TYPO3-Travis-Integration.git build-environment
-  - source build-environment/install-helper.sh
-  - if [[ "$TRAVIS_PHP_VERSION" == "5.3" ]]; then installPhpModule -y apc; fi
-  - if [[ "$TRAVIS_PHP_VERSION" != "5.5" ]]; then installPhpModule igbinary; fi
-  - installPhpModule -y memcache
-  - installPhpModule redis
-  - mkdir fileadmin uploads typo3temp
-  - mv build-environment/typo3conf .
-  - git clone --single-branch --branch master --depth 1 git://git.typo3.org/TYPO3CMS/Extensions/phpunit.git typo3conf/ext/phpunit/
+  - composer self-update
+  - composer --dev install
+  - mkdir -p uploads typo3temp typo3conf/ext
 
 script:
-  - printf "UnitTests\nLint" | parallel --gnu --keep-order 'echo "Running {}"; ./build-environment/execute{}.sh'
-  - grep directory typo3/sysext/core/Build/FunctionalTests.xml | sed 's#[      ]*<directory>\.\./\.\./\.\./\.\./\(typo3/sysext.*\)</directory>$#\1#g' | parallel --gnu 'echo "Running {} tests"; ./typo3conf/ext/phpunit/Composer/vendor/bin/phpunit -c typo3/sysext/core/Build/FunctionalTests.xml {}'
+  - >
+    echo;
+    echo "Running unit tests";
+    ./bin/phpunit -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 {}'
+  - >
+    echo;
+    echo "Running php lint";
+    /bin/bash -c "
+        if ! find typo3/ -name \*.php | parallel --gnu 'php -l {}' > /tmp/errors 2>&1; then
+            grep -v \"No syntax errors detected in\" /tmp/errors;
+            exit 99;
+        fi
+    "
\ No newline at end of file
index b5c7557..2379aa5 100644 (file)
                "ext-pcre": "*",
                "ext-session": "*",
                "ext-xml": "*",
-               "typo3/cms-composer-installers": "*"
+               "typo3/cms-composer-installers": "1.1.*@dev"
+       },
+       "require-dev": {
+               "mikey179/vfsStream": "1.3.*@dev",
+               "phpunit/phpunit": "3.7.*"
        },
        "suggest": {
                "ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
index b5d9e11..8fca56f 100644 (file)
@@ -54,13 +54,6 @@ if (getenv('TYPO3_PATH_WEB')) {
        $webRoot = getcwd() . '/';
 }
 
-/**
- * Fail if configuration is not found
- */
-if (!file_exists($webRoot . 'typo3conf/LocalConfiguration.php')) {
-       throw new \Exception('TYPO3 web root not found. Call PHPUnit from that directory or set TYPO3_PATH_WEB to it.');
-}
-
 if (!defined('ORIGINAL_ROOT')) {
        define('ORIGINAL_ROOT', $webRoot);
 }
index 443c00a..6a974d7 100644 (file)
@@ -69,13 +69,6 @@ if (getenv('TYPO3_PATH_WEB')) {
 }
 
 /**
- * Fail if configuration is not found
- */
-if (!file_exists($webRoot . 'typo3conf/LocalConfiguration.php')) {
-       throw new \Exception('TYPO3 web root not found. Call PHPUnit from that directory or set TYPO3_PATH_WEB to it.');
-}
-
-/**
  * Define basic TYPO3 constants
  */
 define('PATH_site', $webRoot);
@@ -107,6 +100,3 @@ $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
        ->initializeCachingFramework()
        ->initializeClassLoaderCaches()
        ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\UnitTestPackageManager');
-
-require PATH_site . 'typo3conf/ext/phpunit/Composer/vendor/autoload.php';
-require PATH_site . 'typo3conf/ext/phpunit/Migrations/vfsStream.php';
index ad16ee7..c697f72 100644 (file)
@@ -275,7 +275,42 @@ class FunctionalTestCaseBootstrapUtility {
         * @return void
         */
        protected function setUpLocalConfiguration(array $configurationToMerge) {
-               $originalConfigurationArray = require ORIGINAL_ROOT . 'typo3conf/LocalConfiguration.php';
+               $databaseName = getenv('typo3DatabaseName');
+               $databaseHost = getenv('typo3DatabaseHost');
+               $databaseUsername = getenv('typo3DatabaseUsername');
+               $databasePassword = getenv('typo3DatabasePassword');
+               $databasePort = getenv('typo3DatabasePort');
+               if ($databaseName || $databaseHost || $databaseUsername || $databasePassword || $databasePort) {
+                       // Try to get database credentials from environment variables first
+                       $originalConfigurationArray = array(
+                               'DB' => array(),
+                       );
+                       if ($databaseName) {
+                               $originalConfigurationArray['DB']['database'] = $databaseName;
+                       }
+                       if ($databaseHost) {
+                               $originalConfigurationArray['DB']['host'] = $databaseHost;
+                       }
+                       if ($databaseUsername) {
+                               $originalConfigurationArray['DB']['username'] = $databaseUsername;
+                       }
+                       if ($databasePassword) {
+                               $originalConfigurationArray['DB']['password'] = $databasePassword;
+                       }
+                       if ($databasePort) {
+                               $originalConfigurationArray['DB']['port'] = $databasePort;
+                       }
+               } elseif (file_exists(ORIGINAL_ROOT . 'typo3conf/LocalConfiguration.php')) {
+                       // See if a LocalConfiguration file exists in "parent" instance to get db credentials from
+                       $originalConfigurationArray = require ORIGINAL_ROOT . 'typo3conf/LocalConfiguration.php';
+               } else {
+                       throw new Exception(
+                               'Database credentials for functional tests are neither set through environment'
+                               . ' variables, and can not be found in an existing LocalConfiguration file',
+                               1397406356
+                       );
+               }
+
                // Base of final LocalConfiguration is core factory configuration
                $finalConfigurationArray = require ORIGINAL_ROOT .'typo3/sysext/core/Configuration/FactoryConfiguration.php';