humanmade / altis-dev-tools

Dev Tools module for Altis
https://www.altis-dxp.com/resources/docs/dev-tools/
7 stars 2 forks source link

PHPUnit options delimiter bug when passing options to PHPUnit #108

Open ntwb opened 3 years ago

ntwb commented 3 years ago

Passing options to PHPUnit doesn't always work as expected, the docs state:

https://www.altis-dxp.com/resources/docs/dev-tools/testing-with-phpunit/

To pass any of the supported command line options to PHPUnit you need to add them after the options delimiter --. For example:

Running tests in a specific directory.

composer dev-tools phpunit -- content/themes/custom-theme/tests

Running tests with code coverage and junit reports.

composer dev-tools phpunit -- --coverage-xml coverage --log-junit junit.xml

The full list of PHPUnit command line options is available here or you can run composer dev-tools phpunit -- --help.

Steps to reproduce:

  1. From the terminal of a Altis install with the server running composer server start
  2. Run composer dev-tools phpunit -- --version

I expected to see the version of PHPUnit echo'd to the terminal

Instead I see the version of Composer: Composer version 1.10.16 2020-10-24 09:55:59

❯ composer dev-tools phpunit -- --version
Composer version 1.10.16 2020-10-24 09:55:59

I expected to see the same as when running PHPUnit directly from the /vendor folder:

❯ ./vendor/bin/phpunit --version
PHPUnit 7.1.5 by Sebastian Bergmann and contributors.

This is also reproducable with the docs example: composer dev-tools phpunit -- --help

Running this results in:

❯ composer dev-tools phpunit -- --help
Usage:
  dev-tools [options] [--] <subcommand> [<options>]...

Arguments:
  subcommand                     phpunit
  options                        

Options:
      --chassis                  Run commands in the Local Chassis environment
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Run a dev tools feature.

  To run PHPUnit integration tests:
      phpunit [--chassis] [--] [options]
                                  use `--` to separate arguments you want to
                                  pass to phpunit. Use the --chassis option
                                  if you are running Local Chassis.

This is the equivalent output of composer dev-tools --help which is the dev-tools help and not the phpunit help

Acceptance criteria:

johnbillion commented 3 years ago

This is a known bug in Composer, although I don't have the ticket to hand. The same problem exists for any custom Composer script.

johnbillion commented 2 years ago

I think this can be closed as the problem is not specific to this library and the root cause is in symfony/console. See https://github.com/composer/composer/issues/8165.