|
10 | 10 | namespace PHPUnit\Logging\TestDox;
|
11 | 11 |
|
12 | 12 | use PHPUnit\Framework\Attributes\CoversClass;
|
| 13 | +use PHPUnit\Framework\Attributes\DataProvider; |
13 | 14 | use PHPUnit\Framework\Attributes\Group;
|
14 | 15 | use PHPUnit\Framework\Attributes\Small;
|
15 | 16 | use PHPUnit\Framework\TestCase;
|
| 17 | +use PHPUnit\TestFixture\BackedEnumeration; |
| 18 | +use PHPUnit\TestFixture\Enumeration; |
16 | 19 | use PHPUnit\TestFixture\TestDox\TestDoxAttributeOnTestClassTest;
|
| 20 | +use PHPUnit\TestFixture\TestDoxTest; |
| 21 | +use stdClass; |
17 | 22 |
|
18 | 23 | #[CoversClass(NamePrettifier::class)]
|
19 | 24 | #[Group('testdox')]
|
20 | 25 | #[Small]
|
21 | 26 | final class NamePrettifierTest extends TestCase
|
22 | 27 | {
|
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 |
24 | 32 | {
|
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 | + ]; |
35 | 75 | }
|
36 | 76 |
|
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 |
38 | 81 | {
|
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)); |
50 | 209 | }
|
51 | 210 | }
|
0 commit comments