File tree Expand file tree Collapse file tree 13 files changed +608
-0
lines changed
rules-tests/CodeQuality/Rector
Class_/YieldDataProviderRector/Fixture
MethodCall/WithCallbackIdenticalToStandaloneAssertsRector Expand file tree Collapse file tree 13 files changed +608
-0
lines changed Original file line number Diff line number Diff line change 4545use Rector \PHPUnit \CodeQuality \Rector \MethodCall \StringCastAssertStringContainsStringRector ;
4646use Rector \PHPUnit \CodeQuality \Rector \MethodCall \UseSpecificWillMethodRector ;
4747use Rector \PHPUnit \CodeQuality \Rector \MethodCall \UseSpecificWithMethodRector ;
48+ use Rector \PHPUnit \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector ;
4849use Rector \PHPUnit \CodeQuality \Rector \StmtsAwareInterface \DeclareStrictTypesTestsRector ;
4950use Rector \PHPUnit \PHPUnit60 \Rector \MethodCall \GetMockBuilderGetMockToCreateMockRector ;
5051use Rector \PHPUnit \PHPUnit90 \Rector \MethodCall \ReplaceAtMethodWithDesiredMatcherRector ;
121122
122123 FinalizeTestCaseClassRector::class,
123124 DeclareStrictTypesTestsRector::class,
125+ WithCallbackIdenticalToStandaloneAssertsRector::class,
124126
125127 // prefer simple mocking
126128 GetMockBuilderGetMockToCreateMockRector::class,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \YieldDataProviderRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class SkipYieldFromExpr extends TestCase
8+ {
9+ #[\PHPUnit \Framework \Attributes \DataProvider('dataProvider ' )]
10+ public function test (string $ val1 , string $ val2 ): void
11+ {
12+ }
13+
14+ public static function dataProvider (): iterable
15+ {
16+ yield from self ::someData ();
17+ }
18+
19+ public static function someData (): iterable
20+ {
21+ yield ['value1 ' , 'value2 ' ];
22+ yield ['value3 ' , 'value4 ' ];
23+ yield ['value5 ' , 'value6 ' ];
24+ yield ['value7 ' , 'value8 ' ];
25+ }
26+ }
27+
28+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class ClosureInstanceOf extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
12+
13+ $ someMock ->expects ($ this ->any ())
14+ ->method ('trans ' )
15+ ->with ($ this ->callback (function ($ args ): bool {
16+ return count ($ args ) === 5 && $ args [0 ] instanceof \stdClass;
17+ }));
18+ }
19+ }
20+
21+ ?>
22+ -----
23+ <?php
24+
25+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
26+
27+ use PHPUnit \Framework \TestCase ;
28+
29+ final class ClosureInstanceOf extends TestCase
30+ {
31+ public function test ()
32+ {
33+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
34+
35+ $ someMock ->expects ($ this ->any ())
36+ ->method ('trans ' )
37+ ->with ($ this ->callback (function ($ args ): void {
38+ $ this ->assertInstanceOf (\stdClass::class, $ args [0 ]);
39+ $ this ->assertCount (5 , $ args );
40+ }));
41+ }
42+ }
43+
44+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class SkipMultipleStmts extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
12+
13+ $ someMock ->expects ($ this ->any ())
14+ ->method ('trans ' )
15+ ->with ($ this ->callback (function ($ args ): bool {
16+ $ result = false ;
17+ return count ($ args ) === 5 && $ args [0 ] === 'some_value ' ;
18+ }));
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+
9+ final class SkipNoArgs extends TestCase
10+ {
11+ public function test ()
12+ {
13+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
14+
15+ $ someMock ->expects ($ this ->any ())
16+ ->method ('trans ' )
17+ ->with ($ this ->callback (function (): bool {
18+ $ args = [1 , 2 , 3 ];
19+ return count ($ args ) === 5 && $ args [0 ] === 'some_value ' ;
20+ }));
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class SkipOr extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
12+
13+ $ someMock ->expects ($ this ->any ())
14+ ->method ('trans ' )
15+ ->with ($ this ->callback (function ($ args ): bool {
16+ return count ($ args ) === 5 || $ args [0 ] === 'some_value ' ;
17+ }));
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class WithArrowFunction extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
12+
13+ $ someMock ->expects ($ this ->any ())
14+ ->method ('trans ' )
15+ ->with (
16+ $ this ->callback (
17+ fn ($ args ): bool => count ($ args ) === 5 && $ args [0 ] instanceof \stdClass
18+ )
19+ );
20+ }
21+ }
22+
23+ ?>
24+ -----
25+ <?php
26+
27+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
28+
29+ use PHPUnit \Framework \TestCase ;
30+
31+ final class WithArrowFunction extends TestCase
32+ {
33+ public function test ()
34+ {
35+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
36+
37+ $ someMock ->expects ($ this ->any ())
38+ ->method ('trans ' )
39+ ->with (
40+ $ this ->callback (
41+ function ($ args ): void {
42+ $ this ->assertInstanceOf (\stdClass::class, $ args [0 ]);
43+ $ this ->assertCount (5 , $ args );
44+ }
45+ )
46+ );
47+ }
48+ }
49+
50+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class WithCallbackAssert extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
12+
13+ $ someMock ->expects ($ this ->any ())
14+ ->method ('trans ' )
15+ ->with ($ this ->callback (function ($ args ): bool {
16+ return count ($ args ) === 5 && $ args [0 ] === 'some_value ' ;
17+ }));
18+ }
19+ }
20+
21+ ?>
22+ -----
23+ <?php
24+
25+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
26+
27+ use PHPUnit \Framework \TestCase ;
28+
29+ final class WithCallbackAssert extends TestCase
30+ {
31+ public function test ()
32+ {
33+ $ someMock = $ this ->getMockBuilder ('AnyType ' )->getMock ();
34+
35+ $ someMock ->expects ($ this ->any ())
36+ ->method ('trans ' )
37+ ->with ($ this ->callback (function ($ args ): void {
38+ $ this ->assertSame ('some_value ' , $ args [0 ]);
39+ $ this ->assertCount (5 , $ args );
40+ }));
41+ }
42+ }
43+
44+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector ;
6+
7+ use Iterator ;
8+ use PHPUnit \Framework \Attributes \DataProvider ;
9+ use Rector \Testing \PHPUnit \AbstractRectorTestCase ;
10+
11+ final class WithCallbackIdenticalToStandaloneAssertsRectorTest 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+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Rector \Config \RectorConfig ;
6+ use Rector \PHPUnit \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector ;
7+
8+ return static function (RectorConfig $ rectorConfig ): void {
9+ $ rectorConfig ->rule (WithCallbackIdenticalToStandaloneAssertsRector::class);
10+ };
You can’t perform that action at this time.
0 commit comments