CombineNestedDirnameFixerTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\FunctionNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Gregor Harlan
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer>
  22. */
  23. final class CombineNestedDirnameFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php dirname();',
  39. ];
  40. yield [
  41. '<?php dirname($path);',
  42. ];
  43. yield [
  44. '<?php dirname($path, 3);',
  45. ];
  46. yield [
  47. '<?php dirname($path, 2);',
  48. '<?php dirname(dirname($path));',
  49. ];
  50. yield [
  51. '<?php dirname /* a */ ( /* b */ /* c */ $path /* d */, 2);',
  52. '<?php dirname /* a */ ( /* b */ dirname( /* c */ $path) /* d */);',
  53. ];
  54. yield [
  55. '<?php dirname($path, 3);',
  56. '<?php dirname(\dirname(dirname($path)));',
  57. ];
  58. yield [
  59. '<?php dirname($path, 4);',
  60. '<?php dirname(dirname($path, 3));',
  61. ];
  62. yield [
  63. '<?php dirname($path, 4);',
  64. '<?php dirname(dirname($path), 3);',
  65. ];
  66. yield [
  67. '<?php dirname($path, 5);',
  68. '<?php dirname(dirname($path, 2), 3);',
  69. ];
  70. yield [
  71. '<?php dirname($path, 5);',
  72. '<?php dirname(dirname(dirname($path), 3));',
  73. ];
  74. yield [
  75. '<?php dirname(dirname($path, $level));',
  76. ];
  77. yield [
  78. '<?php dirname("foo/".dirname($path));',
  79. ];
  80. yield [
  81. '<?php dirname(dirname($path).$foo);',
  82. ];
  83. yield [
  84. '<?php foo\dirname(dirname($path));',
  85. ];
  86. yield [
  87. '<?php dirname(foo(dirname($path, 2)), 2);',
  88. '<?php dirname(dirname(foo(dirname(dirname($path)))));',
  89. ];
  90. yield [
  91. '<?php new dirname(dirname($path, 2));',
  92. '<?php new dirname(dirname(dirname($path)));',
  93. ];
  94. yield [
  95. '<?php dirname($path, 3);',
  96. '<?php dirname(dirname(dirname($path, ), ));',
  97. ];
  98. yield [
  99. '<?php dirname($path, 3);',
  100. '<?php dirname(dirname(dirname($path, ), ), );',
  101. ];
  102. }
  103. /**
  104. * @dataProvider provideFix81Cases
  105. *
  106. * @requires PHP 8.1
  107. */
  108. public function testFix81(string $expected, ?string $input = null): void
  109. {
  110. $this->doTest($expected, $input);
  111. }
  112. /**
  113. * @return iterable<array{string}>
  114. */
  115. public static function provideFix81Cases(): iterable
  116. {
  117. yield ['<?php $a = dirname(dirname(...));'];
  118. }
  119. }