CombineNestedDirnameFixerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. final class CombineNestedDirnameFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. return [
  33. [
  34. '<?php dirname();',
  35. ],
  36. [
  37. '<?php dirname($path);',
  38. ],
  39. [
  40. '<?php dirname($path, 3);',
  41. ],
  42. [
  43. '<?php dirname($path, 2);',
  44. '<?php dirname(dirname($path));',
  45. ],
  46. [
  47. '<?php dirname /* a */ ( /* b */ /* c */ $path /* d */, 2);',
  48. '<?php dirname /* a */ ( /* b */ dirname( /* c */ $path) /* d */);',
  49. ],
  50. [
  51. '<?php dirname($path, 3);',
  52. '<?php dirname(\dirname(dirname($path)));',
  53. ],
  54. [
  55. '<?php dirname($path, 4);',
  56. '<?php dirname(dirname($path, 3));',
  57. ],
  58. [
  59. '<?php dirname($path, 4);',
  60. '<?php dirname(dirname($path), 3);',
  61. ],
  62. [
  63. '<?php dirname($path, 5);',
  64. '<?php dirname(dirname($path, 2), 3);',
  65. ],
  66. [
  67. '<?php dirname($path, 5);',
  68. '<?php dirname(dirname(dirname($path), 3));',
  69. ],
  70. [
  71. '<?php dirname(dirname($path, $level));',
  72. ],
  73. [
  74. '<?php dirname("foo/".dirname($path));',
  75. ],
  76. [
  77. '<?php dirname(dirname($path).$foo);',
  78. ],
  79. [
  80. '<?php foo\dirname(dirname($path));',
  81. ],
  82. [
  83. '<?php dirname(foo(dirname($path, 2)), 2);',
  84. '<?php dirname(dirname(foo(dirname(dirname($path)))));',
  85. ],
  86. [
  87. '<?php new dirname(dirname($path, 2));',
  88. '<?php new dirname(dirname(dirname($path)));',
  89. ],
  90. [
  91. '<?php dirname($path, 3);',
  92. '<?php dirname(dirname(dirname($path, ), ));',
  93. ],
  94. [
  95. '<?php dirname($path, 3);',
  96. '<?php dirname(dirname(dirname($path, ), ), );',
  97. ],
  98. ];
  99. }
  100. /**
  101. * @dataProvider provideFix81Cases
  102. *
  103. * @requires PHP 8.1
  104. */
  105. public function testFix81(string $expected, ?string $input = null): void
  106. {
  107. $this->doTest($expected, $input);
  108. }
  109. public static function provideFix81Cases(): iterable
  110. {
  111. yield ['<?php $a = dirname(dirname(...));'];
  112. }
  113. }