Skip to content

Commit

Permalink
Add return-types with help from DebugClassLoader in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 26, 2019
1 parent d887a0d commit 528083d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
45 changes: 45 additions & 0 deletions .github/patch-types.php
@@ -0,0 +1,45 @@
<?php

if (false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=force=1&php71-compat=0');
}

require __DIR__.'/../.phpunit/phpunit-8.3-0/vendor/autoload.php';

file_put_contents(__DIR__.'/../vendor/autoload.php', preg_replace('/^return (Composer.*);/m', <<<'EOTXT'
$loader = \1;
$loader->addClassMap(['Symfony\Component\Debug\Exception\FlattenException' => \dirname(__DIR__).'/src/Symfony/Component/Debug/Exception/FlattenException.php']);
return $loader;
EOTXT
, file_get_contents(__DIR__.'/../vendor/autoload.php')));

$loader = require __DIR__.'/../vendor/autoload.php';

Symfony\Component\ErrorHandler\DebugClassLoader::enable();

foreach ($loader->getClassMap() as $class => $file) {
switch (true) {
case false !== strpos(realpath($file), '/vendor/'):
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
case false !== strpos($file, '/src/Symfony/Component/Debug/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ParentNotExists.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/'):
case false !== strpos($file, '/src/Symfony/Component/ErrorHandler/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php'):
case false !== strpos($file, '/src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectOuter.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/Php74.php') && \PHP_VERSION_ID < 70400:
continue 2;
}

class_exists($class);
}

Symfony\Component\ErrorHandler\DebugClassLoader::disable();
21 changes: 15 additions & 6 deletions .travis.yml
Expand Up @@ -26,7 +26,7 @@ env:
matrix:
include:
- php: 7.1
env: php_extra="7.2"
env: php_extra="7.2 7.4snapshot"
- php: 7.3
env: deps=high
- php: 7.4snapshot
Expand Down Expand Up @@ -79,10 +79,8 @@ before_install:
export COMPONENTS=$(find src/Symfony -mindepth 2 -type f -name phpunit.xml.dist -printf '%h\n')
find ~/.phpenv -name xdebug.ini -delete
if [[ $TRAVIS_PHP_VERSION = 7.4* && $deps ]]; then
if [[ $TRAVIS_PHP_VERSION = 7.4* ]]; then
export PHPUNIT_X="$PHPUNIT_X,issue-32995"
elif [[ $TRAVIS_PHP_VERSION = 7.4* ]]; then
export PHPUNIT_X="$PHPUNIT --group issue-32995"
fi
nanoseconds () {
Expand Down Expand Up @@ -150,7 +148,7 @@ before_install:
- |
# php.ini configuration
for PHP in $TRAVIS_PHP_VERSION $php_extra; do
phpenv global $PHP 2>/dev/null || (cd / && wget https://s3.amazonaws.com/travis-php-archives/binaries/ubuntu/14.04/x86_64/php-$PHP.tar.bz2 -O - | tar -xj)
phpenv global $PHP 2>/dev/null || (cd / && wget https://storage.googleapis.com/travis-ci-language-archives/php/binaries/ubuntu/16.04/x86_64/php-$PHP.tar.bz2 -O - | tar -xj)
INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini
echo date.timezone = Europe/Paris >> $INI
echo memory_limit = -1 >> $INI
Expand Down Expand Up @@ -262,7 +260,7 @@ install:
run_tests () {
set -e
export PHP=$1
if [[ $PHP != $TRAVIS_PHP_VERSION && $TRAVIS_PULL_REQUEST != false ]]; then
if [[ $PHP != 7.4* && $PHP != $TRAVIS_PHP_VERSION && $TRAVIS_PULL_REQUEST != false ]]; then
echo -e "\\n\\e[1;34mIntermediate PHP version $PHP is skipped for pull requests.\\e[0m"
break
fi
Expand All @@ -279,6 +277,17 @@ install:
echo "$COMPONENTS" | parallel --gnu "tfold {} 'cd {} && ([ -e composer.lock ] && ${COMPOSER_UP/update/install} || $COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'"
echo "$COMPONENTS" | xargs -n1 -I{} tar --append -f ~/php-ext/composer-lowest.lock.tar {}/composer.lock
else
if [[ $PHP = 7.4* ]]; then
# add return types before running the test suite
rm vendor/symfony/contracts -Rf
ln -sd $(realpath src/Symfony/Contracts) vendor/symfony/contracts
sed -i 's/"\*\*\/Tests\/"//' composer.json
composer install --optimize-autoloader
php .github/patch-types.php
php .github/patch-types.php # ensure the script is idempotent
export PHPUNIT_X="$PHPUNIT_X,issue-32995,legacy"
fi
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
tfold src/Symfony/Component/Console.tty $PHPUNIT src/Symfony/Component/Console --group tty
if [[ $PHP = ${MIN_PHP%.*} ]]; then
Expand Down

0 comments on commit 528083d

Please sign in to comment.