Skip to content

Commit 8a70782

Browse files
committed
Add more tests
1 parent 71d67ac commit 8a70782

File tree

4 files changed

+94
-11
lines changed

4 files changed

+94
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3777-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3781-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

src/Fixer/PhpdocNoNamedArgumentsTagFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
138138

139139
$content = $tokens[$docBlockIndex]->getContent();
140140

141-
$newContent = Preg::replace('/@no-named-arguments.*(\\R)/', \rtrim('@no-named-arguments ' . $this->description) . '$1', $content);
141+
$newContent = Preg::replace('/@no-named-arguments.*\\R/', \rtrim('@no-named-arguments ' . $this->description) . $this->whitespacesConfig->getLineEnding(), $content);
142142

143143
if ($newContent !== $content) {
144144
$tokens[$docBlockIndex] = new Token([\T_DOC_COMMENT, $newContent]);

tests/Fixer/AbstractFixerTestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ final protected static function getFixer(): FixerInterface
159159
/**
160160
* @param null|array<string, mixed> $configuration
161161
*/
162-
final protected function doTest(string $expected, ?string $input = null, ?array $configuration = null): void
162+
final protected function doTest(string $expected, ?string $input = null, ?array $configuration = null, ?WhitespacesFixerConfig $whitespacesFixerConfig = null): void
163163
{
164164
$fixer = self::getFixer();
165165

166+
if ($whitespacesFixerConfig instanceof WhitespacesFixerConfig) {
167+
$fixer->setWhitespacesConfig($whitespacesFixerConfig);
168+
}
169+
166170
if ($fixer instanceof ConfigurableFixerInterface) {
167171
$fixer->configure($configuration ?? []);
168172
}

tests/Fixer/PhpdocNoNamedArgumentsTagFixerTest.php

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
1515
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
16+
use PhpCsFixer\WhitespacesFixerConfig;
1617

1718
/**
1819
* @internal
@@ -52,9 +53,9 @@ public function testIsRisky(): void
5253
*
5354
* @dataProvider provideFixCases
5455
*/
55-
public function testFix(string $expected, ?string $input = null, array $configuration = []): void
56+
public function testFix(string $expected, ?string $input = null, array $configuration = [], ?WhitespacesFixerConfig $whitespacesFixerConfig = null): void
5657
{
57-
$this->doTest($expected, $input, $configuration);
58+
$this->doTest($expected, $input, $configuration, $whitespacesFixerConfig);
5859
}
5960

6061
/**
@@ -93,35 +94,88 @@ class Foo {}
9394
PHP,
9495
];
9596

96-
yield 'change the description' => [
97+
yield 'create PHPDoc with description' => [
9798
<<<'PHP'
9899
<?php
99100
100101
/**
101-
* @no-named-arguments Some description
102+
* @no-named-arguments The description
102103
*/
103104
class Foo {}
104105
PHP,
105106
<<<'PHP'
106107
<?php
107108
class Foo {}
108109
PHP,
109-
['description' => 'Some description'],
110+
['description' => 'The description'],
111+
];
112+
113+
yield 'add description' => [
114+
<<<'PHP'
115+
<?php
116+
/**
117+
* @no-named-arguments New description
118+
*/
119+
class Foo {}
120+
PHP,
121+
<<<'PHP'
122+
<?php
123+
/**
124+
* @no-named-arguments
125+
*/
126+
class Foo {}
127+
PHP,
128+
['description' => 'New description'],
129+
];
130+
131+
yield 'change description' => [
132+
<<<'PHP'
133+
<?php
134+
/**
135+
* @no-named-arguments New description
136+
*/
137+
class Foo {}
138+
PHP,
139+
<<<'PHP'
140+
<?php
141+
/**
142+
* @no-named-arguments Old description
143+
*/
144+
class Foo {}
145+
PHP,
146+
['description' => 'New description'],
147+
];
148+
149+
yield 'remove description' => [
150+
<<<'PHP'
151+
<?php
152+
/**
153+
* @no-named-arguments
154+
*/
155+
class Foo {}
156+
PHP,
157+
<<<'PHP'
158+
<?php
159+
/**
160+
* @no-named-arguments Description to remove
161+
*/
162+
class Foo {}
163+
PHP,
110164
];
111165

112166
yield 'multiple classes' => [
113167
<<<'PHP'
114168
<?php
115169
116170
/**
117-
* @no-named-arguments Some description
171+
* @no-named-arguments
118172
*/
119173
class Foo {}
120174
121175
new class {};
122176
123177
/**
124-
* @no-named-arguments Some description
178+
* @no-named-arguments
125179
*/
126180
class Bar {}
127181
PHP,
@@ -133,7 +187,32 @@ class Foo {}
133187
134188
class Bar {}
135189
PHP,
136-
['description' => 'Some description'],
190+
];
191+
192+
yield 'tabs and Windows Line endings' => [
193+
\str_replace(
194+
[' ', "\n"],
195+
["\t", "\r\n"],
196+
<<<'PHP'
197+
<?php
198+
199+
/**
200+
* @no-named-arguments
201+
*/
202+
class Foo {}
203+
PHP,
204+
),
205+
\str_replace(
206+
[' ', "\n"],
207+
["\t", "\r\n"],
208+
<<<'PHP'
209+
<?php
210+
211+
class Foo {}
212+
PHP,
213+
),
214+
[],
215+
new WhitespacesFixerConfig("\t", "\r\n"),
137216
];
138217
}
139218
}

0 commit comments

Comments
 (0)