Skip to content

Commit

Permalink
Output skipped details on verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 7, 2020
1 parent 56c529e commit 50a80fb
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 29 deletions.
18 changes: 18 additions & 0 deletions src/Logging/JUnit/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,22 @@ public function getRisky(): array

return $messages;
}

/**
* {@inheritDoc}
*/
public function getSkipped(): array
{
$messages = [];
$suites = $this->isSingle ? $this->suites : $this->suites[0]->suites;
foreach ($suites as $suite) {
foreach ($suite->cases as $case) {
foreach ($case->skipped as $msg) {
$messages[] = $msg['text'];
}
}
}

return $messages;
}
}
20 changes: 20 additions & 0 deletions src/Logging/JUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use function class_exists;
use function is_subclass_of;
use function iterator_to_array;
use function sprintf;
use function trim;

/**
Expand Down Expand Up @@ -118,6 +119,25 @@ public static function caseFromNode(SimpleXMLElement $node): self
];

foreach ($defect_groups as $group => $defects) {
if ($group === 'skipped' && $defects !== []) {
$text = (string) $node['name'];
if ((string) $node['class'] !== '') {
$text = sprintf(
"%s::%s\n\n%s:%s",
(string) $node['class'],
(string) $node['name'],
(string) $node['file'],
(string) $node['line']
);
}

$case->skipped[] = [
'type' => '',
'text' => $text,
];
continue;
}

foreach ($defects as $defect) {
assert($defect !== false);

Expand Down
13 changes: 13 additions & 0 deletions src/Logging/LogInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,17 @@ public function getRisky(): array

return $messages;
}

/**
* {@inheritDoc}
*/
public function getSkipped(): array
{
$messages = [];
foreach ($this->readers as $reader) {
$messages = array_merge($messages, $reader->getSkipped());
}

return $messages;
}
}
7 changes: 5 additions & 2 deletions src/Logging/MetaProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public function getTotalAssertions(): int;

public function getTotalErrors(): int;

public function getTotalFailures(): int;

public function getTotalWarnings(): int;

public function getTotalFailures(): int;

public function getTotalSkipped(): int;

public function getTotalTime(): float;
Expand All @@ -34,4 +34,7 @@ public function getFailures(): array;

/** @return string[] */
public function getRisky(): array;

/** @return string[] */
public function getSkipped(): array;
}
44 changes: 29 additions & 15 deletions src/Runners/PHPUnit/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ final class Options
self::ORDER_REVERSE,
];

public const VERBOSITY_NORMAL = 1;
public const VERBOSITY_VERBOSE = 2;
public const VERBOSITY_VERY_VERBOSE = 4;

/**
* @see \PHPUnit\Util\Configuration
Expand Down Expand Up @@ -171,12 +174,8 @@ final class Options
*/
private $passthruPhp;

/**
* Verbosity. If true, debug output will be printed.
*
* @var int
*/
private $verbose;
/** @var int */
private $verbosity;

/**
* Limit the number of tests recorded in coverage reports
Expand Down Expand Up @@ -258,7 +257,7 @@ private function __construct(
bool $stopOnFailure,
array $testsuite,
string $tmpDir,
int $verbose,
int $verbosity,
?string $whitelist,
string $orderBy,
int $randomOrderSeed
Expand Down Expand Up @@ -294,7 +293,7 @@ private function __construct(
$this->stopOnFailure = $stopOnFailure;
$this->testsuite = $testsuite;
$this->tmpDir = $tmpDir;
$this->verbose = $verbose;
$this->verbosity = $verbosity;
$this->whitelist = $whitelist;
$this->orderBy = $orderBy;
$this->randomOrderSeed = $randomOrderSeed;
Expand Down Expand Up @@ -449,6 +448,22 @@ public static function fromConsoleInput(InputInterface $input, string $cwd): sel
// is strictly coupled with PHPUnit pinned version
$phpunit = self::getPhpunitBinary();

$verbosity = self::VERBOSITY_NORMAL;
if (
$input->hasParameterOption('-vv', true)
|| $input->hasParameterOption('--verbose=2', true)
|| $input->getParameterOption('--verbose', false, true) === 2
) {
$verbosity = self::VERBOSITY_VERY_VERBOSE;
} elseif (
$input->hasParameterOption('-v', true)
|| $input->hasParameterOption('--verbose=1', true)
|| $input->hasParameterOption('--verbose', true)
|| $input->getParameterOption('--verbose', false, true) === 1
) {
$verbosity = self::VERBOSITY_VERBOSE;
}

return new self(
$options['bootstrap'],
$colors,
Expand Down Expand Up @@ -481,7 +496,7 @@ public static function fromConsoleInput(InputInterface $input, string $cwd): sel
$options['stop-on-failure'],
$testsuite,
$options['tmp-dir'],
(int) $options['verbose'],
$verbosity,
$options['whitelist'],
$options['order-by'] ?? self::ORDER_DEFAULT,
(int) $options['random-order-seed']
Expand Down Expand Up @@ -705,10 +720,9 @@ public static function setInputDefinition(InputDefinition $inputDefinition): voi
),
new InputOption(
'verbose',
'v',
InputOption::VALUE_REQUIRED,
'If given, debug output is printed. Example: --verbose=1',
0
'v|vv',
InputOption::VALUE_NONE,
'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output'
),
new InputOption(
'whitelist',
Expand Down Expand Up @@ -933,9 +947,9 @@ public function passthruPhp(): ?array
return $this->passthruPhp;
}

public function verbose(): int
public function verbosity(): int
{
return $this->verbose;
return $this->verbosity;
}

public function coverageTestLimit(): int
Expand Down
21 changes: 18 additions & 3 deletions src/Runners/PHPUnit/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,17 @@ public function println(string $string = ''): void
*/
public function printResults(): void
{
$failures = array_filter([
$toFilter = [
$this->getErrors(),
$this->getWarnings(),
$this->getFailures(),
$this->getRisky(),
]);
];
if ($this->options->verbosity() >= Options::VERBOSITY_VERBOSE) {
$toFilter[] = $this->getSkipped();
}

$failures = array_filter($toFilter);

$this->output->write($this->getHeader());
$this->output->write(implode("---\n\n", $failures));
Expand Down Expand Up @@ -313,7 +318,7 @@ public function getFailures(): string
}

/**
* Returns the failure messages.
* Returns the risky messages.
*/
public function getRisky(): string
{
Expand All @@ -322,6 +327,16 @@ public function getRisky(): string
return $this->getDefects($risky, 'risky');
}

/**
* Returns the skipped messages.
*/
public function getSkipped(): string
{
$risky = $this->results->getSkipped();

return $this->getDefects($risky, 'skipped');
}

/**
* Returns the total cases being printed.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function fillRunQueue(array $availableTokens): void
$this->running[$token] = new RunnerWorker($executableTest, $this->options, $token);
$this->running[$token]->run();

if ($this->options->verbose() === 0) {
if ($this->options->verbosity() < Options::VERBOSITY_VERY_VERBOSE) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Runners/PHPUnit/Worker/WrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct(OutputInterface $output, Options $options, int $toke
$parameters[] = '--write-to';
$parameters[] = $this->writeToPathname;

if ($options->verbose() > 0) {
if ($options->verbosity() >= Options::VERBOSITY_VERY_VERBOSE) {
$this->output->writeln(sprintf(
'Starting WrapperWorker via: %s',
implode(' ', array_map('\escapeshellarg', $parameters))
Expand Down Expand Up @@ -129,7 +129,7 @@ public function assign(ExecutableTest $test, string $phpunit, array $phpunitOpti
assert($this->currentlyExecuting === null);
$commandArguments = $test->commandArguments($phpunit, $phpunitOptions, $options->passthru());
$command = implode(' ', array_map('\\escapeshellarg', $commandArguments));
if ($options->verbose() > 0) {
if ($options->verbosity() >= Options::VERBOSITY_VERY_VERBOSE) {
$this->output->write("\nExecuting test via: {$command}\n");
}

Expand Down
27 changes: 27 additions & 0 deletions test/Unit/Logging/JUnit/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,33 @@ public function testGetMultiErrorsMessages(): void
);
}

public function testGetSkippedMessagesForSkippingTest(): void
{
$reader = new Reader(FIXTURES . DS . 'results' . DS . 'single-skipped.xml');
$skipped = $reader->getSkipped();
static::assertCount(1, $skipped);
static::assertSame(
"UnitTestWithMethodAnnotationsTest::testIncomplete\n\n" .
'/home/brian/Projects/parallel-phpunit/test/fixtures/failing_tests/UnitTestWithMethodAnnotationsTest.php:51',
$skipped[0]
);
}

public function testGetSkippedMessagesForSkippingDataProviders(): void
{
$reader = new Reader(FIXTURES . DS . 'results' . DS . 'data-provider-errors.xml');
$skipped = $reader->getSkipped();
static::assertCount(2, $skipped);
static::assertSame(
'ParaTest\Tests\fixtures\github\GH565\IssueTest::testIncompleteByDataProvider',
$skipped[0]
);
static::assertSame(
'ParaTest\Tests\fixtures\github\GH565\IssueTest::testSkippedByDataProvider',
$skipped[1]
);
}

public function testMixedGetFeedback(): void
{
$feedback = $this->mixed->getFeedback();
Expand Down
11 changes: 11 additions & 0 deletions test/Unit/Logging/LogInterpreterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public function testGetRiskyReturnsArrayOfErrorMessages(): void
static::assertSame($errors, $this->interpreter->getRisky());
}

public function testGetSkippedReturnsArrayOfTestNames(): void
{
$interpreter = new LogInterpreter();
$interpreter->addReader(new Reader($this->skipped->getTempFile()));
$skipped = [
"UnitTestWithMethodAnnotationsTest::testIncomplete\n\n" .
'/home/brian/Projects/parallel-phpunit/test/fixtures/failing_tests/UnitTestWithMethodAnnotationsTest.php:51',
];
static::assertSame($skipped, $interpreter->getSkipped());
}

public function testGetCasesReturnsAllCases(): void
{
$cases = $this->interpreter->getCases();
Expand Down
13 changes: 10 additions & 3 deletions test/Unit/Runners/PHPUnit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function testDefaultOptions(): void
static::assertFalse($options->stopOnFailure());
static::assertEmpty($options->testsuite());
static::assertSame(TMP_DIR, $options->tmpDir());
static::assertSame(0, $options->verbose());
static::assertSame(Options::VERBOSITY_NORMAL, $options->verbosity());
static::assertNull($options->whitelist());
static::assertSame(Options::ORDER_DEFAULT, $options->orderBy());
static::assertSame(0, $options->randomOrderSeed());
Expand Down Expand Up @@ -292,7 +292,7 @@ public function testProvidedOptions(): void
'--stop-on-failure' => true,
'--testsuite' => 'TESTSUITE',
'--tmp-dir' => ($tmpDir = uniqid(TMP_DIR . DS . 't')),
'--verbose' => 1,
'--verbose' => 2,
'--whitelist' => 'WHITELIST',
'--order-by' => Options::ORDER_RANDOM,
'--random-order-seed' => $expected_random_seed,
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testProvidedOptions(): void
static::assertTrue($options->stopOnFailure());
static::assertSame(['TESTSUITE'], $options->testsuite());
static::assertSame($tmpDir, $options->tmpDir());
static::assertSame(1, $options->verbose());
static::assertSame(Options::VERBOSITY_VERY_VERBOSE, $options->verbosity());
static::assertSame('WHITELIST', $options->whitelist());
static::assertSame(Options::ORDER_RANDOM, $options->orderBy());
static::assertSame($expected_random_seed, $options->randomOrderSeed());
Expand All @@ -349,6 +349,13 @@ public function testProvidedOptions(): void
static::assertTrue($options->hasCoverage());
}

public function testSingleVerboseFlag(): void
{
$options = $this->createOptionsFromArgv(['--verbose' => 1], __DIR__);

static::assertSame(Options::VERBOSITY_VERBOSE, $options->verbosity());
}

public function testGatherOptionsFromConfiguration(): void
{
$argv = [
Expand Down
Loading

0 comments on commit 50a80fb

Please sign in to comment.