File: NamePrettifierTest.php

package info (click to toggle)
phpunit 11.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 46,840 kB
  • sloc: php: 87,742; xml: 1,938; makefile: 118; sh: 93
file content (51 lines) | stat: -rw-r--r-- 3,065 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\Logging\TestDox;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\TestDox\TestDoxAttributeOnTestClassTest;

#[CoversClass(NamePrettifier::class)]
#[Group('testdox')]
#[Small]
final class NamePrettifierTest extends TestCase
{
    public function testNameOfTestClassCanBePrettified(): void
    {
        $this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('FooTest'));
        $this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestFoo'));
        $this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestsFoo'));
        $this->assertSame('Foo', (new NamePrettifier)->prettifyTestClassName('TestFooTest'));
        $this->assertSame('Foo (Test\Foo)', (new NamePrettifier)->prettifyTestClassName('Test\FooTest'));
        $this->assertSame('Foo (Tests\Foo)', (new NamePrettifier)->prettifyTestClassName('Tests\FooTest'));
        $this->assertSame('Unnamed Tests', (new NamePrettifier)->prettifyTestClassName('TestTest'));
        $this->assertSame('Système Testé', (new NamePrettifier)->prettifyTestClassName('SystèmeTestéTest'));
        $this->assertSame('Expression Évaluée', (new NamePrettifier)->prettifyTestClassName('ExpressionÉvaluéeTest'));
        $this->assertSame('Custom Title', (new NamePrettifier)->prettifyTestClassName(TestDoxAttributeOnTestClassTest::class));
    }

    public function testNameOfTestMethodCanBePrettified(): void
    {
        $this->assertSame('', (new NamePrettifier)->prettifyTestMethodName(''));
        $this->assertSame('', (new NamePrettifier)->prettifyTestMethodName('test'));
        $this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('testThisIsATest'));
        $this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('testThisIsATest2'));
        $this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('this_is_a_test'));
        $this->assertSame('This is a test', (new NamePrettifier)->prettifyTestMethodName('test_this_is_a_test'));
        $this->assertSame('Foo for bar is 0', (new NamePrettifier)->prettifyTestMethodName('testFooForBarIs0'));
        $this->assertSame('Foo for baz is 1', (new NamePrettifier)->prettifyTestMethodName('testFooForBazIs1'));
        $this->assertSame('This has a 123 in its name', (new NamePrettifier)->prettifyTestMethodName('testThisHasA123InItsName'));
        $this->assertSame('Sets redirect header on 301', (new NamePrettifier)->prettifyTestMethodName('testSetsRedirectHeaderOn301'));
        $this->assertSame('Sets redirect header on 302', (new NamePrettifier)->prettifyTestMethodName('testSetsRedirectHeaderOn302'));
    }
}