File: HelperTest.php

package info (click to toggle)
symfony 7.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,424 kB
  • sloc: php: 1,510,651; xml: 7,039; javascript: 979; sh: 586; makefile: 242; pascal: 70
file content (75 lines) | stat: -rw-r--r-- 2,422 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Tests\Helper;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\Helper;

class HelperTest extends TestCase
{
    public static function formatTimeProvider()
    {
        return [
            [0,      '< 1 ms', 1],
            [0.0004, '< 1 ms', 1],
            [0.95,   '950 ms', 1],
            [1,      '1 s', 1],
            [2,      '2 s', 2],
            [59,     '59 s', 1],
            [59.21,  '59 s', 1],
            [59.21,  '59 s, 210 ms', 5],
            [60,     '1 min', 2],
            [61,     '1 min, 1 s', 2],
            [119,    '1 min, 59 s', 2],
            [120,    '2 min', 2],
            [121,    '2 min, 1 s', 2],
            [3599,   '59 min, 59 s', 2],
            [3600,   '1 h', 2],
            [7199,   '1 h, 59 min', 2],
            [7200,   '2 h', 2],
            [7201,   '2 h', 2],
            [86399,  '23 h, 59 min', 2],
            [86399,  '23 h, 59 min, 59 s', 3],
            [86400,  '1 d', 2],
            [86401,  '1 d', 2],
            [172799, '1 d, 23 h', 2],
            [172799, '1 d, 23 h, 59 min, 59 s', 4],
            [172799.123, '1 d, 23 h, 59 min, 59 s, 123 ms', 5],
            [172800, '2 d', 2],
            [172801, '2 d', 2],
            [172801, '2 d, 1 s', 4],
        ];
    }

    public static function decoratedTextProvider()
    {
        return [
            ['abc', 'abc'],
            ['abc<fg=default;bg=default>', 'abc'],
            ["a\033[1;36mbc", 'abc'],
            ["a\033]8;;http://url\033\\b\033]8;;\033\\c", 'abc'],
        ];
    }

    #[\PHPUnit\Framework\Attributes\DataProvider('formatTimeProvider')]
    public function testFormatTime(int|float $secs, string $expectedFormat, int $precision)
    {
        $this->assertEquals($expectedFormat, Helper::formatTime($secs, $precision));
    }

    #[\PHPUnit\Framework\Attributes\DataProvider('decoratedTextProvider')]
    public function testRemoveDecoration(string $decoratedText, string $undecoratedText)
    {
        $this->assertEquals($undecoratedText, Helper::removeDecoration(new OutputFormatter(), $decoratedText));
    }
}