2019-10-13 07:59:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-09-22 13:39:33 +02:00
|
|
|
|
2021-03-12 23:20:25 +01:00
|
|
|
namespace Rector\Tests\PSR4;
|
2019-09-22 13:39:33 +02:00
|
|
|
|
|
|
|
use Iterator;
|
2020-02-06 22:48:18 +01:00
|
|
|
use Rector\Core\HttpKernel\RectorKernel;
|
2019-09-22 13:39:33 +02:00
|
|
|
use Rector\PSR4\FileRelocationResolver;
|
2021-03-12 23:20:25 +01:00
|
|
|
use Rector\Tests\PSR4\Source\SomeFile;
|
2020-11-16 17:50:38 +00:00
|
|
|
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
2019-11-23 18:27:18 +01:00
|
|
|
use Symplify\SmartFileSystem\SmartFileInfo;
|
2019-09-22 13:39:33 +02:00
|
|
|
|
|
|
|
final class FileRelocationResolverTest extends AbstractKernelTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var FileRelocationResolver
|
|
|
|
*/
|
|
|
|
private $fileRelocationResolver;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->bootKernel(RectorKernel::class);
|
|
|
|
|
2020-12-23 21:40:46 +01:00
|
|
|
$this->fileRelocationResolver = $this->getService(FileRelocationResolver::class);
|
2019-09-22 13:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-02 18:25:05 +01:00
|
|
|
* @dataProvider provideData()
|
2019-09-22 13:39:33 +02:00
|
|
|
*/
|
|
|
|
public function test(string $file, string $oldClass, string $newClass, string $expectedNewFileLocation): void
|
|
|
|
{
|
|
|
|
$smartFileInfo = new SmartFileInfo($file);
|
|
|
|
|
|
|
|
$newFileLocation = $this->fileRelocationResolver->resolveNewFileLocationFromOldClassToNewClass(
|
|
|
|
$smartFileInfo,
|
|
|
|
$oldClass,
|
|
|
|
$newClass
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame($expectedNewFileLocation, $newFileLocation);
|
|
|
|
}
|
|
|
|
|
2021-03-17 19:59:47 +01:00
|
|
|
/**
|
|
|
|
* @return Iterator<mixed>
|
|
|
|
*/
|
2020-02-02 18:25:05 +01:00
|
|
|
public function provideData(): Iterator
|
2019-09-22 13:39:33 +02:00
|
|
|
{
|
|
|
|
yield [
|
|
|
|
__DIR__ . '/Source/SomeFile.php',
|
|
|
|
SomeFile::class,
|
2021-03-12 23:20:25 +01:00
|
|
|
'Rector\Tests\PSR10\Source\SomeFile',
|
|
|
|
'rules-tests/PSR10/Source/SomeFile.php',
|
2019-09-22 13:39:33 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|