HelperTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\Console\Tests\Helper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Formatter\OutputFormatter;
  13. use Symfony\Component\Console\Helper\Helper;
  14. class HelperTest extends TestCase
  15. {
  16. public static function formatTimeProvider()
  17. {
  18. return [
  19. [0, '< 1 sec'],
  20. [1, '1 sec'],
  21. [2, '2 secs'],
  22. [59, '59 secs'],
  23. [60, '1 min'],
  24. [61, '1 min'],
  25. [119, '1 min'],
  26. [120, '2 mins'],
  27. [121, '2 mins'],
  28. [3599, '59 mins'],
  29. [3600, '1 hr'],
  30. [7199, '1 hr'],
  31. [7200, '2 hrs'],
  32. [7201, '2 hrs'],
  33. [86399, '23 hrs'],
  34. [86400, '1 day'],
  35. [86401, '1 day'],
  36. [172799, '1 day'],
  37. [172800, '2 days'],
  38. [172801, '2 days'],
  39. ];
  40. }
  41. public static function decoratedTextProvider()
  42. {
  43. return [
  44. ['abc', 'abc'],
  45. ['abc<fg=default;bg=default>', 'abc'],
  46. ["a\033[1;36mbc", 'abc'],
  47. ["a\033]8;;http://url\033\\b\033]8;;\033\\c", 'abc'],
  48. ];
  49. }
  50. /**
  51. * @dataProvider formatTimeProvider
  52. *
  53. * @param int $secs
  54. * @param string $expectedFormat
  55. */
  56. public function testFormatTime($secs, $expectedFormat)
  57. {
  58. $this->assertEquals($expectedFormat, Helper::formatTime($secs));
  59. }
  60. /**
  61. * @dataProvider decoratedTextProvider
  62. */
  63. public function testRemoveDecoration(string $decoratedText, string $undecoratedText)
  64. {
  65. $this->assertEquals($undecoratedText, Helper::removeDecoration(new OutputFormatter(), $decoratedText));
  66. }
  67. }