* Dariusz Rumiński * * 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; use PhpCsFixer\WhitespacesFixerConfig; /** * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer */ final class PhpdocAlignFixerTest extends AbstractFixerTestCase { public function testFix() { $this->fixer->configure(['tags' => ['param']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixLeftAlign() { $this->fixer->configure(['tags' => ['param'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testFixPartiallyUntyped() { $this->fixer->configure(['tags' => ['param']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixPartiallyUntypedLeftAlign() { $this->fixer->configure(['tags' => ['param'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testFixMultiLineDesc() { $this->fixer->configure(['tags' => ['param', 'property', 'method']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixMultiLineDescLeftAlign() { $this->fixer->configure(['tags' => ['param', 'property', 'method'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testFixMultiLineDescWithThrows() { $this->fixer->configure(['tags' => ['param', 'return', 'throws']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixMultiLineDescWithThrowsLeftAlign() { $this->fixer->configure(['tags' => ['param', 'return', 'throws'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithReturnAndThrows() { $this->fixer->configure(['tags' => ['param', 'throws', 'return']]); $expected = <<<'EOF' doTest($expected, $input); } /** * References the issue #55 on github issue * https://github.com/FriendsOfPhp/PHP-CS-Fixer/issues/55. */ public function testFixThreeParamsWithReturn() { $this->fixer->configure(['tags' => ['param', 'return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixOnlyReturn() { $this->fixer->configure(['tags' => ['return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testReturnWithDollarThis() { $this->fixer->configure(['tags' => ['param', 'return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testCustomAnnotationsStayUntouched() { $this->fixer->configure(['tags' => ['return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testCustomAnnotationsStayUntouched2() { $this->fixer->configure(['tags' => ['var']]); $expected = <<<'EOF' |Value[] * @ORM\ManyToMany( * targetEntity="\Dl\Component\DomainModel\Product\Value\AbstractValue", * inversedBy="externalAliases" * ) */ private $values; } EOF; $this->doTest($expected); } public function testFixTestLeftAlign() { $this->fixer->configure(['tags' => ['param'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testFixTest() { $this->fixer->configure(['tags' => ['param']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithVar() { $this->fixer->configure(['tags' => ['var']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithType() { $this->fixer->configure(['tags' => ['type']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithVarAndDescription() { $this->fixer->configure(['tags' => ['var']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithVarAndInlineDescription() { $this->fixer->configure(['tags' => ['var']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixWithTypeAndInlineDescription() { $this->fixer->configure(['tags' => ['type']]); $expected = <<<'EOF' doTest($expected, $input); } public function testRetainsNewLineCharacters() { $this->fixer->configure(['tags' => ['param']]); // when we're not modifying a docblock, then line endings shouldn't change $this->doTest("fixer->configure(['tags' => ['return']]); $input = <<<'EOF' doTest($input); } public function testDifferentIndentation() { $this->fixer->configure(['tags' => ['param', 'return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testDifferentIndentationLeftAlign() { $this->fixer->configure(['tags' => ['param', 'return'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } /** * @param string $expected * @param string $input * * @dataProvider provideMessyWhitespacesCases */ public function testMessyWhitespaces(array $config, $expected, $input, WhitespacesFixerConfig $whitespacesFixerConfig) { $this->fixer->configure($config); $this->fixer->setWhitespacesConfig($whitespacesFixerConfig); $this->doTest($expected, $input); } public function provideMessyWhitespacesCases() { return [ [ ['tags' => ['type']], " ['param', 'return']], "fixer->configure(['tags' => ['var']]); $expected = "doTest($expected); } public function testFixUnicode() { $this->fixer->configure(['tags' => ['param', 'return']]); $expected = <<<'EOF' doTest($expected, $input); } public function testDoesNotAlignPropertyByDefault() { $expected = <<<'EOF' doTest($expected, $input); } public function testAlignsProperty() { $this->fixer->configure(['tags' => ['param', 'property', 'return', 'throws', 'type', 'var']]); $expected = <<<'EOF' doTest($expected, $input); } public function testDoesNotAlignMethodByDefault() { $expected = <<<'EOF' doTest($expected, $input); } public function testAlignsMethod() { $this->fixer->configure(['tags' => ['param', 'method', 'return', 'throws', 'type', 'var']]); $expected = <<<'EOF' doTest($expected, $input); } public function testAlignsMethodWithoutParameters() { $this->fixer->configure(['tags' => ['method', 'property']]); $expected = <<<'EOF' doTest($expected, $input); } public function testAlignsMethodWithoutParametersLeftAlign() { $this->fixer->configure(['tags' => ['method', 'property'], 'align' => 'left']); $expected = <<<'EOF' doTest($expected, $input); } public function testDoesNotFormatMethod() { $this->fixer->configure(['tags' => ['method']]); $input = <<<'EOF' doTest($input); } public function testAlignsMethodWithoutReturnType() { $this->fixer->configure(['tags' => ['method', 'property']]); $expected = <<<'EOF' doTest($expected, $input); } public function testAlignsMethodsWithoutReturnType() { $this->fixer->configure(['tags' => ['method']]); $expected = <<<'EOF' doTest($expected, $input); } public function testDoesNotAlignWithEmptyConfig() { $this->fixer->configure(['tags' => []]); $input = <<<'EOF' doTest($input); } /** * @param string $expected * @param string $input * * @dataProvider provideVariadicCases */ public function testVariadicParams(array $config, $expected, $input) { $this->fixer->configure($config); $this->doTest($expected, $input); } public function provideVariadicCases() { return [ [ ['tags' => ['param']], ' ['param']], ' ['param'], 'align' => 'left'], ' ['property', 'property-read', 'property-write']], 'fixer->configure($config); $this->doTest($input); } public function provideInvalidPhpdocCases() { return [ [ ['tags' => ['param', 'return', 'throws', 'type', 'var']], ' ['param', 'return', 'throws', 'type', 'var', 'method']], ' ['param', 'return', 'throws', 'type', 'var']], '