Skip to content

Commit

Permalink
Add missing test for ConstantToClassConstantRector (#7)
Browse files Browse the repository at this point in the history
* Add missing test for `ConstantToClassConstantRector`

* Update namespace
  • Loading branch information
zoglo authored May 8, 2024
1 parent d5973a1 commit 426478a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Contao\Rector\Tests\Rector\ConstantToClassConstantRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class ConstantToClassConstantRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/config.php';
}
}
14 changes: 14 additions & 0 deletions tests/Rector/ConstantToClassConstantRector/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Contao\CoreBundle\Monolog\ContaoContext;
use Contao\Rector\Rector\ConstantToClassConstantRector;
use Contao\Rector\ValueObject\ConstantToClassConstant;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ConstantToClassConstantRector::class, [
new ConstantToClassConstant('TL_ACCESS', ContaoContext::class, 'ACCESS')
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo extends Controller
{
public function bar()
{
$logLevel = TL_ACCESS;
}
}
?>
-----
<?php

class Foo extends Controller
{
public function bar()
{
$logLevel = \Contao\CoreBundle\Monolog\ContaoContext::ACCESS;
}
}
?>

0 comments on commit 426478a

Please sign in to comment.