123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\Phpdoc;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer
- */
- final class PhpdocInlineTagFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param string $expected
- * @param null|string $input
- *
- * @dataProvider provideTestFixInlineDocCases
- */
- public function testFixInlineDoc($expected, $input = null)
- {
- $this->doTest($expected, $input);
- }
- public function provideTestFixInlineDocCases()
- {
- $cases = [
- [
- '<?php
- /**
- * {link} { LINK }
- * { test }
- * {@inheritdoc rire éclatant des écoliers qui décontenança®¶ñ¿}
- * test other comment
- * {@inheritdoc test} a
- * {@inheritdoc test} b
- * {@inheritdoc test} c
- * {@inheritdoc foo bar.} d
- * {@inheritdoc foo bar.} e
- * {@inheritdoc test} f
- * end comment {@inheritdoc here we are done} @spacepossum {1}
- */
- ',
- '<?php
- /**
- * {link} { LINK }
- * { test }
- * {@inheritDoc rire éclatant des écoliers qui décontenança®¶ñ¿ }
- * test other comment
- * @{inheritdoc test} a
- * {{@inheritdoc test}} b
- * {@ inheritdoc test} c
- * { @inheritdoc foo bar. } d
- * {@ inheritdoc foo bar. } e
- * @{{inheritdoc test}} f
- * end comment {@inheritdoc here we are done} @spacepossum {1}
- */
- ',
- ],
- ];
- foreach (['example', 'id', 'internal', 'inheritdoc', 'link', 'source', 'toc', 'tutorial'] as $tag) {
- $cases[] = [
- sprintf("<?php\n /**\n * {@%s}a\n */\n", $tag),
- sprintf("<?php\n /**\n * @{%s}a\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * {@%s} b\n */\n", $tag),
- sprintf("<?php\n /**\n * {{@%s}} b\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s}\n */\n", $tag),
- sprintf("<?php\n /**\n * c @{{%s}}\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
- sprintf("<?php\n /**\n * c @{{%s test}}\n */\n", $tag),
- ];
- // test unbalanced { tags
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
- sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
- sprintf("<?php\n /**\n * c {{@%s test}\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
- sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
- sprintf("<?php\n /**\n * c @{{%s test}}}\n */\n", $tag),
- ];
- }
- // don't touch custom tags
- $tag = 'foo';
- $cases[] = [
- sprintf("<?php\n /**\n * @{%s}a\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * {{@%s}} b\n */\n", $tag),
- ];
- $cases[] = [
- sprintf("<?php\n /**\n * c @{{%s}}\n */\n", $tag),
- ];
- // don't auto inline tags with the exception of inheritdoc
- foreach (['example', 'id', 'internal', 'foo', 'link', 'source', 'toc', 'tutorial'] as $tag) {
- $cases[] = [
- sprintf("<?php\n /**\n * @%s\n */\n", $tag),
- ];
- }
- // don't touch well formatted tags
- foreach (['example', 'id', 'internal', 'inheritdoc', 'link', 'source', 'toc', 'tutorial'] as $tag) {
- $cases[] = [
- sprintf("<?php\n /**\n * {@%s}\n */\n", $tag),
- ];
- }
- // common typos
- $cases[] = [
- '<?php
- /**
- * Typo {@inheritdoc} {@example} {@id} {@source} {@tutorial} {links}
- * inheritdocs
- */
- ',
- '<?php
- /**
- * Typo {@inheritdocs} {@exampleS} { @ids} { @sources } {{{ @tutorials }} {links}
- * inheritdocs
- */
- ',
- ];
- // invalid syntax
- $cases[] = [
- '<?php
- /**
- * {@link https://www.ietf.org/rfc/rfc1035.txt)
- */
- $someVar = "hello";',
- ];
- return $cases;
- }
- /**
- * @dataProvider provideTestFixInheritDocCases
- */
- public function testFixInheritDoc($expected, $input = null)
- {
- $this->doTest($expected, $input);
- }
- public function provideTestFixInheritDocCases()
- {
- return [
- [
- '<?php
- /**
- * {@inheritdoc} should this be inside the tag?
- * {@inheritdoc}
- * {@inheritdoc}
- * {@inheritdoc}
- * inheritdoc
- */
- ',
- // missing { } test for inheritdoc
- '<?php
- /**
- * @inheritdoc should this be inside the tag?
- * @inheritdoc
- * @inheritdocs
- * {@inheritdocs}
- * inheritdoc
- */
- ',
- ],
- ];
- }
- }
|