Skip to content

Commit

Permalink
Fix --testdox output on @dataProvider (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Mar 3, 2023
1 parent 6f90dca commit 5169120
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@
"ext-simplexml": "*",
"fidry/cpu-core-counter": "^0.4.1 || ^0.5.1",
"jean85/pretty-package-versions": "^2.0.5",
"phpunit/php-code-coverage": "^9.2.24",
"phpunit/php-code-coverage": "^9.2.25",
"phpunit/php-file-iterator": "^3.0.6",
"phpunit/php-timer": "^5.0.3",
"phpunit/phpunit": "^9.6.3",
"sebastian/environment": "^5.1.4",
"symfony/console": "^5.4.16 || ^6.2.5",
"symfony/process": "^5.4.11 || ^6.2.5"
"phpunit/phpunit": "^9.6.4",
"sebastian/environment": "^5.1.5",
"symfony/console": "^5.4.21 || ^6.2.7",
"symfony/process": "^5.4.21 || ^6.2.7"
},
"require-dev": {
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^10.0.0",
"infection/infection": "^0.26.19",
"squizlabs/php_codesniffer": "^3.7.1",
"symfony/filesystem": "^5.4.13 || ^6.2.5",
"vimeo/psalm": "^5.6"
"squizlabs/php_codesniffer": "^3.7.2",
"symfony/filesystem": "^5.4.21 || ^6.2.7",
"vimeo/psalm": "^5.7.7"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 10 additions & 5 deletions src/Runners/PHPUnit/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use function get_class;
use function implode;
use function is_array;
use function is_string;
use function max;
use function preg_split;
use function rtrim;
Expand Down Expand Up @@ -687,13 +688,17 @@ private function processTestdoxReader(TestSuite $testSuite): void

$prettifier = new NamePrettifier(false);

$class = $testSuite->name;
assert(class_exists($class));
$separator = PHP_EOL;
foreach ($testSuite->cases as $index => $case) {
if ($index === 0) {
$class = $case->class;
assert(class_exists($class));

$this->output->writeln($prettifier->prettifyTestClass($class));
}

$this->output->writeln($prettifier->prettifyTestClass($class));
assert(isset($class) && is_string($class) && class_exists($class));

$separator = PHP_EOL;
foreach ($testSuite->cases as $case) {
$separator = PHP_EOL;
$testCase = new $class($case->name);
assert($testCase instanceof TestCase);
Expand Down
13 changes: 13 additions & 0 deletions test/Unit/Runners/PHPUnit/RunnerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,19 @@ final public function testRunnerReversed(): void
static::assertSame($defaultOrder, $reverseOrderReversed);
}

final public function testTestdoxAndDataProvider(): void
{
$this->bareOptions['--path'] = $this->fixture('testdox_dataprovider');
$this->bareOptions['--testdox'] = true;

$runnerResult = $this->runRunner();

$output = $runnerResult->getOutput();
static::assertStringContainsString('✔ Trim with data set "leading space is trimmed"', $output);
static::assertStringContainsString('✔ Trim with data set "trailing space and newline are trimmed"', $output);
static::assertStringContainsString('OK (2 tests, 2 assertions)', $output);
}

/** @return string[] */
private function prepareOutputForTestOrderCheck(string $output): array
{
Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/testdox_dataprovider/TestdoxDataProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\testdox_dataprovider;

use PHPUnit\Framework\TestCase;

use function trim;

final class TestdoxDataProviderTest extends TestCase
{
/** @dataProvider provideTrimData */
public function testTrim(string $expectedResult, string $input): void
{
self::assertSame($expectedResult, trim($input));
}

/** @return array<non-empty-string, list<non-empty-string>> */
public function provideTrimData(): array
{
return [
'leading space is trimmed' => [
'Hello World',
' Hello World',
],
'trailing space and newline are trimmed' => [
'Hello World',
"Hello World \n",
],
];
}
}

0 comments on commit 5169120

Please sign in to comment.