SingleBlankLineBeforeNamespaceFixerTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\NamespaceNotation;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. use PhpCsFixer\WhitespacesFixerConfig;
  14. /**
  15. * @author Graham Campbell <graham@alt-three.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\AbstractLinesBeforeNamespaceFixer
  20. * @covers \PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer
  21. */
  22. final class SingleBlankLineBeforeNamespaceFixerTest extends AbstractFixerTestCase
  23. {
  24. /**
  25. * @dataProvider provideFixCases
  26. *
  27. * @param string $expected
  28. * @param null|string $input
  29. * @param null|WhitespacesFixerConfig $whitespaces
  30. */
  31. public function testFix($expected, $input = null, WhitespacesFixerConfig $whitespaces = null)
  32. {
  33. if (null !== $whitespaces) {
  34. $this->fixer->setWhitespacesConfig($whitespaces);
  35. }
  36. $this->doTest($expected, $input);
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function provideFixCases()
  42. {
  43. return [
  44. ["<?php\n\nnamespace X;"],
  45. ["<?php\n\nnamespace X;", "<?php\n\n\n\nnamespace X;"],
  46. ["<?php\r\n\r\nnamespace X;"],
  47. ["<?php\n\nnamespace X;", "<?php\r\n\r\n\r\n\r\nnamespace X;"],
  48. ["<?php\n\nfoo();\nnamespace\\bar\\baz();"],
  49. ["<?php\n\nnamespace X;", "<?php\nnamespace X;"],
  50. ["<?php\n\nnamespace X;", '<?php namespace X;'],
  51. ["<?php\n\nnamespace X;", "<?php\t\nnamespace X;"],
  52. ["<?php \n\nnamespace X;"],
  53. ["<?php\r\n\r\nnamespace X;", '<?php namespace X;', new WhitespacesFixerConfig(' ', "\r\n")],
  54. ["<?php\r\n\r\nnamespace X;", "<?php\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  55. ["<?php\r\n\r\nnamespace X;", "<?php\n\n\n\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  56. ["<?php\r\n\r\nnamespace X;", "<?php\r\n\n\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  57. ];
  58. }
  59. public function testFixExampleWithCommentTooMuch()
  60. {
  61. $expected = <<<'EOF'
  62. <?php
  63. /*
  64. * This file is part of the PHP CS utility.
  65. *
  66. * (c) Fabien Potencier <fabien@symfony.com>
  67. *
  68. * This source file is subject to the MIT license that is bundled
  69. * with this source code in the file LICENSE.
  70. */
  71. namespace PhpCsFixer\Fixer\Contrib;
  72. EOF;
  73. $input = <<<'EOF'
  74. <?php
  75. /*
  76. * This file is part of the PHP CS utility.
  77. *
  78. * (c) Fabien Potencier <fabien@symfony.com>
  79. *
  80. * This source file is subject to the MIT license that is bundled
  81. * with this source code in the file LICENSE.
  82. */
  83. namespace PhpCsFixer\Fixer\Contrib;
  84. EOF;
  85. $this->doTest($expected, $input);
  86. }
  87. public function testFixExampleWithCommentTooLittle()
  88. {
  89. $expected = <<<'EOF'
  90. <?php
  91. /*
  92. * This file is part of the PHP CS utility.
  93. *
  94. * (c) Fabien Potencier <fabien@symfony.com>
  95. *
  96. * This source file is subject to the MIT license that is bundled
  97. * with this source code in the file LICENSE.
  98. */
  99. namespace PhpCsFixer\Fixer\Contrib;
  100. EOF;
  101. $input = <<<'EOF'
  102. <?php
  103. /*
  104. * This file is part of the PHP CS utility.
  105. *
  106. * (c) Fabien Potencier <fabien@symfony.com>
  107. *
  108. * This source file is subject to the MIT license that is bundled
  109. * with this source code in the file LICENSE.
  110. */
  111. namespace PhpCsFixer\Fixer\Contrib;
  112. EOF;
  113. $this->doTest($expected, $input);
  114. }
  115. }