CombineNestedDirnameFixerTest.php 3.3 KB

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