Resolves #4. Add fixer to replace ::className() method usages with ::class keyword.

This commit is contained in:
erickskrauch
2018-08-06 11:59:44 +03:00
parent 76bd14c167
commit 59e9994662
4 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace Ely\CS\Test\Fixer\Operator;
use Ely\CS\Fixer\LanguageConstruct\RemoveClassNameMethodUsagesFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
/**
* @covers \Ely\CS\Fixer\LanguageConstruct\RemoveClassNameMethodUsagesFixer
*/
class RemoveClassNameMethodUsagesFixerTest extends AbstractFixerTestCase {
/**
* @param string $expected
* @param null|string $input
*
* @dataProvider provideFixCases
*/
public function testFix($expected, $input = null) {
$this->doTest($expected, $input);
}
public function provideFixCases() {
return [
[
'<?php echo className();',
],
[
'<?php
use Foo\Bar\Baz;
$exceptionString = Baz::classname();
',
],
[
'<?php
use Foo\Bar\Baz;
$className = Baz::class;
',
'<?php
use Foo\Bar\Baz;
$className = Baz::className();
',
],
[
'<?php
use Foo\Bar\Baz;
$exceptionString = "The class should be instance of " . Baz::class . " and nothing else";
',
'<?php
use Foo\Bar\Baz;
$exceptionString = "The class should be instance of " . Baz::className() . " and nothing else";
',
],
];
}
protected function createFixer() {
return new RemoveClassNameMethodUsagesFixer();
}
}