Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the commands to run Symfony Tests through Docker 🐳 #47102

Conversation

alexislefebvre
Copy link
Contributor

@alexislefebvre alexislefebvre commented Jul 28, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes, but only for internal development of Symfony
Deprecations? no
Tickets Fix #47032
License MIT
Doc PR symfony/symfony-docs#17080

This PR add some scripts to Composer:

  docker-build                 Build the Docker image, you can use a different version by defining “DOCKER_PHP_VERSION”, e.g. “env DOCKER_PHP_VERSION="8.1" composer docker-build”
  docker-install-dependencies  Install dependencies through Composer
  docker-run                   Base command to run Docker
  docker-tests                 Run tests, you should pass arguments, e.g. “composer docker-tests src/Symfony/Component/DependencyInjection/” for testing a specific folder or “composer docker-tests src/Symfony/” to run the whole test suite in parallel. Options for PHPUnit must be prepend with --, e.g. “composer docker-tests -- --verbose --debug src/Symfony/Component/DependencyInjection/”

They allow anyone to run tests through Docker easily, with all the benefits of Docker: the environment is independent of the system, the system dependencies can be added easily, the build is reproducible, etc.

How to use it:

$ composer docker-build
$ composer docker-install-dependencies
$ composer docker-tests src/Symfony/Component/Yaml/

(these are shortcuts to composer run-script …)

We can also specify another version of PHP:

env DOCKER_PHP_VERSION="8.1" composer docker-build

Try it:

git clone --branch add-composer-script-and-docker-for-development --single-branch \
--depth 5 -- git@github.com:alexislefebvre/symfony.git
cd symfony/
composer docker-build
composer docker-composer
composer docker-tests -- src/Symfony/Component/Yaml/

I only tested on Linux, it may not work on Windows.

Caveat: Running the whole test suite with composer run-script docker-tests crash with the output ^[[54;19R and I don't understand why. It is probably not due to a timeout from Composer since it appears before the default timeout of 5 minutes.

example with full output

$ git clone --branch add-composer-script-and-docker-for-development --single-branch \
--depth 5 -- git@github.com:alexislefebvre/symfony.git
Clonage dans 'symfony'...
remote: Enumerating objects: 12977, done.
remote: Counting objects: 100% (12977/12977), done.
remote: Compressing objects: 100% (10046/10046), done.
remote: Total 12977 (delta 5146), reused 5941 (delta 2414), pack-reused 0
Réception d'objets: 100% (12977/12977), 12.76 Mio | 13.51 Mio/s, fait.
Résolution des deltas: 100% (5146/5146), fait.
$ cd symfony/
$ composer docker-build
> docker build --tag symfony-tests .docker/
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM php:8.1-cli-alpine3.15
 ---> 6781ff42796c
Step 2/4 : RUN apk add --no-cache libxslt-dev     && docker-php-ext-configure xsl     && docker-php-ext-install xsl
 ---> Using cache
 ---> 224639ddac78
Step 3/4 : COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
 ---> Using cache
 ---> 0bf66081e129
Step 4/4 : WORKDIR /symfony
 ---> Using cache
 ---> 6d9316a0bc11
Successfully built 6d9316a0bc11
Successfully tagged symfony-tests:latest
$ composer docker-composer
> docker run --rm --tty --volume $(pwd):/symfony symfony-tests 'env' 'COMPOSER_ROOT_VERSION=6.2.x-dev' 'composer' 'update'
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 87 installs, 0 updates, 0 removals
[…]
$ composer docker-tests
> docker run --rm --tty --volume $(pwd):/symfony symfony-tests 'php' './phpunit' 'src/Symfony/Component/Yaml/'
No composer.json found in the current directory, showing available packages from packagist.org
[…]
  - Installing symfony/phpunit-bridge (dev-main): Symlinking from ../../vendor/symfony/phpunit-bridge
7 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
24 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHPUnit 9.5.21 #StandWithUkraine

Testing /symfony/src/Symfony/Component/Yaml
...............................................................  63 / 722 (  8%)
............................................................... 126 / 722 ( 17%)
............................................................... 189 / 722 ( 26%)
............................................................... 252 / 722 ( 34%)
............................................................... 315 / 722 ( 43%)
............................................................... 378 / 722 ( 52%)
............................................................... 441 / 722 ( 61%)
............................................................... 504 / 722 ( 69%)
............................................................... 567 / 722 ( 78%)
............................................................... 630 / 722 ( 87%)
............................................................... 693 / 722 ( 95%)
........S....................                                   722 / 722 (100%)

Time: 00:00.247, Memory: 22.00 MB

OK, but incomplete, skipped, or risky tests!
Tests: 722, Assertions: 1053, Skipped: 1.

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature labels Jul 28, 2022
@carsonbot carsonbot added this to the 6.2 milestone Jul 28, 2022
@carsonbot carsonbot changed the title [DX] Provide the commands to run Symfony Tests through Docker 🐳 Provide the commands to run Symfony Tests through Docker 🐳 Jul 28, 2022
composer.json Outdated Show resolved Hide resolved
@alexislefebvre alexislefebvre force-pushed the add-composer-script-and-docker-for-development branch 2 times, most recently from 8e63c60 to a5540b3 Compare July 28, 2022 17:51
.docker/Dockerfile Outdated Show resolved Hide resolved
@alexislefebvre
Copy link
Contributor Author

alexislefebvre commented Jul 29, 2022

It looks like the test testGetCurrentPosition is stealing the output and block the output of the test suite:

$ composer docker-tests -- --debug --filter="testGetCurrentPosition"
> docker run --rm --tty --user $(id --user):$(id --group) --volume $(pwd):/symfony symfony-tests 'php' './phpunit' '--debug' '--filter=testGetCurrentPosition'
PHPUnit 9.5.21 #StandWithUkraine

Testing 
Test 'Symfony\Component\Console\Tests\CursorTest::testGetCurrentPosition' started
^[[52;1R

composer.json Outdated Show resolved Hide resolved
@javaDeveloperKid
Copy link
Contributor

How are we with this?

@alexislefebvre
Copy link
Contributor Author

Ubuntu 22.04.1 LTS was released 2 months ago, so all users of Ubuntu can install PHP 8.1 now. It should allow most of the Linux users (¹) to run tests without Docker.

This PR may be updated to allow different versions of PHP, including PHP 8.3 whose development will start a the end of this year.

(¹) I don't have numbers but it looks like Ubuntu is the most popular distro.

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
.docker/Dockerfile Outdated Show resolved Hide resolved
@alexislefebvre alexislefebvre force-pushed the add-composer-script-and-docker-for-development branch from c7f13b0 to a4031d2 Compare January 23, 2023 18:46
.docker/Dockerfile Outdated Show resolved Hide resolved
alexislefebvre and others added 2 commits January 25, 2023 14:23
Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
@alexislefebvre
Copy link
Contributor Author

Let's close this, this feature didn't get much traction.

@alexislefebvre alexislefebvre deleted the add-composer-script-and-docker-for-development branch March 2, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DX][RFC] Provide the commands to run Symfony Tests through Docker
6 participants