Skip to content

Commit

Permalink
Closes #5708 and #5709
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 18, 2024
1 parent 0f800f8 commit 129106b
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 10 deletions.
8 changes: 8 additions & 0 deletions ChangeLog-11.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ All notable changes of the PHPUnit 11.1 release series are documented in this fi

* [#5696](https://github.com/sebastianbergmann/phpunit/pull/5696): `#[DisableReturnValueGenerationForTestDoubles]` attribute for disabling return value generation for test doubles created using `createMock()`, `createMockForIntersectionOfInterfaces()`, `createPartialMock()`, `createStub()`, and `createStubForIntersectionOfInterfaces()`

### Changed

* [#5708](https://github.com/sebastianbergmann/phpunit/issues/5708): Allow the `--group`, `--exclude-group`, `--covers`, `--uses`, and `--test-suffix` CLI options to be used multiple times

### Deprecated

* [#5709](https://github.com/sebastianbergmann/phpunit/issues/5709): Deprecate support for using comma-separated values with the `--group`, `--exclude-group`, `--covers`, `--uses`, and `--test-suffix` CLI options

[11.1.0]: https://github.com/sebastianbergmann/phpunit/compare/11.0...main
6 changes: 6 additions & 0 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co
| [#5423](https://github.com/sebastianbergmann/phpunit/issues/5423) | `TestCase::returnValueMap()` | 10.3.0 | Use `$double->willReturnMap()` instead of `$double->will($this->returnValueMap())` |
| [#5535](https://github.com/sebastianbergmann/phpunit/issues/5525) | Configuring expectations using `expects()` on test stubs | 11.0.0 | Create a mock object when you need to configure expectations on a test double |

### Running Tests

| Issue | Description | Since | Replacement |
|-------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|--------|-------------------------------------------------------------------------|
| [#5709](https://github.com/sebastianbergmann/phpunit/issues/5709) | Support for using comma-separated values with the `--group`, `--exclude-group`, `--covers`, `--uses`, and `--test-suffix` CLI options | 11.1.0 | Use `--group foo --group bar` instead of `--group foo,bar`, for example |

#### Miscellaneous

| Issue | Description | Since | Replacement |
Expand Down
78 changes: 72 additions & 6 deletions src/TextUI/Configuration/Cli/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
namespace PHPUnit\TextUI\CliArguments;

use function array_map;
use function array_merge;
use function basename;
use function explode;
use function getcwd;
use function is_file;
use function is_numeric;
use function sprintf;
use function str_contains;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Runner\TestSuiteSorter;
use PHPUnit\Util\Filesystem;
Expand Down Expand Up @@ -251,6 +253,8 @@ public function fromParameters(array $parameters): Configuration
$debug = false;

foreach ($options[0] as $option) {
$optionAllowedMultipleTimes = false;

switch ($option[0]) {
case '--colors':
$colors = $option[1] ?: \PHPUnit\TextUI\Configuration\Configuration::COLOR_AUTO;
Expand Down Expand Up @@ -416,27 +420,87 @@ public function fromParameters(array $parameters): Configuration
break;

case '--group':
$groups = explode(',', $option[1]);
if (str_contains($option[1], ',')) {
EventFacade::emitter()->testRunnerTriggeredWarning(
'Using comma-separated values with --group is deprecated and will no longer work in PHPUnit 12',
);
}

if ($groups === null) {
$groups = [];
}

$groups = array_merge($groups, explode(',', $option[1]));

$optionAllowedMultipleTimes = true;

break;

case '--exclude-group':
$excludeGroups = explode(',', $option[1]);
if (str_contains($option[1], ',')) {
EventFacade::emitter()->testRunnerTriggeredWarning(
'Using comma-separated values with --exclude-group is deprecated and will no longer work in PHPUnit 12',
);
}

if ($excludeGroups === null) {
$excludeGroups = [];
}

$excludeGroups = array_merge($excludeGroups, explode(',', $option[1]));

$optionAllowedMultipleTimes = true;

break;

case '--covers':
$testsCovering = array_map('strtolower', explode(',', $option[1]));
if (str_contains($option[1], ',')) {
EventFacade::emitter()->testRunnerTriggeredWarning(
'Using comma-separated values with --covers is deprecated and will no longer work in PHPUnit 12',
);
}

if ($testsCovering === null) {
$testsCovering = [];
}

$testsCovering = array_merge($testsCovering, array_map('strtolower', explode(',', $option[1])));

$optionAllowedMultipleTimes = true;

break;

case '--uses':
$testsUsing = array_map('strtolower', explode(',', $option[1]));
if (str_contains($option[1], ',')) {
EventFacade::emitter()->testRunnerTriggeredWarning(
'Using comma-separated values with --uses is deprecated and will no longer work in PHPUnit 12',
);
}

if ($testsUsing === null) {
$testsUsing = [];
}

$testsUsing = array_merge($testsUsing, array_map('strtolower', explode(',', $option[1])));

$optionAllowedMultipleTimes = true;

break;

case '--test-suffix':
$testSuffixes = explode(',', $option[1]);
if (str_contains($option[1], ',')) {
EventFacade::emitter()->testRunnerTriggeredWarning(
'Using comma-separated values with --test-suffix is deprecated and will no longer work in PHPUnit 12',
);
}

if ($testSuffixes === null) {
$testSuffixes = [];
}

$testSuffixes = array_merge($testSuffixes, explode(',', $option[1]));

$optionAllowedMultipleTimes = true;

break;

Expand Down Expand Up @@ -845,7 +909,9 @@ public function fromParameters(array $parameters): Configuration
break;
}

$this->markProcessed($option[0]);
if (!$optionAllowedMultipleTimes) {
$this->markProcessed($option[0]);
}
}

if (empty($iniSettings)) {
Expand Down
41 changes: 41 additions & 0 deletions tests/end-to-end/cli/group/exclude-group-argument-csv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
phpunit --exclude-group one,two tests/FooTest.php
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'one,two';
$_SERVER['argv'][] = __DIR__ . '/../../_files/groups/tests/FooTest.php';

require_once __DIR__ . '/../../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Triggered Warning (Using comma-separated values with --exclude-group is deprecated and will no longer work in PHPUnit 12)
Test Runner Configured
Test Suite Loaded (3 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Suite Filtered (1 test)
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Groups\FooTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Prepared (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Passed (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Finished (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Suite Finished (PHPUnit\TestFixture\Groups\FooTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
4 changes: 3 additions & 1 deletion tests/end-to-end/cli/group/exclude-group-argument.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ $_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'one,two';
$_SERVER['argv'][] = 'one';
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'two';
$_SERVER['argv'][] = __DIR__ . '/../../_files/groups/tests/FooTest.php';

require_once __DIR__ . '/../../../bootstrap.php';
Expand Down
45 changes: 45 additions & 0 deletions tests/end-to-end/cli/group/exclude-group-configuration-csv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
phpunit --exclude-group one,two
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/../../_files/groups';
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'one,two';

require_once __DIR__ . '/../../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Triggered Warning (Using comma-separated values with --exclude-group is deprecated and will no longer work in PHPUnit 12)
Test Runner Configured
Test Suite Loaded (3 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Suite Filtered (1 test)
Test Runner Execution Started (1 test)
Test Suite Started (%s%etests%eend-to-end%e_files%egroups%ephpunit.xml, 1 test)
Test Suite Started (default, 1 test)
Test Suite Started (PHPUnit\TestFixture\Groups\FooTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Prepared (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Passed (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Finished (PHPUnit\TestFixture\Groups\FooTest::testThree)
Test Suite Finished (PHPUnit\TestFixture\Groups\FooTest, 1 test)
Test Suite Finished (default, 1 test)
Test Suite Finished (%s%etests%eend-to-end%e_files%egroups%ephpunit.xml, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
4 changes: 3 additions & 1 deletion tests/end-to-end/cli/group/exclude-group-configuration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ $_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/../../_files/groups';
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'one,two';
$_SERVER['argv'][] = 'one';
$_SERVER['argv'][] = '--exclude-group';
$_SERVER['argv'][] = 'two';

require_once __DIR__ . '/../../../bootstrap.php';

Expand Down
35 changes: 35 additions & 0 deletions tests/end-to-end/cli/group/size-groups-csv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
phpunit --group small,medium,large ../../_files/size-groups/SizeGroupsTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--group';
$_SERVER['argv'][] = 'small,medium,large';
$_SERVER['argv'][] = __DIR__ . '/../../_files/size-groups/SizeGroupsTest.php';

require_once __DIR__ . '/../../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

There were 7 PHPUnit test runner warnings:

1) Using comma-separated values with --group is deprecated and will no longer work in PHPUnit 12

2) Group name "small" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne

3) Group name "medium" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne

4) Group name "large" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne

5) Group name "small" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest

6) Group name "medium" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest

7) Group name "large" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest

No tests executed!
6 changes: 5 additions & 1 deletion tests/end-to-end/cli/group/size-groups.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ phpunit --group small,medium,large ../../_files/size-groups/SizeGroupsTest.php
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--group';
$_SERVER['argv'][] = 'small,medium,large';
$_SERVER['argv'][] = 'small';
$_SERVER['argv'][] = '--group';
$_SERVER['argv'][] = 'medium';
$_SERVER['argv'][] = '--group';
$_SERVER['argv'][] = 'large';
$_SERVER['argv'][] = __DIR__ . '/../../_files/size-groups/SizeGroupsTest.php';

require_once __DIR__ . '/../../../bootstrap.php';
Expand Down
27 changes: 27 additions & 0 deletions tests/end-to-end/generic/test-suffix-multiple-csv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
phpunit --test-suffix .test.php,.my.php ../../_files/
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--test-suffix';
$_SERVER['argv'][] = '.test.php,.my.php';
$_SERVER['argv'][] = __DIR__ . '/../../_files/';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

..... 5 / 5 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit test runner warning:

1) Using comma-separated values with --test-suffix is deprecated and will no longer work in PHPUnit 12

WARNINGS!
Tests: 5, Assertions: 5, Warnings: 1.
4 changes: 3 additions & 1 deletion tests/end-to-end/generic/test-suffix-multiple.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ phpunit --test-suffix .test.php,.my.php ../../_files/
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--test-suffix';
$_SERVER['argv'][] = '.test.php,.my.php';
$_SERVER['argv'][] = '.test.php';
$_SERVER['argv'][] = '--test-suffix';
$_SERVER['argv'][] = '.my.php';
$_SERVER['argv'][] = __DIR__ . '/../../_files/';

require_once __DIR__ . '/../../bootstrap.php';
Expand Down

0 comments on commit 129106b

Please sign in to comment.