Based on PR https://github.com/rectorphp/rector-nette/pull/26 and https://github.com/rectorphp/rector-nette/pull/23 I've created this generic way how to test Rectors which create / update also another files.
Usage:
Rector:
Add file with content:
$addedFileWithContent = new AddedFileWithContent($templateFilePath, $content);
$this->removedAndAddedFilesCollector->addAddedFile($addedFileWithContent);
Test fixtures
Fixtures contains more parts separated by -----
like in previous tests:
1) original content
-----
2) expected content (keep empty if no change should happen)
-----
3) path to another changed file (relative to file processed)
-----
4) original content of another file (keep empty if file doesn't exist yet)
-----
5) expected content of another file
3-5 can be multiplied in case there are more files created / updated
Fixture example
<?php
namespace Rector\Nette\Tests\Rector\Class_\LatteVarTypesBasedOnPresenterTemplateParametersRector\Fixture;
use Nette\Application\UI\Presenter;
class SomePresenter extends Presenter
{
public function renderDefault(): void
{
$this->template->title = 'My title';
$this->template->count = 123;
}
}
?>
-----
-----
templates/Some/default.latte
-----
<h1>{$title}</h1>
<span class="count">{$count}</span>
-----
{varType string $title}
{varType int $count}
<h1>{$title}</h1>
<span class="count">{$count}</span>
RectorTest
In RectorTest just use
$this->doTestFileInfoWithAdditionalChanges($fileInfo);
instead of
$this->doTestFileInfo($fileInfo);