Permalink
Browse files

changed Travis to use out own PHPUnit to avoid conflicts

  • Loading branch information...
fabpot committed Sep 10, 2016
1 parent 6d771a3 commit 8d1d13a3860b1b6f1e4a224af1d08264e9eeae5c
Showing with 222 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +12 −5 .travis.yml
  3. +209 −0 phpunit
View
@@ -2,3 +2,4 @@ composer.phar
cache
build
vendor
+/.phpunit
View
@@ -15,14 +15,24 @@ matrix:
- php: 5.6
env: BLACKFIRE=on
- php: 7.0
- - php: hhvm
+ # Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
+ - php: hhvm-3.12
+ sudo: required
+ dist: trusty
+ group: edge
+ fast_finish: true
sudo: false
cache:
- $HOME/.composer/cache/files
+ - .phpunit
before_install:
+ - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi
+ - echo memory_limit = -1 >> $INI_FILE
+ - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
+ - ./phpunit install
- |
if [[ "$BLACKFIRE" = "on" ]]; then
openssl aes-256-cbc -K $encrypted_16ab3ffdcd52_key -iv $encrypted_16ab3ffdcd52_iv -in .blackfire.travis.ini.enc -out ~/.blackfire.ini -d
@@ -32,9 +42,6 @@ before_install:
- if [[ "$TWIG" = "2.x" ]]; then sed -i 's/~1.20|~2.0/~2.0/g' composer.json; composer update; fi
- if [[ "$TWIG" = "1.x" ]]; then sed -i 's/~1.20|~2.0/~1.20/g' composer.json; composer update; fi
-install:
- - travis_retry composer install
-
before_script:
- phpenv config-rm xdebug.ini || true
- |
@@ -45,4 +52,4 @@ before_script:
fi
script:
- - phpunit
+ - ./phpunit
View
209 phpunit
@@ -0,0 +1,209 @@
+#!/usr/bin/env php
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+// Please update when phpunit needs to be reinstalled with fresh deps:
+// Cache-Id-Version: 2016-06-29 13:45 UTC
+
+error_reporting(-1);
+
+// PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+
+$PHPUNIT_VERSION = PHP_VERSION_ID >= 50600 ? '5.1' : '4.8';
+$PHPUNIT_DIR = __DIR__.'/.phpunit';
+$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
+$PHP = escapeshellarg($PHP);
+if ('phpdbg' === PHP_SAPI) {
+ $PHP .= ' -qrr';
+}
+
+$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
+ ? $PHP.' '.escapeshellarg($COMPOSER)
+ : 'composer';
+
+if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
+ // Build a standalone phpunit without symfony/yaml
+
+ $oldPwd = getcwd();
+ @mkdir($PHPUNIT_DIR);
+ chdir($PHPUNIT_DIR);
+ if (file_exists("phpunit-$PHPUNIT_VERSION")) {
+ passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
+ }
+ if (extension_loaded('openssl') && ini_get('allow_url_fopen')) {
+ stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
+ } else {
+ @unlink("$PHPUNIT_VERSION.zip");
+ passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
+ }
+ $zip = new ZipArchive();
+ $zip->open("$PHPUNIT_VERSION.zip");
+ $zip->extractTo(getcwd());
+ $zip->close();
+ chdir("phpunit-$PHPUNIT_VERSION");
+ passthru("$COMPOSER remove --no-update phpspec/prophecy");
+ passthru("$COMPOSER remove --no-update symfony/yaml");
+ if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
+ passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
+ }
+ passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.2@dev\"");
+ passthru("$COMPOSER install --prefer-dist --no-progress --ansi", $exit);
+ if ($exit) {
+ exit($exit);
+ }
+ file_put_contents('phpunit', <<<'EOPHP'
+<?php
+
+define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
+
+$loader = require PHPUNIT_COMPOSER_INSTALL;
+
+if (getenv('SYMFONY_PHPUNIT_OVERLOAD') && file_exists(__DIR__.'/../../src/Symfony/Bridge/PhpUnit')) {
+ $loader->addPsr4('Symfony\\Bridge\\PhpUnit\\', array('src/Symfony/Bridge/PhpUnit'), true);
+}
+unset($loader);
+Symfony\Bridge\PhpUnit\TextUI\Command::main();
+
+EOPHP
+ );
+ chdir('..');
+ file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__));
+ chdir($oldPwd);
+
+}
+
+$cmd = array_map('escapeshellarg', $argv);
+$exit = 0;
+
+if (isset($argv[1]) && 'symfony' === $argv[1]) {
+ array_shift($cmd);
+}
+
+$cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
+$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
+
+if ('\\' === DIRECTORY_SEPARATOR) {
+ $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
+} else {
+ $cmd .= '%2$s';
+}
+
+if (isset($argv[1]) && 'symfony' === $argv[1]) {
+ // Find Symfony components in plain php for Windows portability
+
+ $oldPwd = getcwd();
+ chdir(__DIR__);
+ $finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
+ $finder = new RecursiveIteratorIterator($finder);
+ $finder->setMaxDepth(3);
+
+ $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
+ $runningProcs = array();
+
+ foreach ($finder as $file => $fileInfo) {
+ if ('phpunit.xml.dist' === $file) {
+ $component = dirname($fileInfo->getPathname());
+
+ // Run phpunit tests in parallel
+
+ if ($skippedTests) {
+ putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
+ }
+
+ $c = escapeshellarg($component);
+
+ if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
+ $runningProcs[$component] = $proc;
+ } else {
+ $exit = 1;
+ echo "\033[41mKO\033[0m $component\n\n";
+ }
+ }
+ }
+ chdir($oldPwd);
+
+ // Fixes for colors support on appveyor
+ // See https://github.com/appveyor/ci/issues/373
+ $colorFixes = array(
+ array("S\033[0m\033[0m\033[36m\033[1mS", "E\033[0m\033[0m\033[31m\033[1mE", "I\033[0m\033[0m\033[33m\033[1mI", "F\033[0m\033[0m\033[41m\033[37mF"),
+ array("SS", "EE", "II", "FF"),
+ );
+ $colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
+ $colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
+
+ while ($runningProcs) {
+ usleep(300000);
+ $terminatedProcs = array();
+ foreach ($runningProcs as $component => $proc) {
+ $procStatus = proc_get_status($proc);
+ if (!$procStatus['running']) {
+ $terminatedProcs[$component] = $procStatus['exitcode'];
+ unset($runningProcs[$component]);
+ proc_close($proc);
+ }
+ }
+
+ foreach ($terminatedProcs as $component => $procStatus) {
+ foreach (array('out', 'err') as $file) {
+ $file = "$component/phpunit.std$file";
+
+ if ('\\' === DIRECTORY_SEPARATOR) {
+ $h = fopen($file, 'rb');
+ while (false !== $line = fgets($h)) {
+ echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
+ '/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
+ "$1m\033[$2$3$4$4",
+ $line
+ ));
+ }
+ fclose($h);
+ } else {
+ readfile($file);
+ }
+ unlink($file);
+ }
+
+ // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
+ // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
+ // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
+ // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
+ if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
+ $exit = $procStatus;
+ echo "\033[41mKO\033[0m $component\n\n";
+ } else {
+ echo "\033[32mOK\033[0m $component\n\n";
+ }
+ }
+ }
+} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
+ // Run regular phpunit in a subprocess
+
+ $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
+ if ($proc = proc_open(sprintf($cmd, '', ' 2> '.escapeshellarg($errFile)), array(1 => array('pipe', 'w')), $pipes)) {
+ stream_copy_to_stream($pipes[1], STDOUT);
+ fclose($pipes[1]);
+ $exit = proc_close($proc);
+
+ readfile($errFile);
+ unlink($errFile);
+ }
+
+ if (!file_exists($component = array_pop($argv))) {
+ $component = basename(getcwd());
+ }
+
+ if ($exit) {
+ echo "\033[41mKO\033[0m $component\n\n";
+ } else {
+ echo "\033[32mOK\033[0m $component\n\n";
+ }
+}
+
+exit($exit);

0 comments on commit 8d1d13a

Please sign in to comment.