Skip to content

Commit b9e107e

Browse files
authored
[Attribute] Handle comment below @dataProvider doc on DataProviderAnnotationToAttributeRector (#500)
1 parent d3b9088 commit b9e107e

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
4+
5+
class WithCommentAbove extends \PHPUnit\Framework\TestCase
6+
{
7+
/**
8+
* This is a useless test to demonstrate a problem.
9+
*
10+
* @dataProvider dataProvider
11+
*/
12+
public function testProvider(bool $expected): void
13+
{
14+
self::assertSame($expected, $expected);
15+
}
16+
17+
public static function dataProvider(): iterable
18+
{
19+
yield [true];
20+
}
21+
}
22+
23+
?>
24+
-----
25+
<?php
26+
27+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
28+
29+
class WithCommentAbove extends \PHPUnit\Framework\TestCase
30+
{
31+
/**
32+
* This is a useless test to demonstrate a problem.
33+
*/
34+
#[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')]
35+
public function testProvider(bool $expected): void
36+
{
37+
self::assertSame($expected, $expected);
38+
}
39+
40+
public static function dataProvider(): iterable
41+
{
42+
yield [true];
43+
}
44+
}
45+
46+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
4+
5+
class WithCommentBelow extends \PHPUnit\Framework\TestCase
6+
{
7+
/**
8+
* @dataProvider dataProvider
9+
*
10+
* This is a useless test to demonstrate a problem.
11+
*/
12+
public function testProvider(bool $expected): void
13+
{
14+
self::assertSame($expected, $expected);
15+
}
16+
17+
public static function dataProvider(): iterable
18+
{
19+
yield [true];
20+
}
21+
}
22+
23+
?>
24+
-----
25+
<?php
26+
27+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
28+
29+
class WithCommentBelow extends \PHPUnit\Framework\TestCase
30+
{
31+
#[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')]
32+
public function testProvider(bool $expected): void
33+
{
34+
self::assertSame($expected, $expected);
35+
}
36+
37+
public static function dataProvider(): iterable
38+
{
39+
yield [true];
40+
}
41+
}
42+
43+
?>

rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function refactor(Node $node): ?Node
138138

139139
$originalAttributeValue = $desiredTagValueNode->value->value;
140140

141-
$node->attrGroups[] = $this->createAttributeGroup($originalAttributeValue);
141+
$node->attrGroups[] = $this->createAttributeGroup(strtok($originalAttributeValue, " \t\n\r\0\x0B"));
142142

143143
// cleanup
144144
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);

0 commit comments

Comments
 (0)