Skip to content

Commit bf0add0

Browse files
committed
[Tests] Added coverage for the rule to remove class aliases
1 parent 52adc1c commit bf0add0

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php /** @noinspection ALL */
2+
3+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
4+
5+
class MyAnotherLegacyClass
6+
{
7+
public function foo(): void
8+
{
9+
}
10+
}
11+
12+
class_alias(MyAnotherLegacyClass::class, 'eZ\Some\Namespace\MyAnotherLegacyClass');
13+
14+
?>
15+
-----
16+
<?php /** @noinspection ALL */
17+
18+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
19+
20+
class MyAnotherLegacyClass
21+
{
22+
public function foo(): void
23+
{
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php /** @noinspection ALL */
2+
3+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
4+
5+
class MyIbexaClass
6+
{
7+
public function foo(): void
8+
{
9+
}
10+
}
11+
12+
class_alias(MyIbexaClass::class, 'Ibexa\Platform\MyAnotherLegacyClass');
13+
14+
?>
15+
-----
16+
<?php /** @noinspection ALL */
17+
18+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
19+
20+
class MyIbexaClass
21+
{
22+
public function foo(): void
23+
{
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php /** @noinspection ALL */
2+
3+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
4+
5+
class MyLegacyClass
6+
{
7+
public function foo(): void
8+
{
9+
}
10+
}
11+
12+
class_alias(MyLegacyClass::class, 'EzSystems\Some\Namespace\MyLegacyClass');
13+
14+
?>
15+
-----
16+
<?php /** @noinspection ALL */
17+
18+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
19+
20+
class MyLegacyClass
21+
{
22+
public function foo(): void
23+
{
24+
}
25+
}
26+
27+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php /** @noinspection ALL */
2+
3+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
4+
5+
class ThirdPartyClass
6+
{
7+
public function foo(): void
8+
{
9+
}
10+
}
11+
12+
// this is not ours, should remain
13+
class_alias(ThirdPartyClass::class, 'ThirdPartyVendor\Accidental\Ibexa\Collsion');
14+
15+
?>
16+
-----
17+
<?php /** @noinspection ALL */
18+
19+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;
20+
21+
class ThirdPartyClass
22+
{
23+
public function foo(): void
24+
{
25+
}
26+
}
27+
28+
// this is not ours, should remain
29+
class_alias(ThirdPartyClass::class, 'ThirdPartyVendor\Accidental\Ibexa\Collsion');
30+
31+
?>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector;
10+
11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
13+
14+
/**
15+
* @covers \Ibexa\Rector\Rule\Internal\RemoveLegacyClassAliasRector
16+
*/
17+
final class RemoveLegacyClassAliasRectorTest extends AbstractRectorTestCase
18+
{
19+
/**
20+
* @throws \Rector\Exception\ShouldNotHappenException
21+
*/
22+
#[DataProvider('provideData')]
23+
public function test(string $filePath): void
24+
{
25+
$this->doTestFile($filePath);
26+
}
27+
28+
public static function provideData(): \Iterator
29+
{
30+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
31+
}
32+
33+
public function provideConfigFilePath(): string
34+
{
35+
return __DIR__ . '/config/configured_rule.php';
36+
}
37+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
use Ibexa\Rector\Rule\Internal\RemoveLegacyClassAliasRector;
10+
use Rector\Config\RectorConfig;
11+
12+
return static function (RectorConfig $rectorConfig): void {
13+
$rectorConfig->rule(RemoveLegacyClassAliasRector::class);
14+
};

0 commit comments

Comments
 (0)