Skip to content

Commit

Permalink
[Tests] Added coverage for the rule to remove class aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed May 9, 2024
1 parent 9bb4137 commit db459d1
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyAnotherLegacyClass
{
public function foo(): void
{
}
}

class_alias(MyAnotherLegacyClass::class, 'eZ\Some\Namespace\MyAnotherLegacyClass');

?>
-----
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyAnotherLegacyClass
{
public function foo(): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyIbexaClass
{
public function foo(): void
{
}
}

class_alias(MyIbexaClass::class, 'Ibexa\Platform\MyAnotherLegacyClass');

?>
-----
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyIbexaClass
{
public function foo(): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyLegacyClass
{
public function foo(): void
{
}
}

class_alias(MyLegacyClass::class, 'EzSystems\Some\Namespace\MyLegacyClass');

?>
-----
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class MyLegacyClass
{
public function foo(): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class ThirdPartyClass
{
public function foo(): void
{
}
}

// this is not ours, should remain
class_alias(ThirdPartyClass::class, 'ThirdPartyVendor\Accidental\Ibexa\Collsion');

?>
-----
<?php /** @noinspection ALL */

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector\Fixture;

class ThirdPartyClass
{
public function foo(): void
{
}
}

// this is not ours, should remain
class_alias(ThirdPartyClass::class, 'ThirdPartyVendor\Accidental\Ibexa\Collsion');

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rector\Tests\Rule\Internal\RemoveLegacyClassAliasRector;

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

/**
* @covers \Ibexa\Rector\Rule\Internal\RemoveLegacyClassAliasRector
*/
final class RemoveLegacyClassAliasRectorTest extends AbstractRectorTestCase
{
/**
* @throws \Rector\Exception\ShouldNotHappenException
*/
#[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/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

use Ibexa\Rector\Rule\Internal\RemoveLegacyClassAliasRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(RemoveLegacyClassAliasRector::class);
};

0 comments on commit db459d1

Please sign in to comment.