mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 04:10:51 +00:00
make use of Symplify/EasyTesting
This commit is contained in:
parent
6d2aad57a6
commit
f713c16afd
|
@ -31,12 +31,12 @@
|
|||
"symfony/dependency-injection": "^4.4.8|^5.0.6",
|
||||
"symfony/finder": "^4.4.8|^5.0.6",
|
||||
"symfony/process": "^4.4.8|^5.0.6",
|
||||
"symplify/auto-bind-parameter": "^8.1",
|
||||
"symplify/autowire-array-parameter": "^8.1",
|
||||
"symplify/console-color-diff": "^8.1",
|
||||
"symplify/package-builder": "^8.1",
|
||||
"symplify/parameter-name-guard": "^8.1",
|
||||
"symplify/set-config-resolver": "^8.1",
|
||||
"symplify/auto-bind-parameter": "^8.1.2",
|
||||
"symplify/autowire-array-parameter": "^8.1.2",
|
||||
"symplify/console-color-diff": "^8.1.2",
|
||||
"symplify/package-builder": "^8.1.2",
|
||||
"symplify/parameter-name-guard": "^8.1.2",
|
||||
"symplify/set-config-resolver": "^8.1.2",
|
||||
"tracy/tracy": "^2.7"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -46,11 +46,11 @@
|
|||
"psr/event-dispatcher": "^1.0",
|
||||
"slam/phpstan-extensions": "^5.0",
|
||||
"slevomat/coding-standard": "dev-master",
|
||||
"symplify/changelog-linker": "^8.1",
|
||||
"symplify/easy-coding-standard": "^8.1",
|
||||
"symplify/monorepo-builder": "^8.1",
|
||||
"symplify/phpstan-extensions": "^8.1",
|
||||
"symplify/easy-testing": "^8.1",
|
||||
"symplify/changelog-linker": "^8.1.2",
|
||||
"symplify/easy-coding-standard": "^8.1.2",
|
||||
"symplify/monorepo-builder": "^8.1.2",
|
||||
"symplify/phpstan-extensions": "^8.1.2",
|
||||
"symplify/easy-testing": "^8.1.2",
|
||||
"thecodingmachine/phpstan-strict-rules": "^0.12"
|
||||
},
|
||||
"replace": {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// just for the test
|
|
@ -5,8 +5,6 @@ namespace Rector\NetteTesterToPHPUnit\Tests\Rector\StaticCall\NetteAssertToPHPUn
|
|||
use Rector\NetteTesterToPHPUnit\Tests\Rector\Class_\NetteTesterClassToPHPUnitClassRector\Source\ORMTestCase;
|
||||
use Tester\Assert;
|
||||
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
class EventsCompatibilityTest extends ORMTestCase
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -5,8 +5,6 @@ namespace Rector\NetteTesterToPHPUnit\Tests\Rector\Class_\NetteTesterClassToPHPU
|
|||
use Tester\Assert;
|
||||
use Tester\TestCase;
|
||||
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
class ExtensionTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace Rector\NetteTesterToPHPUnit\Tests\Rector\Class_\NetteTesterClassToPHPUnitClassRector;
|
||||
|
||||
use Iterator;
|
||||
use Nette\Utils\FileSystem;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\NetteTesterToPHPUnit\Rector\Class_\NetteTesterClassToPHPUnitClassRector;
|
||||
use Rector\NetteTesterToPHPUnit\Rector\StaticCall\NetteAssertToPHPUnitAssertRector;
|
||||
|
@ -17,9 +16,6 @@ final class NetteTesterPHPUnitRectorTest extends AbstractRectorTestCase
|
|||
*/
|
||||
public function test(string $file): void
|
||||
{
|
||||
// prepare dummy data
|
||||
FileSystem::copy(__DIR__ . '/Copy', $this->getTempPath());
|
||||
|
||||
$this->doTestFile($file);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
|||
use Rector\RemovingStatic\Rector\Class_\NewUniqueObjectToEntityFactoryRector;
|
||||
use Rector\RemovingStatic\Rector\Class_\PassFactoryToUniqueObjectRector;
|
||||
use Rector\RemovingStatic\Tests\Rector\Class_\PassFactoryToEntityRector\Source\TurnMeToService;
|
||||
use Symplify\EasyTesting\Fixture\StaticFixtureSplitter;
|
||||
|
||||
final class PassFactoryToEntityRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
|
@ -19,11 +20,12 @@ final class PassFactoryToEntityRectorTest extends AbstractRectorTestCase
|
|||
{
|
||||
$this->doTestFile($file);
|
||||
|
||||
// test factory content
|
||||
$this->assertFileExists($this->getTempPath() . '/AnotherClassWithMoreArgumentsFactory.php');
|
||||
$expectedFactoryFilePath = StaticFixtureSplitter::getTemporaryPath() . '/AnotherClassWithMoreArgumentsFactory.php';
|
||||
|
||||
$this->assertFileExists($expectedFactoryFilePath);
|
||||
$this->assertFileEquals(
|
||||
__DIR__ . '/Source/ExpectedAnotherClassWithMoreArgumentsFactory.php',
|
||||
$this->getTempPath() . '/AnotherClassWithMoreArgumentsFactory.php'
|
||||
$expectedFactoryFilePath
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ final class RenameNonPhpTest extends AbstractRectorTestCase
|
|||
*/
|
||||
public function test(string $filePath): void
|
||||
{
|
||||
$this->doTestFile($filePath);
|
||||
$this->doTestFileWithoutAutoload($filePath);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
|
|
|
@ -28,11 +28,6 @@ abstract class AbstractNodeVisitorTestCase extends AbstractKernelTestCase
|
|||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @var FixtureSplitter
|
||||
*/
|
||||
protected $fixtureSplitter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootKernelWithConfigs(RectorKernel::class, []);
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symplify\EasyTesting\Fixture\StaticFixtureSplitter;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
use Symplify\SetConfigResolver\ConfigResolver;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
@ -49,11 +50,6 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
|
|||
*/
|
||||
protected $originalTempFileInfo;
|
||||
|
||||
/**
|
||||
* @var FixtureSplitter
|
||||
*/
|
||||
protected $fixtureSplitter;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -83,8 +79,7 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->fixtureSplitter = new FixtureSplitter($this->getTempPath());
|
||||
$this->runnableRectorFactory = new RunnableRectorFactory($this->fixtureSplitter);
|
||||
$this->runnableRectorFactory = new RunnableRectorFactory();
|
||||
|
||||
if ($this->provideConfig() !== '') {
|
||||
$this->ensureConfigFileExists();
|
||||
|
@ -153,7 +148,7 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
|
|||
{
|
||||
$fixtureFileInfo = new SmartFileInfo($fixtureFile);
|
||||
|
||||
[$originalFileInfo, $expectedFileInfo] = $this->fixtureSplitter->splitContentToOriginalFileAndExpectedFile(
|
||||
[$originalFileInfo, $expectedFileInfo] = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos(
|
||||
$fixtureFileInfo,
|
||||
$this->autoloadTestFixture
|
||||
);
|
||||
|
@ -201,7 +196,8 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
|
|||
|
||||
protected function doTestExtraFile(string $expectedExtraFileName, string $expectedExtraContentFilePath): void
|
||||
{
|
||||
$expectedFilePath = sys_get_temp_dir() . '/rector_temp_tests/' . $expectedExtraFileName;
|
||||
$temporaryPath = StaticFixtureSplitter::getTemporaryPath();
|
||||
$expectedFilePath = $temporaryPath . '/' . $expectedExtraFileName;
|
||||
$this->assertFileExists($expectedFilePath);
|
||||
|
||||
$this->assertFileEquals($expectedExtraContentFilePath, $expectedFilePath);
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Testing\PHPUnit;
|
||||
|
||||
use Nette\Utils\FileSystem;
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Core\Testing\ValueObject\SplitLine;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class FixtureSplitter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $tempPath;
|
||||
|
||||
public function __construct(string $tempPath)
|
||||
{
|
||||
$this->tempPath = $tempPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SmartFileInfo[]
|
||||
*/
|
||||
public function splitContentToOriginalFileAndExpectedFile(
|
||||
SmartFileInfo $smartFileInfo,
|
||||
bool $autoloadTestFixture
|
||||
): array {
|
||||
[$originalContent, $expectedContent] = $this->resolveBeforeAfterFixtureContent($smartFileInfo);
|
||||
|
||||
$originalFile = $this->createTemporaryPathWithPrefix($smartFileInfo, 'original');
|
||||
$expectedFile = $this->createTemporaryPathWithPrefix($smartFileInfo, 'expected');
|
||||
|
||||
FileSystem::write($originalFile, $originalContent);
|
||||
FileSystem::write($expectedFile, $expectedContent);
|
||||
|
||||
// file needs to be autoload so PHPStan can analyze
|
||||
if ($autoloadTestFixture && Strings::match($smartFileInfo->getFilename(), '#\.php(\.inc)?$#')) {
|
||||
require_once $originalFile;
|
||||
}
|
||||
|
||||
$originalFileInfo = new SmartFileInfo($originalFile);
|
||||
$expectedFileInfo = new SmartFileInfo($expectedFile);
|
||||
|
||||
return [$originalFileInfo, $expectedFileInfo];
|
||||
}
|
||||
|
||||
public function createTemporaryPathWithPrefix(SmartFileInfo $smartFileInfo, string $prefix): string
|
||||
{
|
||||
// warning: if this hash is too short, the file can becom "identical"; took me 1 hour to find out
|
||||
$hash = Strings::substring(md5($smartFileInfo->getRealPath()), -15);
|
||||
|
||||
return sprintf($this->tempPath . '/%s_%s_%s', $prefix, $hash, $smartFileInfo->getBasename('.inc'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function resolveBeforeAfterFixtureContent(SmartFileInfo $smartFileInfo): array
|
||||
{
|
||||
if (Strings::match($smartFileInfo->getContents(), SplitLine::REGEX)) {
|
||||
// original → expected
|
||||
[$originalContent, $expectedContent] = Strings::split($smartFileInfo->getContents(), SplitLine::REGEX);
|
||||
} else {
|
||||
// no changes
|
||||
$originalContent = $smartFileInfo->getContents();
|
||||
$expectedContent = $originalContent;
|
||||
}
|
||||
|
||||
return [$originalContent, $expectedContent];
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ namespace Rector\Core\Testing\PHPUnit;
|
|||
|
||||
use Nette\Utils\FileSystem;
|
||||
use Nette\Utils\Random;
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Core\Testing\Contract\RunnableInterface;
|
||||
use Rector\Core\Testing\PHPUnit\Runnable\ClassLikeNamesSuffixer;
|
||||
use Rector\Core\Testing\PHPUnit\Runnable\RunnableClassFinder;
|
||||
|
@ -13,11 +14,6 @@ use Symplify\SmartFileSystem\SmartFileInfo;
|
|||
|
||||
final class RunnableRectorFactory
|
||||
{
|
||||
/**
|
||||
* @var FixtureSplitter
|
||||
*/
|
||||
private $fixtureSplitter;
|
||||
|
||||
/**
|
||||
* @var RunnableClassFinder
|
||||
*/
|
||||
|
@ -28,18 +24,17 @@ final class RunnableRectorFactory
|
|||
*/
|
||||
private $classLikeNamesSuffixer;
|
||||
|
||||
public function __construct(FixtureSplitter $fixtureSplitter)
|
||||
public function __construct()
|
||||
{
|
||||
$this->fixtureSplitter = $fixtureSplitter;
|
||||
$this->runnableClassFinder = new RunnableClassFinder();
|
||||
$this->classLikeNamesSuffixer = new ClassLikeNamesSuffixer();
|
||||
}
|
||||
|
||||
public function createRunnableClass(SmartFileInfo $classFileContent): RunnableInterface
|
||||
public function createRunnableClass(SmartFileInfo $classContentFileInfo): RunnableInterface
|
||||
{
|
||||
$temporaryPath = $this->fixtureSplitter->createTemporaryPathWithPrefix($classFileContent, 'runnable');
|
||||
$temporaryPath = $this->createTemporaryPathWithPrefix($classContentFileInfo);
|
||||
|
||||
$fileContent = $classFileContent->getContents();
|
||||
$fileContent = $classContentFileInfo->getContents();
|
||||
$classNameSuffix = $this->getTemporaryClassSuffix();
|
||||
|
||||
$suffixedFileContent = $this->classLikeNamesSuffixer->suffixContent($fileContent, $classNameSuffix);
|
||||
|
@ -56,4 +51,12 @@ final class RunnableRectorFactory
|
|||
{
|
||||
return Random::generate(30);
|
||||
}
|
||||
|
||||
private function createTemporaryPathWithPrefix(SmartFileInfo $smartFileInfo): string
|
||||
{
|
||||
// warning: if this hash is too short, the file can becom "identical"; took me 1 hour to find out
|
||||
$hash = Strings::substring(md5($smartFileInfo->getRealPath()), -15);
|
||||
|
||||
return sprintf(sys_get_temp_dir() . '/_rector_runnable_%s_%s', $hash, $smartFileInfo->getBasename('.inc'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user