4
4
namespace Rector \Testing \PHPUnit ;
5
5
6
6
use Iterator ;
7
+ use RectorPrefix202208 \Nette \Utils \Strings ;
7
8
use PHPStan \Analyser \NodeScopeResolver ;
8
9
use PHPUnit \Framework \ExpectationFailedException ;
9
10
use RectorPrefix202208 \Psr \Container \ContainerInterface ;
16
17
use Rector \Core \ValueObject \Application \File ;
17
18
use Rector \NodeTypeResolver \Reflection \BetterReflection \SourceLocatorProvider \DynamicSourceLocatorProvider ;
18
19
use Rector \Testing \Contract \RectorTestInterface ;
20
+ use Rector \Testing \Fixture \FixtureFileFinder ;
21
+ use Rector \Testing \Fixture \FixtureSplitter ;
22
+ use Rector \Testing \Fixture \FixtureTempFileDumper ;
19
23
use Rector \Testing \PHPUnit \Behavior \MovingFilesTrait ;
20
- use RectorPrefix202208 \ Symplify \ EasyTesting \ DataProvider \ StaticFixtureFinder ;
24
+ use SplFileInfo ;
21
25
use RectorPrefix202208 \Symplify \EasyTesting \DataProvider \StaticFixtureUpdater ;
22
- use RectorPrefix202208 \Symplify \EasyTesting \StaticFixtureSplitter ;
23
26
use RectorPrefix202208 \Symplify \PackageBuilder \Parameter \ParameterProvider ;
24
27
use Symplify \SmartFileSystem \SmartFileInfo ;
25
28
abstract class AbstractRectorTestCase extends \Rector \Testing \PHPUnit \AbstractTestCase implements RectorTestInterface
@@ -59,6 +62,7 @@ protected function setUp() : void
59
62
$ this ->applicationFileProcessor = $ this ->getService (ApplicationFileProcessor::class);
60
63
$ this ->parameterProvider = $ this ->getService (ParameterProvider::class);
61
64
$ this ->dynamicSourceLocatorProvider = $ this ->getService (DynamicSourceLocatorProvider::class);
65
+ // restore added and removed files to 0
62
66
$ this ->removedAndAddedFilesCollector = $ this ->getService (RemovedAndAddedFilesCollector::class);
63
67
$ this ->removedAndAddedFilesCollector ->reset ();
64
68
/** @var AdditionalAutoloader $additionalAutoloader */
@@ -79,30 +83,43 @@ protected function tearDown() : void
79
83
*/
80
84
protected function yieldFilesFromDirectory (string $ directory , string $ suffix = '*.php.inc ' ) : Iterator
81
85
{
82
- return StaticFixtureFinder::yieldDirectoryExclusively ($ directory , $ suffix );
83
- }
84
- /**
85
- * @return Iterator<string, array<int, SmartFileInfo>>
86
- */
87
- protected function yieldFilesWithPathnameFromDirectory (string $ directory , string $ suffix = '*.php.inc ' ) : Iterator
88
- {
89
- return StaticFixtureFinder::yieldDirectoryExclusivelyWithRelativePathname ($ directory , $ suffix );
86
+ return FixtureFileFinder::yieldDirectory ($ directory , $ suffix );
90
87
}
91
88
protected function isWindows () : bool
92
89
{
93
90
return \strncasecmp (\PHP_OS , 'WIN ' , 3 ) === 0 ;
94
91
}
95
- protected function doTestFileInfo (SmartFileInfo $ fixtureFileInfo, bool $ allowMatches = \true) : void
92
+ protected function doTestFileInfo (SmartFileInfo $ fixtureFileInfo)
96
93
{
97
- $ inputFileInfoAndExpectedFileInfo = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos ($ fixtureFileInfo );
98
- $ inputFileInfo = $ inputFileInfoAndExpectedFileInfo ->getInputFileInfo ();
94
+ if (Strings::match ($ fixtureFileInfo ->getContents (), FixtureSplitter::SPLIT_LINE_REGEX )) {
95
+ // changed content
96
+ [$ inputFileContents , $ expectedFileContents ] = FixtureSplitter::loadFileAndSplitInputAndExpected ($ fixtureFileInfo ->getRealPath ());
97
+ } else {
98
+ // no change
99
+ $ inputFileContents = $ fixtureFileInfo ->getContents ();
100
+ $ expectedFileContents = $ fixtureFileInfo ->getContents ();
101
+ }
102
+ $ fileSuffix = $ this ->resolveOriginalFixtureFileSuffix ($ fixtureFileInfo );
103
+ $ inputFileInfo = FixtureTempFileDumper::dump ($ inputFileContents , $ fileSuffix );
104
+ $ expectedFileInfo = FixtureTempFileDumper::dump ($ expectedFileContents , $ fileSuffix );
99
105
$ this ->originalTempFileInfo = $ inputFileInfo ;
100
- $ expectedFileInfo = $ inputFileInfoAndExpectedFileInfo -> getExpectedFileInfo ( );
101
- $ this -> doTestFileMatchesExpectedContent ( $ inputFileInfo , $ expectedFileInfo , $ fixtureFileInfo , $ allowMatches );
106
+ $ this -> doTestFileMatchesExpectedContent ( $ inputFileInfo , $ expectedFileInfo , $ fixtureFileInfo );
107
+ // , $allowMatches);
102
108
}
103
109
protected function getFixtureTempDirectory () : string
104
110
{
105
- return \sys_get_temp_dir () . '/_temp_fixture_easy_testing ' ;
111
+ return \sys_get_temp_dir () . FixtureTempFileDumper::TEMP_FIXTURE_DIRECTORY ;
112
+ }
113
+ private function resolveOriginalFixtureFileSuffix (SplFileInfo $ splFileInfo ) : string
114
+ {
115
+ $ fixtureRealPath = $ splFileInfo ->getRealPath ();
116
+ if (\substr_compare ($ fixtureRealPath , '.inc ' , -\strlen ('.inc ' )) === 0 ) {
117
+ $ fixtureRealPath = \rtrim ($ fixtureRealPath , '.inc ' );
118
+ }
119
+ if (\substr_compare ($ fixtureRealPath , '.blade.php ' , -\strlen ('.blade.php ' )) === 0 ) {
120
+ return 'blade.php ' ;
121
+ }
122
+ return \pathinfo ($ fixtureRealPath , \PATHINFO_EXTENSION );
106
123
}
107
124
private function includePreloadFilesAndScoperAutoload () : void
108
125
{
0 commit comments