* 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\Tests\Test\AbstractFixerTestCase; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer */ final class PhpUnitStrictFixerTest extends AbstractFixerTestCase { /** * @param string $expected * @param null|string $input * * @dataProvider provideTestFixCases */ public function testFix($expected, $input = null) { $this->doTest($expected, $input); $this->fixer->configure(['assertions' => [ 'assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals', ]]); $this->doTest($expected, $input); } public function provideTestFixCases() { $methodsMap = [ 'assertAttributeEquals' => 'assertAttributeSame', 'assertAttributeNotEquals' => 'assertAttributeNotSame', 'assertEquals' => 'assertSame', 'assertNotEquals' => 'assertNotSame', ]; $cases = [ ['foo();'], ]; foreach ($methodsMap as $methodBefore => $methodAfter) { $cases[] = ["${methodBefore}(1, 1);"]; $cases[] = ["${methodAfter}(1, 1);"]; $cases[] = [ "${methodAfter}(1, 2);", "${methodBefore}(1, 2);", ]; $cases[] = [ "${methodAfter}(1, 2); \$this->${methodAfter}(1, 2);", "${methodBefore}(1, 2); \$this->${methodBefore}(1, 2);", ]; $cases[] = [ "${methodAfter}(1, 2, 'descr');", "${methodBefore}(1, 2, 'descr');", ]; $cases[] = [ "/*aaa*/${methodAfter} \t /**bbb*/ ( /*ccc*/1 , 2);", "/*aaa*/${methodBefore} \t /**bbb*/ ( /*ccc*/1 , 2);", ]; $cases[] = [ "${methodAfter}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');", "${methodBefore}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');", ]; } return $cases; } public function testInvalidConfig() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp('/^\[php_unit_strict\] Invalid configuration: The option "assertions" .*\.$/'); $this->fixer->configure(['assertions' => ['__TEST__']]); } }