fix tests by making paramter provider aware of source

This commit is contained in:
TomasVotruba 2017-12-20 14:43:48 +01:00
parent aa1d9c0f6c
commit bb7225c625
3 changed files with 12 additions and 3 deletions

View File

@ -4,14 +4,15 @@ namespace Rector\Testing\PHPUnit;
use Rector\Application\FileProcessor;
use Rector\DependencyInjection\ContainerFactory;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
abstract class AbstractConfigurableRectorTestCase extends AbstractRectorTestCase
{
protected function setUp(): void
{
$this->container = (new ContainerFactory())->createWithConfig($this->provideConfig());
$this->fileProcessor = $this->container->get(FileProcessor::class);
$this->parameterProvider = $this->container->get(ParameterProvider::class);
}
abstract protected function provideConfig(): string;

View File

@ -8,6 +8,7 @@ use Rector\Application\FileProcessor;
use Rector\DependencyInjection\ContainerFactory;
use Rector\FileSystem\FileGuard;
use SplFileInfo;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
abstract class AbstractRectorTestCase extends TestCase
{
@ -21,11 +22,16 @@ abstract class AbstractRectorTestCase extends TestCase
*/
protected $container;
/**
* @var ParameterProvider
*/
protected $parameterProvider;
protected function setUp(): void
{
$this->container = (new ContainerFactory())->createWithConfig(__DIR__ . '/../../config/levels.yml');
$this->fileProcessor = $this->container->get(FileProcessor::class);
$this->parameterProvider = $this->container->get(ParameterProvider::class);
}
protected function doTestFileMatchesExpectedContent(string $file, string $reconstructedFile): void
@ -33,6 +39,8 @@ abstract class AbstractRectorTestCase extends TestCase
FileGuard::ensureFileExists($file, get_called_class());
FileGuard::ensureFileExists($reconstructedFile, get_called_class());
$this->parameterProvider->changeParameter('source', [$file]);
$reconstructedFileContent = $this->fileProcessor->processFileWithRectorsToString(
new SplFileInfo($file),
$this->getRectorClasses()

View File

@ -2,7 +2,7 @@ rectors:
Rector\Rector\Contrib\Nette\Environment\GetServiceToConstructorInjectionRector: ~
services:
Rector\Tests\Rector\Contrib\Nette\Environment\GetServiceToConstructorInjectionRector\Source\DummyProvider:
Rector\Tests\Rector\Contrib\Nette\Environment\GetServiceToConstructorInjectionRector\Source\DummyProvider: ~
# require for interface autowiring
Rector\Contract\Bridge\ServiceTypeForNameProviderInterface: