mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Updated Rector to commit cc97becc06dcf1b69c5de01aebf09b498c0d9006
cc97becc06
[Testing] In case of failed test using multiple rules, show applied Rector rules to make easy to find them (#5222)
This commit is contained in:
parent
394c30d8ba
commit
23db14797e
|
@ -28,6 +28,7 @@ use Rector\Testing\Contract\RectorTestInterface;
|
|||
use Rector\Testing\Fixture\FixtureFileFinder;
|
||||
use Rector\Testing\Fixture\FixtureFileUpdater;
|
||||
use Rector\Testing\Fixture\FixtureSplitter;
|
||||
use Rector\Testing\PHPUnit\ValueObject\RectorTestResult;
|
||||
abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLazyTestCase implements RectorTestInterface
|
||||
{
|
||||
/**
|
||||
|
@ -186,9 +187,18 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
|
|||
// the original file content must be loaded first
|
||||
$originalFileContent = FileSystem::read($originalFilePath);
|
||||
// the file is now changed (if any rule matches)
|
||||
$changedContent = $this->processFilePath($originalFilePath);
|
||||
$rectorTestResult = $this->processFilePath($originalFilePath);
|
||||
$changedContent = $rectorTestResult->getChangedContents();
|
||||
$fixtureFilename = \basename($fixtureFilePath);
|
||||
$failureMessage = \sprintf('Failed on fixture file "%s"', $fixtureFilename);
|
||||
// give more context about used rules in case of set testing
|
||||
if (\count($rectorTestResult->getAppliedRectorClasses()) > 1) {
|
||||
$failureMessage .= \PHP_EOL . \PHP_EOL;
|
||||
$failureMessage .= 'Applied Rector rules:' . \PHP_EOL;
|
||||
foreach ($rectorTestResult->getAppliedRectorClasses() as $appliedRectorClass) {
|
||||
$failureMessage .= ' * ' . $appliedRectorClass . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->assertSame($expectedFileContents, $changedContent, $failureMessage);
|
||||
} catch (ExpectationFailedException $exception) {
|
||||
|
@ -197,7 +207,7 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
|
|||
$this->assertStringMatchesFormat($expectedFileContents, $changedContent, $failureMessage);
|
||||
}
|
||||
}
|
||||
private function processFilePath(string $filePath) : string
|
||||
private function processFilePath(string $filePath) : RectorTestResult
|
||||
{
|
||||
$this->dynamicSourceLocatorProvider->setFilePath($filePath);
|
||||
/** @var ConfigurationFactory $configurationFactory */
|
||||
|
@ -213,7 +223,8 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
|
|||
$this->applicationFileProcessor->processFiles([$filePath], $configuration);
|
||||
}
|
||||
// return changed file contents
|
||||
return FileSystem::read($filePath);
|
||||
$changedFileContents = FileSystem::read($filePath);
|
||||
return new RectorTestResult($changedFileContents, $processResult);
|
||||
}
|
||||
private function createInputFilePath(string $fixtureFilePath) : string
|
||||
{
|
||||
|
|
|
@ -5,12 +5,6 @@ namespace Rector\Testing\PHPUnit;
|
|||
|
||||
abstract class AbstractTestCase extends \Rector\Testing\PHPUnit\AbstractLazyTestCase
|
||||
{
|
||||
/**
|
||||
* @deprecated only for BC
|
||||
*/
|
||||
protected function boot() : void
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param string[] $configFiles
|
||||
*/
|
||||
|
|
41
packages/Testing/PHPUnit/ValueObject/RectorTestResult.php
Normal file
41
packages/Testing/PHPUnit/ValueObject/RectorTestResult.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Testing\PHPUnit\ValueObject;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\ValueObject\ProcessResult;
|
||||
final class RectorTestResult
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $changedContents;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\ValueObject\ProcessResult
|
||||
*/
|
||||
private $processResult;
|
||||
public function __construct(string $changedContents, ProcessResult $processResult)
|
||||
{
|
||||
$this->changedContents = $changedContents;
|
||||
$this->processResult = $processResult;
|
||||
}
|
||||
public function getChangedContents() : string
|
||||
{
|
||||
return $this->changedContents;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<RectorInterface>>
|
||||
*/
|
||||
public function getAppliedRectorClasses() : array
|
||||
{
|
||||
$rectorClasses = [];
|
||||
foreach ($this->processResult->getFileDiffs() as $fileDiff) {
|
||||
$rectorClasses = \array_merge($rectorClasses, $fileDiff->getRectorClasses());
|
||||
}
|
||||
\sort($rectorClasses);
|
||||
return \array_unique($rectorClasses);
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '2fac959116e4f50471422e5e5c9eaca3163e6667';
|
||||
public const PACKAGE_VERSION = 'cc97becc06dcf1b69c5de01aebf09b498c0d9006';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-03 15:36:34';
|
||||
public const RELEASE_DATE = '2023-11-03 13:00:11';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2216,6 +2216,7 @@ return array(
|
|||
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\StaticPHPUnitEnvironment' => $baseDir . '/packages/Testing/PHPUnit/StaticPHPUnitEnvironment.php',
|
||||
'Rector\\Testing\\PHPUnit\\ValueObject\\RectorTestResult' => $baseDir . '/packages/Testing/PHPUnit/ValueObject/RectorTestResult.php',
|
||||
'Rector\\Testing\\TestingParser\\TestingParser' => $baseDir . '/packages/Testing/TestingParser/TestingParser.php',
|
||||
'Rector\\Transform\\NodeAnalyzer\\FuncCallStaticCallToMethodCallAnalyzer' => $baseDir . '/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php',
|
||||
'Rector\\Transform\\NodeFactory\\PropertyFetchFactory' => $baseDir . '/rules/Transform/NodeFactory/PropertyFetchFactory.php',
|
||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -2434,6 +2434,7 @@ class ComposerStaticInit18ad0e678efbbb500e116f7c54cccdd4
|
|||
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\StaticPHPUnitEnvironment' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/StaticPHPUnitEnvironment.php',
|
||||
'Rector\\Testing\\PHPUnit\\ValueObject\\RectorTestResult' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/ValueObject/RectorTestResult.php',
|
||||
'Rector\\Testing\\TestingParser\\TestingParser' => __DIR__ . '/../..' . '/packages/Testing/TestingParser/TestingParser.php',
|
||||
'Rector\\Transform\\NodeAnalyzer\\FuncCallStaticCallToMethodCallAnalyzer' => __DIR__ . '/../..' . '/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php',
|
||||
'Rector\\Transform\\NodeFactory\\PropertyFetchFactory' => __DIR__ . '/../..' . '/rules/Transform/NodeFactory/PropertyFetchFactory.php',
|
||||
|
|
Loading…
Reference in New Issue
Block a user