Skip to content

Commit

Permalink
Fix --testdox output (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Feb 6, 2024
1 parent 4ffc52e commit b2830e3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
5 changes: 3 additions & 2 deletions bin/phpunit-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'teamcity-file:',
'testdox-file:',
'testdox-color',
'testdox-columns:',
'phpunit-argv:',
]);

Expand Down Expand Up @@ -41,7 +42,7 @@
assert(isset($getopt['testresult-file']) && is_string($getopt['testresult-file']));
assert(!isset($getopt['teamcity-file']) || is_string($getopt['teamcity-file']));
assert(!isset($getopt['testdox-file']) || is_string($getopt['testdox-file']));
assert(!isset($getopt['testdox-columns']) || is_int($getopt['testdox-columns']));
assert(!isset($getopt['testdox-columns']) || $getopt['testdox-columns'] === (string) (int) $getopt['testdox-columns']);

assert(isset($getopt['phpunit-argv']) && is_string($getopt['phpunit-argv']));
$phpunitArgv = unserialize($getopt['phpunit-argv'], ['allowed_classes' => false]);
Expand All @@ -55,7 +56,7 @@
$getopt['teamcity-file'] ?? null,
$getopt['testdox-file'] ?? null,
isset($getopt['testdox-color']),
$getopt['testdox-columns'] ?? null,
isset($getopt['testdox-columns']) ? (int) $getopt['testdox-columns'] : null,
);

while (true) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"phpunit/php-code-coverage": "^10.1.11 || ^11.0.0",
"phpunit/php-file-iterator": "^4.1.0 || ^5.0.0",
"phpunit/php-timer": "^6.0.0 || ^7.0.0",
"phpunit/phpunit": "^10.5.9 || ^11.0.0",
"phpunit/phpunit": "^10.5.9 || ^11.0.2",
"sebastian/environment": "^6.0.1 || ^7.0.0",
"symfony/console": "^6.4.3 || ^7.0.3",
"symfony/process": "^6.4.3 || ^7.0.3"
Expand Down
4 changes: 4 additions & 0 deletions test/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ final protected function createOptionsFromArgv(array $argv, ?string $cwd = null)
$argv['--tmp-dir'] = $this->tmpDir;
}

if (! isset($argv['--passthru-php'])) {
$argv['--passthru-php'] = "'-d' 'zend.assertions=1'";
}

$input = new ArrayInput($argv, $inputDefinition);

return Options::fromConsoleInput($input, $cwd ?? __DIR__);
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testDefaultOptions(): void
self::assertNotEmpty($options->phpunitOptions);
self::assertSame(0, $options->maxBatchSize);
self::assertFalse($options->noTestTokens);
self::assertEmpty($options->passthruPhp);
self::assertSame(['-d', 'zend.assertions=1'], $options->passthruPhp);
self::assertStringContainsString('phpunit', $options->phpunit);
self::assertSame(PROCESSES_FOR_TESTS, $options->processes);
self::assertSame('WrapperRunner', $options->runner);
Expand Down
21 changes: 21 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,27 @@ public function testTeamcityOutput(): void
);
}

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

$result = $this->runRunner();

$format = file_get_contents(__DIR__ . '/fixtures/common_results_testdox_output');
self::assertNotFalse($format);

$output = $result->output;
$output = preg_replace("/^Processes: \\d+\nRuntime: PHP \\d+.\\d+.\\d+(-\w+)?\n\n/", '', $output, 1, $count);
self::assertSame(1, $count);
self::assertNotNull($output);

self::assertStringMatchesFormat(
self::sorted($format),
self::sorted($output),
);
}

public function testExitCodesPathWithoutTests(): void
{
$this->bareOptions['path'] = $this->fixture('no_tests');
Expand Down
42 changes: 42 additions & 0 deletions test/Unit/WrapperRunner/fixtures/common_results_testdox_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

EFIRS.W 7 / 7 (100%)

Time: %s, Memory: %s MB

Error (ParaTest\Tests\fixtures\common_results\Error)
✘ Error
│ RuntimeException: Error here!
│ %s/test/fixtures/common_results/ErrorTest.php:15

Incomplete (ParaTest\Tests\fixtures\common_results\Incomplete)
∅ Incomplete
│ %s/test/fixtures/common_results/IncompleteTest.php:14

Skipped (ParaTest\Tests\fixtures\common_results\Skipped)
↩ Skipped

Warning (ParaTest\Tests\fixtures\common_results\Warning)
⚠ Warning

Failure (ParaTest\Tests\fixtures\common_results\Failure)
✘ Failure
│ Failed asserting that false is true.
│ %s/test/fixtures/common_results/FailureTest.php:14

Risky (ParaTest\Tests\fixtures\common_results\Risky)
⚠ Risky

Success (ParaTest\Tests\fixtures\common_results\Success)
✔ Success

ERRORS!
Tests: %s

0 comments on commit b2830e3

Please sign in to comment.