SingleBlankLineBeforeNamespaceFixerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. */
  30. public function testFix($expected, $input = null, WhitespacesFixerConfig $whitespaces = null)
  31. {
  32. if (null !== $whitespaces) {
  33. $this->fixer->setWhitespacesConfig($whitespaces);
  34. }
  35. $this->doTest($expected, $input);
  36. }
  37. /**
  38. * @return array
  39. */
  40. public function provideFixCases()
  41. {
  42. return [
  43. ["<?php\n\nnamespace X;"],
  44. ["<?php\n\nnamespace X;", "<?php\n\n\n\nnamespace X;"],
  45. ["<?php\r\n\r\nnamespace X;"],
  46. ["<?php\n\nnamespace X;", "<?php\r\n\r\n\r\n\r\nnamespace X;"],
  47. ["<?php\n\nfoo();\nnamespace\\bar\\baz();"],
  48. ["<?php\n\nnamespace X;", "<?php\nnamespace X;"],
  49. ["<?php\n\nnamespace X;", '<?php namespace X;'],
  50. ["<?php\n\nnamespace X;", "<?php\t\nnamespace X;"],
  51. ["<?php \n\nnamespace X;"],
  52. ["<?php\r\n\r\nnamespace X;", '<?php namespace X;', new WhitespacesFixerConfig(' ', "\r\n")],
  53. ["<?php\r\n\r\nnamespace X;", "<?php\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  54. ["<?php\r\n\r\nnamespace X;", "<?php\n\n\n\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  55. ["<?php\r\n\r\nnamespace X;", "<?php\r\n\n\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  56. ];
  57. }
  58. public function testFixExampleWithCommentTooMuch()
  59. {
  60. $expected = <<<'EOF'
  61. <?php
  62. /*
  63. * This file is part of the PHP CS utility.
  64. *
  65. * (c) Fabien Potencier <fabien@symfony.com>
  66. *
  67. * This source file is subject to the MIT license that is bundled
  68. * with this source code in the file LICENSE.
  69. */
  70. namespace PhpCsFixer\Fixer\Contrib;
  71. EOF;
  72. $input = <<<'EOF'
  73. <?php
  74. /*
  75. * This file is part of the PHP CS utility.
  76. *
  77. * (c) Fabien Potencier <fabien@symfony.com>
  78. *
  79. * This source file is subject to the MIT license that is bundled
  80. * with this source code in the file LICENSE.
  81. */
  82. namespace PhpCsFixer\Fixer\Contrib;
  83. EOF;
  84. $this->doTest($expected, $input);
  85. }
  86. public function testFixExampleWithCommentTooLittle()
  87. {
  88. $expected = <<<'EOF'
  89. <?php
  90. /*
  91. * This file is part of the PHP CS utility.
  92. *
  93. * (c) Fabien Potencier <fabien@symfony.com>
  94. *
  95. * This source file is subject to the MIT license that is bundled
  96. * with this source code in the file LICENSE.
  97. */
  98. namespace PhpCsFixer\Fixer\Contrib;
  99. EOF;
  100. $input = <<<'EOF'
  101. <?php
  102. /*
  103. * This file is part of the PHP CS utility.
  104. *
  105. * (c) Fabien Potencier <fabien@symfony.com>
  106. *
  107. * This source file is subject to the MIT license that is bundled
  108. * with this source code in the file LICENSE.
  109. */
  110. namespace PhpCsFixer\Fixer\Contrib;
  111. EOF;
  112. $this->doTest($expected, $input);
  113. }
  114. }