* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace Symfony\CS\Tests\Fixer\Contrib; use Symfony\CS\Fixer\Contrib\HeaderCommentFixer; use Symfony\CS\Tests\Fixer\AbstractFixerTestBase; class HeaderCommentFixerTest extends AbstractFixerTestBase { protected static $savedHeader; protected static $testHeader = <<<'EOH' This file is part of the PHP CS utility. (c) Fabien Potencier This source file is subject to the MIT license that is bundled with this source code in the file LICENSE. EOH; protected function setUp() { parent::setUp(); self::$savedHeader = HeaderCommentFixer::getHeader(); HeaderCommentFixer::setHeader(self::$testHeader); } protected function tearDown() { HeaderCommentFixer::setHeader(self::$savedHeader); parent::tearDown(); } public function testFixWithPreviousHeader() { $expected = <<<'EOH' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ phpinfo(); EOH; $input = <<<'EOH' makeTest($expected, $input); } public function testFixWithoutPreviousHeader() { $expected = <<<'EOH' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ phpinfo(); EOH; $input = <<<'EOH' makeTest($expected, $input); } public function testFixWithClassDocblock() { $expected = <<<'EOH' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * @author Antonio J. García Lagar */ class Foo { } EOH; $input = <<<'EOH' */ class Foo { } EOH; $this->makeTest($expected, $input); } public function testFixRemovePreviousHeader() { HeaderCommentFixer::setHeader(''); $expected = <<<'EOH' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ phpinfo(); EOH; $this->makeTest($expected, $input); } public function testFixDoNotTouchFilesWithSeveralOpenTags() { $input = "\nmakeTest($input); } public function testFixDoNotTouchFilesNotStartingWithOpenTag() { $input = " makeTest($input); } public function testFixDoNotTouchFilesWithInlineHtml() { $input = "
"; $this->makeTest($input); } public function testFixAddHeaderToEmptyFile() { $expected = <<<'EOH' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ EOH; $input = "makeTest($expected, $input); } /** * @expectedException \Symfony\CS\ConfigurationException\InvalidFixerConfigurationException * @expectedExceptionMessage [header_comment] Header configuration is invalid. Expected "string", got "stdClass". */ public function testInvalidConfig() { HeaderCommentFixer::setHeader(new \stdClass()); } }