Skip to content

Commit

Permalink
Closes #5908
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 30, 2024
1 parent 98cbd0f commit 8f432cf
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
### Fixed

* [#5887](https://github.com/sebastianbergmann/phpunit/pull/5887): Issue baseline generator does not correctly handle ignoring suppressed issues
* [#5908](https://github.com/sebastianbergmann/phpunit/issues/5908): `--list-tests` and `--list-tests-xml` CLI options do not report error when data provider method throws exception

## [10.5.28] - 2024-07-18

Expand Down
38 changes: 32 additions & 6 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,40 @@ public function run(array $argv): int
// @codeCoverageIgnoreEnd
}

private function execute(Command\Command $command): never
private function execute(Command\Command $command, bool $requiresResultCollectedFromEvents = false): never
{
if ($requiresResultCollectedFromEvents) {
try {
TestResultFacade::init();
EventFacade::instance()->seal();

$resultCollectedFromEvents = TestResultFacade::result();
} catch (EventFacadeIsSealedException|UnknownSubscriberTypeException) {
}
}

print Version::getVersionString() . PHP_EOL . PHP_EOL;

$result = $command->execute();

print $result->output();

exit($result->shellExitCode());
$shellExitCode = $result->shellExitCode();

if (isset($resultCollectedFromEvents) &&
$resultCollectedFromEvents->hasTestTriggeredPhpunitErrorEvents()) {
$shellExitCode = Result::EXCEPTION;

print PHP_EOL . PHP_EOL . 'There were errors:' . PHP_EOL;

foreach ($resultCollectedFromEvents->testTriggeredPhpunitErrorEvents() as $events) {
foreach ($events as $event) {
print PHP_EOL . trim($event->message()) . PHP_EOL;
}
}
}

exit($shellExitCode);
}

private function loadBootstrapScript(string $filename): void
Expand Down Expand Up @@ -438,11 +463,11 @@ private function executeCommandsThatOnlyRequireCliConfiguration(CliConfiguration
private function executeCommandsThatRequireCliConfigurationAndTestSuite(CliConfiguration $cliConfiguration, TestSuite $testSuite): void
{
if ($cliConfiguration->listGroups()) {
$this->execute(new ListGroupsCommand($testSuite));
$this->execute(new ListGroupsCommand($testSuite), true);
}

if ($cliConfiguration->listTests()) {
$this->execute(new ListTestsAsTextCommand($testSuite));
$this->execute(new ListTestsAsTextCommand($testSuite), true);
}

if ($cliConfiguration->hasListTestsXml()) {
Expand All @@ -451,18 +476,19 @@ private function executeCommandsThatRequireCliConfigurationAndTestSuite(CliConfi
$cliConfiguration->listTestsXml(),
$testSuite,
),
true,
);
}
}

private function executeCommandsThatRequireCompleteConfiguration(Configuration $configuration, CliConfiguration $cliConfiguration): void
{
if ($cliConfiguration->listSuites()) {
$this->execute(new ListTestSuitesCommand($configuration->testSuite()));
$this->execute(new ListTestSuitesCommand($configuration->testSuite()), true);
}

if ($cliConfiguration->warmCoverageCache()) {
$this->execute(new WarmCodeCoverageCacheCommand($configuration, CodeCoverageFilterRegistry::instance()));
$this->execute(new WarmCodeCoverageCacheCommand($configuration, CodeCoverageFilterRegistry::instance()), true);
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/5908-list-tests-xml.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5908
--FILE--
<?php declare(strict_types=1);
$file = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--list-tests-xml';
$_SERVER['argv'][] = $file;
$_SERVER['argv'][] = __DIR__ . '/5908/Issue5908Test.php';

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

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

unlink($file);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Wrote list of tests that would have been run to %s


There were errors:

The data provider specified for PHPUnit\TestFixture\Issue5908\Issue5908Test::testOne is invalid
message
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/5908-list-tests.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5908
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--list-tests';
$_SERVER['argv'][] = __DIR__ . '/5908/Issue5908Test.php';

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

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

Available test(s):


There were errors:

The data provider specified for PHPUnit\TestFixture\Issue5908\Issue5908Test::testOne is invalid
message
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/5908/Issue5908Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5908;

use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class Issue5908Test extends TestCase
{
public static function provider(): array
{
throw new Exception('message');
}

#[DataProvider('provider')]
public function testOne(int $value): void
{
}
}

0 comments on commit 8f432cf

Please sign in to comment.