Skip to content

Commit 5688c14

Browse files
Add tests
1 parent e568fe3 commit 5688c14

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

tests/_files/BackedEnumeration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
enum BackedEnumeration: string
13+
{
14+
case Test = 'test';
15+
}

tests/_files/Enumeration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
enum Enumeration
13+
{
14+
case Test;
15+
}

tests/_files/TestDoxTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use PHPUnit\Framework\Attributes\TestDox;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class TestDoxTest extends TestCase
16+
{
17+
public function testOne(): void
18+
{
19+
}
20+
21+
public function testTwo(): void
22+
{
23+
}
24+
25+
#[TestDox('This is a custom test description')]
26+
public function testThree(): void
27+
{
28+
}
29+
30+
#[TestDox('This is a custom test description with placeholders $a $b $f $i $s $o $stdClass $enum $backedEnum $n $empty $default')]
31+
public function testFour(array $a, bool $b, float $f, int $i, string $s, object $o, object $stdClass, $enum, $backedEnum, $n, string $empty, string $default = 'default'): void
32+
{
33+
}
34+
}

tests/unit/Logging/TestDox/NamePrettifierTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
use PHPUnit\Framework\Attributes\Group;
1515
use PHPUnit\Framework\Attributes\Small;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\TestFixture\BackedEnumeration;
18+
use PHPUnit\TestFixture\Enumeration;
1719
use PHPUnit\TestFixture\TestDox\TestDoxAttributeOnTestClassTest;
20+
use PHPUnit\TestFixture\TestDoxTest;
21+
use stdClass;
1822

1923
#[CoversClass(NamePrettifier::class)]
2024
#[Group('testdox')]
@@ -123,6 +127,58 @@ public static function methodNameProvider(): array
123127
];
124128
}
125129

130+
/**
131+
* @return non-empty-list<array{0: non-empty-string, 1: TestCase, 2: bool}>
132+
*/
133+
public static function objectProvider(): array
134+
{
135+
$object = new class {
136+
public function __toString(): string
137+
{
138+
return 'object as string';
139+
}
140+
};
141+
142+
$data = [['string'], true, 0.0, 1, 'string', $object, new stdClass, Enumeration::Test, BackedEnumeration::Test, null, ''];
143+
144+
$testWithDataWithIntegerKey = new TestDoxTest('testTwo');
145+
$testWithDataWithIntegerKey->setData(0, $data);
146+
147+
$testWithDataWithStringKey = new TestDoxTest('testTwo');
148+
$testWithDataWithStringKey->setData('a', $data);
149+
150+
$testWithDataAndTestDoxPlaceholders = new TestDoxTest('testFour');
151+
$testWithDataAndTestDoxPlaceholders->setData('a', $data);
152+
153+
return [
154+
[
155+
'One',
156+
new TestDoxTest('testOne'),
157+
false,
158+
],
159+
[
160+
'Two with data set #0',
161+
$testWithDataWithIntegerKey,
162+
false,
163+
],
164+
[
165+
'Two with data set "a"',
166+
$testWithDataWithStringKey,
167+
false,
168+
],
169+
[
170+
'This is a custom test description',
171+
new TestDoxTest('testThree'),
172+
false,
173+
],
174+
[
175+
'This is a custom test description with placeholders array true 0.0 1 string object as string stdClass Test test null \'\' default',
176+
$testWithDataAndTestDoxPlaceholders,
177+
false,
178+
],
179+
];
180+
}
181+
126182
/**
127183
* @param non-empty-string $expected
128184
* @param non-empty-string $className
@@ -142,4 +198,13 @@ public function testNameOfTestMethodCanBePrettified(string $expected, string $me
142198
{
143199
$this->assertSame($expected, (new NamePrettifier)->prettifyTestMethodName($methodName));
144200
}
201+
202+
/**
203+
* @param non-empty-string $expected
204+
*/
205+
#[DataProvider('objectProvider')]
206+
public function test_TestCase_can_be_prettified(string $expected, TestCase $testCase, bool $colorize): void
207+
{
208+
$this->assertSame($expected, (new NamePrettifier)->prettifyTestCase($testCase, $colorize));
209+
}
145210
}

0 commit comments

Comments
 (0)