Skip to content

Commit

Permalink
Closes #3741
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 30, 2019
1 parent 1c015f5 commit 74d84f7
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.3.md
Expand Up @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 8.3 release series are documented in this fil

### Added

* Implemented [#3741](https://github.com/sebastianbergmann/phpunit/issues/3741): Format class names as well as method names in testdox output
* Implemented [#3748](https://github.com/sebastianbergmann/phpunit/issues/3748): Add option to sort tests based on information from `@small`, `@medium`, and `@large`
* Added `TestCase::getActualOutputForAssertion()` as a wrapper for `TestCase::getActualOutput()` to prevent a test being marked as risky when it prints output and that output is not expected using `TestCase::expectOutputString()` or `TestCase::expectOutputRegEx()`

Expand Down
42 changes: 34 additions & 8 deletions src/Util/TestDox/NamePrettifier.php
Expand Up @@ -49,20 +49,47 @@ public function prettifyTestClass(string $className): string
} catch (UtilException $e) {
}

$result = $className;
$parts = \explode('\\', $className);
$className = \array_pop($parts);

if (\substr($className, -1 * \strlen('Test')) === 'Test') {
$result = \substr($result, 0, \strripos($result, 'Test'));
$className = \substr($className, 0, \strlen($className) - \strlen('Test'));
}

if (\strpos($className, 'Tests') === 0) {
$result = \substr($result, \strlen('Tests'));
$className = \substr($className, \strlen('Tests'));
} elseif (\strpos($className, 'Test') === 0) {
$result = \substr($result, \strlen('Test'));
$className = \substr($className, \strlen('Test'));
}

if ($result[0] === '\\') {
$result = \substr($result, 1);
if (!empty($parts)) {
$parts[] = $className;
$fullyQualifiedName = \implode('\\', $parts);
} else {
$fullyQualifiedName = $className;
}

$result = '';
$wasLowerCase = false;

foreach (\range(0, \strlen($className) - 1) as $i) {
$isLowerCase = \mb_strtolower($className[$i], 'UTF-8') === $className[$i];

if ($wasLowerCase && !$isLowerCase) {
$result .= ' ';
}

$result .= $className[$i];

if ($isLowerCase) {
$wasLowerCase = true;
} else {
$wasLowerCase = false;
}
}

if ($fullyQualifiedName !== $className) {
return $result . ' (' . $fullyQualifiedName . ')';
}

return $result;
Expand Down Expand Up @@ -153,10 +180,9 @@ public function prettifyTestMethod(string $name): string
return \trim(\str_replace('_', ' ', $name));
}

$max = \strlen($name);
$wasNumeric = false;

for ($i = 0; $i < $max; $i++) {
foreach (\range(0, \strlen($name) - 1) as $i) {
if ($i > 0 && \ord($name[$i]) >= 65 && \ord($name[$i]) <= 90) {
$buffer .= ' ' . \strtolower($name[$i]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/defaulttestsuite-using-testsuite.phpt
Expand Up @@ -13,7 +13,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

DummyFoo
Dummy Foo
Foo equals foo

Time: %s, Memory: %s
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/defaulttestsuite.phpt
Expand Up @@ -11,7 +11,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

DummyBar
Dummy Bar
Bar equals bar

Time: %s, Memory: %s
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/group.phpt
Expand Up @@ -14,7 +14,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

NumericGroupAnnotation
Numeric Group Annotation
Empty test for @ticket numeric annotation values
Empty test for @group numeric annotation values

Expand Down
6 changes: 3 additions & 3 deletions tests/end-to-end/loggers/_files/raw_output_StatusTest.txt
Expand Up @@ -3,7 +3,7 @@ PHPUnit %s Sebastian Bergmann and contributors.
Runtime: %s
Configuration: %stests%ebasic%econfiguration.basic.xml

PHPUnit\SelfTest\Basic\SetUpBeforeClass
Set Up Before Class (PHPUnit\SelfTest\Basic\SetUpBeforeClass)
✘ One  %f ms
┐
├ Exception: forcing an Exception in setUpBeforeClass()
Expand All @@ -18,7 +18,7 @@ Configuration: %stests%ebasic%econfiguration.basic.xml
╵ %stests%ebasic%eunit%eSetUpBeforeClassTest.php:31
┴

PHPUnit\SelfTest\Basic\SetUp
Set Up (PHPUnit\SelfTest\Basic\SetUp)
✘ One with set up exception  %f ms
┐
├ RuntimeException: throw exception in setUp
Expand Down Expand Up @@ -115,7 +115,7 @@ Configuration: %stests%ebasic%econfiguration.basic.xml
╵ %stests%ebasic%eunit%eStatusTest.php:%d
┴

PHPUnit\SelfTest\Basic\TearDownAfterClass
Tear Down After Class (PHPUnit\SelfTest\Basic\TearDownAfterClass)
✔ One  %f ms
✔ Two  %f ms
✘ Tear down after class  0 ms
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/loggers/testdox-exclude-group.phpt
Expand Up @@ -18,7 +18,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

.DoxGroup
.Dox Group
. 2 / 2 (100%) [x] Two


Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/loggers/testdox-group.phpt
Expand Up @@ -18,7 +18,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

DoxGroup
Dox Group
.. 2 / 2 (100%) [x] One


Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/loggers/testdox-html.phpt
Expand Up @@ -46,7 +46,7 @@ PHPUnit %s by Sebastian Bergmann and contributors.
</head>
<body>

<h2 id="BankAccountTest">BankAccount</h2>
<h2 id="BankAccountTest">Bank Account</h2>
<ul>
... 3 / 3 (100%) <li style="color: #555753;">✓ Balance is initially zero</li>
<li style="color: #555753;">✓ Balance cannot become negative</li>
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/loggers/testdox-text.phpt
Expand Up @@ -16,7 +16,7 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

BankAccount
Bank Account
... 3 / 3 (100%) [x] Balance is initially zero
[x] Balance cannot become negative
[x] Balance cannot become negative
Expand Down
4 changes: 2 additions & 2 deletions tests/end-to-end/regression/GitHub/3380/issue-3380-test.phpt
Expand Up @@ -19,7 +19,7 @@ unlink($tmpResultCache);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

DataproviderExecutionOrder
Dataprovider Execution Order
First test that always works
Add numbers with a dataprovider with data set "1+2=3"
Add numbers with a dataprovider with data set "2+1=3"
Expand All @@ -44,7 +44,7 @@ Time: %s, Memory: %s

Summary of non-successful tests:

DataproviderExecutionOrder
Dataprovider Execution Order
Add numbers with a dataprovider with data set "1+1=3"
Failed asserting that 2 is identical to 3.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Util/TestDox/CliTestDoxPrinterTest.php
Expand Up @@ -47,7 +47,7 @@ public function testPrintsTheClassNameOfTheTestClass(): void
$this->printer->startTest($this);
$this->printer->endTest($this, 0);

$this->assertStringStartsWith('PHPUnit\Util\TestDox\CliTestDoxPrinter', $this->printer->getBuffer());
$this->assertStringStartsWith('Cli Test Dox Printer (PHPUnit\Util\TestDox\CliTestDoxPrinter)', $this->printer->getBuffer());
}

public function testPrintsThePrettifiedMethodName(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Util/TestDox/NamePrettifierTest.php
Expand Up @@ -37,8 +37,8 @@ public function testTitleHasSensibleDefaults(): void
$this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest'));
$this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo'));
$this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest'));
$this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('Test\FooTest'));
$this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('Tests\FooTest'));
$this->assertEquals('Foo (Test\Foo)', $this->namePrettifier->prettifyTestClass('Test\FooTest'));
$this->assertEquals('Foo (Tests\Foo)', $this->namePrettifier->prettifyTestClass('Tests\FooTest'));
}

public function testTestNameIsConvertedToASentence(): void
Expand Down

0 comments on commit 74d84f7

Please sign in to comment.