* 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\PhpUnit; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer */ final class PhpUnitMockFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield [ 'createMock("Foo"); } }', 'getMockWithoutInvokingTheOriginalConstructor("Foo"); } }', ]; yield [ 'createMock("Foo"); $this->createMock($foo(1, 2)); $this->getMock("Foo", ["aaa"]); } }', 'getMock("Foo"); $this->getMock($foo(1, 2)); $this->getMock("Foo", ["aaa"]); } }', ['target' => PhpUnitTargetVersion::VERSION_5_4], ]; yield [ 'createMock("Foo"); $this->createMock($foo(1, 2)); $this->createPartialMock("Foo", ["aaa"]); $this->getMock("Foo", ["aaa"], ["argument"]); } }', 'getMock("Foo"); $this->getMock($foo(1, 2)); $this->getMock("Foo", ["aaa"]); $this->getMock("Foo", ["aaa"], ["argument"]); } }', ]; yield [ 'createMock("Foo",); $this->createMock("Bar" ,); $this->createMock("Baz" , ); $this->createMock($foo(1, 2), ); $this->createMock($foo(3, 4, )); $this->createMock($foo(5, 6, ), ); $this->createPartialMock("Foo", ["aaa"], ); $this->createPartialMock("Foo", ["bbb", ], ); $this->getMock("Foo", ["aaa"], ["argument"], ); $this->getMock("Foo", ["bbb", ], ["argument", ], ); } }', 'getMock("Foo",); $this->getMock("Bar" ,); $this->getMock("Baz" , ); $this->getMock($foo(1, 2), ); $this->getMock($foo(3, 4, )); $this->getMock($foo(5, 6, ), ); $this->getMock("Foo", ["aaa"], ); $this->getMock("Foo", ["bbb", ], ); $this->getMock("Foo", ["aaa"], ["argument"], ); $this->getMock("Foo", ["bbb", ], ["argument", ], ); } }', ]; } /** * @requires PHP 8.0 */ public function testFix80(): void { $this->doTest( 'createMock("Foo"); } }', 'getMock("Foo"); } }' ); } }