Skip to content

Commit 424e83a

Browse files
committed
Cover array shape iterator for YieldDataProviderRector+RemoveUselessReturnTagRector.
1 parent ddb73ae commit 424e83a

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\Issues\WrongAnnotation;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class AnnotationParsingTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\Issues\AnnotationParsing\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SomeTest extends TestCase
8+
{
9+
#[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')]
10+
public function test(?bool $param1, string $param2, bool $param3)
11+
{
12+
$this->assertTrue($param1);
13+
$this->assertSame('string', $param2);
14+
$this->assertTrue($param3);
15+
}
16+
17+
/**
18+
* @return array<array{0: bool|null, 1: string, 2: bool}>
19+
*/
20+
public static function dataProvider(): array
21+
{
22+
return [
23+
'data1' => [null, 'string', false],
24+
'data2' => [false, 'string', false],
25+
];
26+
}
27+
}
28+
29+
?>
30+
-----
31+
<?php
32+
33+
namespace Rector\PHPUnit\Tests\Issues\AnnotationParsing\Fixture;
34+
35+
use PHPUnit\Framework\TestCase;
36+
37+
final class SomeTest extends TestCase
38+
{
39+
#[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')]
40+
public function test(?bool $param1, string $param2, bool $param3)
41+
{
42+
$this->assertTrue($param1);
43+
$this->assertSame('string', $param2);
44+
$this->assertTrue($param3);
45+
}
46+
47+
/**
48+
* @return \Iterator<(int | string), array{(bool | null), string, bool}>
49+
*/
50+
public static function dataProvider(): \Iterator
51+
{
52+
yield 'data1' => [null, 'string', false];
53+
yield 'data2' => [false, 'string', false];
54+
}
55+
}
56+
57+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
7+
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->rules([
11+
YieldDataProviderRector::class,
12+
RemoveUselessReturnTagRector::class,
13+
]);
14+
};

0 commit comments

Comments
 (0)