simplify Dynamic tests

This commit is contained in:
TomasVotruba 2017-10-14 23:38:11 +02:00
parent d8795a68ac
commit d9c09cc2e4
5 changed files with 62 additions and 126 deletions

View File

@ -1,12 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\Rector\Contrib\Nette\Helper;
use PhpParser\Node\Arg;
final class ServiceFromEnvironmentResolver
{
public function resolveServiceClassFromArgument(Arg $argNode): string
{
}
}

View File

@ -4,5 +4,3 @@ rectors:
'Image': 'Nette\Image'
Rector\Rector\Contrib\Nette\Routing\BootstrapToRouterFactoryRector: ~
Rector\Rector\Contrib\Nette\Routing\CleanupBootstrapToRouterFactoryRector: ~
Rector\Rector\Contrib\Nette\Environment\GetServiceToConstructorInjectionRector: ~

View File

@ -2,62 +2,34 @@
namespace Rector\Tests\Rector\Dynamic\ClassReplacerRector;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Rector\Application\FileProcessor;
use Rector\DependencyInjection\ContainerFactory;
use Rector\Rector\Dynamic\ClassReplacerRector;
use SplFileInfo;
use Rector\Testing\PHPUnit\AbstractConfigurableRectorTestCase;
final class Test extends TestCase
final class Test extends AbstractConfigurableRectorTestCase
{
/**
* @var ClassReplacerRector
*/
private $classReplacerRector;
/**
* @var FileProcessor
*/
private $fileProcessor;
protected function setUp(): void
public function test(): void
{
$container = (new ContainerFactory)->createWithConfig(
__DIR__ . '/config/rector.yml'
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong.php.inc',
__DIR__ . '/correct/correct.php.inc'
);
$this->fileProcessor = $container->get(FileProcessor::class);
$this->classReplacerRector = $container->get(ClassReplacerRector::class);
}
public function testConfiguration(): void
{
$oldToNewClasses = Assert::getObjectAttribute($this->classReplacerRector, 'oldToNewClasses');
$this->assertNotSame([], $oldToNewClasses);
}
/**
* @dataProvider provideTestFiles()
*/
public function testProcessing(string $testedFile, string $expectedFile): void
{
$refactoredFileContent = $this->fileProcessor->processFileWithRectorsToString(
new SplFileInfo($testedFile),
[ClassReplacerRector::class]
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong2.php.inc',
__DIR__ . '/correct/correct2.php.inc'
);
}
$this->assertStringEqualsFile($expectedFile, $refactoredFileContent);
protected function provideConfig(): string
{
return __DIR__ . '/config/rector.yml';
}
/**
* @return string[][]
* @return string[]
*/
public function provideTestFiles(): array
protected function getRectorClasses(): array
{
return [
[__DIR__ . '/wrong/wrong.php.inc', __DIR__ . '/correct/correct.php.inc'],
[__DIR__ . '/wrong/wrong2.php.inc', __DIR__ . '/correct/correct2.php.inc'],
];
return [ClassReplacerRector::class];
}
}

View File

@ -2,49 +2,34 @@
namespace Rector\Tests\Rector\Dynamic\MethodArgumentChangerRector;
use PHPUnit\Framework\TestCase;
use Rector\Application\FileProcessor;
use Rector\DependencyInjection\ContainerFactory;
use Rector\Rector\Dynamic\MethodArgumentChangerRector;
use SplFileInfo;
use Rector\Testing\PHPUnit\AbstractConfigurableRectorTestCase;
final class Test extends TestCase
final class Test extends AbstractConfigurableRectorTestCase
{
/**
* @var FileProcessor
*/
private $fileProcessor;
protected function setUp(): void
protected function provideConfig(): string
{
$container = (new ContainerFactory)->createWithConfig(
__DIR__ . '/config/rector.yml'
return __DIR__ . '/config/rector.yml';
}
public function test(): void
{
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong.php.inc',
__DIR__ . '/correct/correct.php.inc'
);
$this->fileProcessor = $container->get(FileProcessor::class);
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong2.php.inc',
__DIR__ . '/correct/correct2.php.inc'
);
}
/**
* @dataProvider provideTestFiles()
* @return string[]
*/
public function testProcessing(string $testedFile, string $expectedFile): void
protected function getRectorClasses(): array
{
$refactoredFileContent = $this->fileProcessor->processFileWithRectorsToString(
new SplFileInfo($testedFile),
[MethodArgumentChangerRector::class]
);
$this->assertStringEqualsFile($expectedFile, $refactoredFileContent);
}
/**
* @return string[][]
*/
public function provideTestFiles(): array
{
return [
[__DIR__ . '/wrong/wrong.php.inc', __DIR__ . '/correct/correct.php.inc'],
[__DIR__ . '/wrong/wrong2.php.inc', __DIR__ . '/correct/correct2.php.inc'],
];
return [MethodArgumentChangerRector::class];
}
}

View File

@ -2,51 +2,44 @@
namespace Rector\Tests\Rector\Dynamic\NamespaceReplacerRector;
use PHPUnit\Framework\TestCase;
use Rector\Application\FileProcessor;
use Rector\DependencyInjection\ContainerFactory;
use Rector\Rector\Dynamic\NamespaceReplacerRector;
use SplFileInfo;
use Rector\Testing\PHPUnit\AbstractConfigurableRectorTestCase;
final class Test extends TestCase
final class Test extends AbstractConfigurableRectorTestCase
{
/**
* @var FileProcessor
*/
private $fileProcessor;
protected function setUp(): void
public function test(): void
{
$container = (new ContainerFactory)->createWithConfig(
__DIR__ . '/config/rector.yml'
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong.php.inc',
__DIR__ . '/correct/correct.php.inc'
);
$this->fileProcessor = $container->get(FileProcessor::class);
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong2.php.inc',
__DIR__ . '/correct/correct2.php.inc'
);
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong3.php.inc',
__DIR__ . '/correct/correct3.php.inc'
);
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong4.php.inc',
__DIR__ . '/correct/correct4.php.inc'
);
}
protected function provideConfig(): string
{
return __DIR__ . '/config/rector.yml';
}
/**
* @dataProvider provideTestFiles()
* @return string[]
*/
public function test(string $testedFile, string $expectedFile): void
protected function getRectorClasses(): array
{
$refactoredFileContent = $this->fileProcessor->processFileWithRectorsToString(
new SplFileInfo($testedFile),
[NamespaceReplacerRector::class]
);
$this->assertStringEqualsFile($expectedFile, $refactoredFileContent);
}
/**
* @return string[][]
*/
public function provideTestFiles(): array
{
return [
[__DIR__ . '/wrong/wrong.php.inc', __DIR__ . '/correct/correct.php.inc'],
[__DIR__ . '/wrong/wrong2.php.inc', __DIR__ . '/correct/correct2.php.inc'],
[__DIR__ . '/wrong/wrong3.php.inc', __DIR__ . '/correct/correct3.php.inc'],
[__DIR__ . '/wrong/wrong4.php.inc', __DIR__ . '/correct/correct4.php.inc'],
];
return [NamespaceReplacerRector::class];
}
}