Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses testdox prettifier for titles #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/CodewarsResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@
*/
class CodewarsResultPrinter extends DefaultResultPrinter
{

private $prettifier;
/**
* @var TestSuite
*/
private $wrapperSuite = null;
// Temporarily store failure messages so that the outputs can be written before them.
private $failures = array();

public function __construct() {
parent::__construct();
$this->prettifier = new \PHPUnit\Util\TestDox\NamePrettifier();
}

/**
* An error occurred.
*/
Expand Down Expand Up @@ -97,6 +104,7 @@ public function startTestSuite(TestSuite $suite): void
if (empty($suiteName)) {
return;
}
$suiteName = $this->prettifier->prettifyTestClass($suiteName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? prettifyTestCase($test); takes a TestCase, but prettifyTestClass takes a string?

Maybe this is causing the issue you mentioned?

  • Titles of <DESCRIBE::> groups of tests generated with @dataProvider seem to not respect the annotation (but this might be a bug of my implementation)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least that's how I read it in code of PHPUnit 9.6:

However, the bummer seems to be that PHPUnit 10 seems to change the prettifier: move it to another namespace, and rename the method to prettifyTestClassName(string $className). As a result, my reporter will break when PHPUnit gets updated :(

Copy link
Author

@hobovsky hobovsky Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :: in Even Or Odd Test::test Negative Even Numbers looks weird, though.

I run the suite with original TestDox reporter and it seems that it avoids the weirdness by simply not showing the intermediate groups:

image

All test cases seem to be flattened, and test cases generated with @dataProvider are not grouped under a common section, while CW reporter groups them with a <DESCRIBE::>. The title is provided by TestDox prettifier, which apparently does not care much because it's not presented by the TestDox reporter anyway. This might also be a reason why "Titles of <DESCRIBE::> groups of tests generated with @dataProvider seem to not respect the annotation" - they do not respect the annotation, because these titles are not presented by the TestDox reporter.

$this->write(sprintf("\n<DESCRIBE::>%s\n", $suiteName));
}

Expand All @@ -122,7 +130,11 @@ public function endTestSuite(TestSuite $suite): void
*/
public function startTest(Test $test): void
{
$this->write(sprintf("\n<IT::>%s\n", $test->getName()));
$title = $test->getName();
if ($test instanceof TestCase) {
$title = $this->prettifier->prettifyTestCase($test);
}
$this->write(sprintf("\n<IT::>%s\n", $title));
$this->failures = array();
}

Expand Down