NoBlankLinesBeforeNamespaceFixerTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\NoBlankLinesBeforeNamespaceFixer
  21. */
  22. final class NoBlankLinesBeforeNamespaceFixerTest 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 namespace Some\Name\Space;'],
  45. ["<?php\nnamespace X;"],
  46. ["<?php\nnamespace X;", "<?php\n\n\n\nnamespace X;"],
  47. ["<?php\r\nnamespace X;"],
  48. ["<?php\nnamespace X;", "<?php\r\n\r\n\r\n\r\nnamespace X;"],
  49. ["<?php\r\nnamespace X;", "<?php\r\n\r\n\r\n\r\nnamespace X;", new WhitespacesFixerConfig(' ', "\r\n")],
  50. ["<?php\n\nnamespace\\Sub\\Foo::bar();"],
  51. ];
  52. }
  53. public function testFixExampleWithComment()
  54. {
  55. $expected = <<<'EOF'
  56. <?php
  57. /*
  58. * This file is part of the PHP CS utility.
  59. *
  60. * (c) Fabien Potencier <fabien@symfony.com>
  61. *
  62. * This source file is subject to the MIT license that is bundled
  63. * with this source code in the file LICENSE.
  64. */
  65. namespace PhpCsFixer\Fixer\Contrib;
  66. EOF;
  67. $input = <<<'EOF'
  68. <?php
  69. /*
  70. * This file is part of the PHP CS utility.
  71. *
  72. * (c) Fabien Potencier <fabien@symfony.com>
  73. *
  74. * This source file is subject to the MIT license that is bundled
  75. * with this source code in the file LICENSE.
  76. */
  77. namespace PhpCsFixer\Fixer\Contrib;
  78. EOF;
  79. $this->doTest($expected, $input);
  80. }
  81. }