Skip to content

Commit 922f000

Browse files
Merge branch '11.5' into 12.2
2 parents cb6e7e2 + 5688c14 commit 922f000

File tree

4 files changed

+246
-23
lines changed

4 files changed

+246
-23
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: 182 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,201 @@
1010
namespace PHPUnit\Logging\TestDox;
1111

1212
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use PHPUnit\Framework\Attributes\Group;
1415
use PHPUnit\Framework\Attributes\Small;
1516
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\TestFixture\BackedEnumeration;
18+
use PHPUnit\TestFixture\Enumeration;
1619
use PHPUnit\TestFixture\TestDox\TestDoxAttributeOnTestClassTest;
20+
use PHPUnit\TestFixture\TestDoxTest;
21+
use stdClass;
1722

1823
#[CoversClass(NamePrettifier::class)]
1924
#[Group('testdox')]
2025
#[Small]
2126
final class NamePrettifierTest extends TestCase
2227
{
23-
public function testNameOfTestClassCanBePrettified(): void
28+
/**
29+
* @return non-empty-list<array{0: non-empty-string, 1: non-empty-string}>
30+
*/
31+
public static function classNameProvider(): array
2432
{
25-
$this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('FooTest'));
26-
$this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestFoo'));
27-
$this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestsFoo'));
28-
$this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestFooTest'));
29-
$this->assertSame('Foo (Test\Foo)', (new NamePrettifier)->prettifyTestClassName('Test\FooTest'));
30-
$this->assertSame('Foo (Tests\Foo)', (new NamePrettifier)->prettifyTestClassName('Tests\FooTest'));
31-
$this->assertSame('Unnamed Tests', (new NamePrettifier)->prettifyTestClassName('TestTest'));
32-
$this->assertSame('Système Testé', (new NamePrettifier)->prettifyTestClassName('SystèmeTestéTest'));
33-
$this->assertSame('Expression Évaluée', (new NamePrettifier)->prettifyTestClassName('ExpressionÉvaluéeTest'));
34-
$this->assertSame('Custom Title', (new NamePrettifier)->prettifyTestClassName(TestDoxAttributeOnTestClassTest::class));
33+
return [
34+
[
35+
'Foo',
36+
'FooTest',
37+
],
38+
[
39+
'Foo',
40+
'TestFoo',
41+
],
42+
[
43+
'Foo',
44+
'TestsFoo',
45+
],
46+
[
47+
'Foo',
48+
'TestFooTest',
49+
],
50+
[
51+
'Foo (Test\Foo)',
52+
'Test\FooTest',
53+
],
54+
[
55+
'Foo (Tests\Foo)',
56+
'Tests\FooTest',
57+
],
58+
[
59+
'Unnamed Tests',
60+
'TestTest',
61+
],
62+
[
63+
'Système Testé',
64+
'SystèmeTestéTest',
65+
],
66+
[
67+
'Expression Évaluée',
68+
'ExpressionÉvaluéeTest',
69+
],
70+
[
71+
'Custom Title',
72+
TestDoxAttributeOnTestClassTest::class,
73+
],
74+
];
3575
}
3676

37-
public function testNameOfTestMethodCanBePrettified(): void
77+
/**
78+
* @return non-empty-list<array{0: non-empty-string, 1: non-empty-string}>
79+
*/
80+
public static function methodNameProvider(): array
3881
{
39-
$this->assertSame('', (new NamePrettifier)->prettifyTestMethodName(''));
40-
$this->assertSame('', (new NamePrettifier)->prettifyTestMethodName('test'));
41-
$this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('testThisIsATest'));
42-
$this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('testThisIsATest2'));
43-
$this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('this_is_a_test'));
44-
$this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('test_this_is_a_test'));
45-
$this->assertSame('Foo for bar is 0', (new NamePrettifier)->prettifyTestMethodName('testFooForBarIs0'));
46-
$this->assertSame('Foo for baz is 1', (new NamePrettifier)->prettifyTestMethodName('testFooForBazIs1'));
47-
$this->assertSame('This has a 123 in its name', (new NamePrettifier)->prettifyTestMethodName('testThisHasA123InItsName'));
48-
$this->assertSame('Sets redirect header on 301', (new NamePrettifier)->prettifyTestMethodName('testSetsRedirectHeaderOn301'));
49-
$this->assertSame('Sets redirect header on 302', (new NamePrettifier)->prettifyTestMethodName('testSetsRedirectHeaderOn302'));
82+
return [
83+
[
84+
'',
85+
'',
86+
],
87+
[
88+
'',
89+
'test',
90+
],
91+
[
92+
'This is a test',
93+
'testThisIsATest',
94+
],
95+
[
96+
'This is a test',
97+
'testThisIsATest2',
98+
],
99+
[
100+
'This is a test',
101+
'this_is_a_test',
102+
],
103+
[
104+
'This is a test',
105+
'test_this_is_a_test',
106+
],
107+
[
108+
'Foo for bar is 0',
109+
'testFooForBarIs0',
110+
],
111+
[
112+
'Foo for baz is 1',
113+
'testFooForBazIs1',
114+
],
115+
[
116+
'This has a 123 in its name',
117+
'testThisHasA123InItsName',
118+
],
119+
[
120+
'Sets redirect header on 301',
121+
'testSetsRedirectHeaderOn301',
122+
],
123+
[
124+
'Sets redirect header on 302',
125+
'testSetsRedirectHeaderOn302',
126+
],
127+
];
128+
}
129+
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+
182+
/**
183+
* @param non-empty-string $expected
184+
* @param non-empty-string $className
185+
*/
186+
#[DataProvider('classNameProvider')]
187+
public function testNameOfTestClassCanBePrettified(string $expected, string $className): void
188+
{
189+
$this->assertSame($expected, (new NamePrettifier)->prettifyTestClassName($className));
190+
}
191+
192+
/**
193+
* @param non-empty-string $expected
194+
* @param non-empty-string $methodName
195+
*/
196+
#[DataProvider('methodNameProvider')]
197+
public function testNameOfTestMethodCanBePrettified(string $expected, string $methodName): void
198+
{
199+
$this->assertSame($expected, (new NamePrettifier)->prettifyTestMethodName($methodName));
200+
}
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));
50209
}
51210
}

0 commit comments

Comments
 (0)