mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
[YamlParser] move test NamedServiceToClassRector, allow config
This commit is contained in:
parent
a69fcc020f
commit
b10f48e328
@ -7,6 +7,17 @@ use Rector\YamlParser\Contract\Rector\YamlRectorInterface;
|
||||
/**
|
||||
* Turn custom names of services,
|
||||
* to class based ones.
|
||||
*
|
||||
* Before:
|
||||
*
|
||||
* services:
|
||||
* some_class:
|
||||
* class: SomeClass
|
||||
*
|
||||
* After:
|
||||
*
|
||||
* services:
|
||||
* SomeClass: ~
|
||||
*/
|
||||
final class NamedServiceToClassRector implements YamlRectorInterface
|
||||
{
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\YamlParser\Tests\Rector\Contrib\Symfony;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\DependencyInjection\ContainerFactory;
|
||||
use Rector\YamlParser\YamlRectorCollector;
|
||||
|
||||
final class NamedServiceToClassRectorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var YamlRectorCollector
|
||||
*/
|
||||
private $yamlRectorCollector;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$container = (new ContainerFactory())->createWithConfig($this->provideConfig());
|
||||
$this->yamlRectorCollector = $container->get(YamlRectorCollector::class);
|
||||
}
|
||||
|
||||
public function test(): void
|
||||
{
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__ . '/Source/expected.some_services.yml',
|
||||
$this->yamlRectorCollector->processFile(__DIR__ . '/Source/some_services.yml')
|
||||
);
|
||||
}
|
||||
|
||||
private function provideConfig(): string
|
||||
{
|
||||
return __DIR__ . '/Source/config.yml';
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
rectors:
|
||||
Rector\YamlParser\Rector\Contrib\Symfony\NamedServiceToClassRector: ~
|
@ -1,29 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\YamlParser\Tests;
|
||||
|
||||
use Rector\Tests\AbstractContainerAwareTestCase;
|
||||
use Rector\YamlParser\YamlRectorCollector;
|
||||
|
||||
final class YamlRectorCollectorTest extends AbstractContainerAwareTestCase
|
||||
{
|
||||
/**
|
||||
* @var YamlRectorCollector
|
||||
*/
|
||||
private $yamlRectorCollector;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->yamlRectorCollector = $this->container->get(YamlRectorCollector::class);
|
||||
}
|
||||
|
||||
public function testSymfonyServiceRename(): void
|
||||
{
|
||||
$file = __DIR__ . '/YamlRectorCollectorSource/some_services.yml';
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__ . '/YamlRectorCollectorSource/expected.some_services.yml',
|
||||
$this->yamlRectorCollector->processFile($file)
|
||||
);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace Rector\Configuration\Validator;
|
||||
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\Exception\Validator\InvalidRectorClassException;
|
||||
use Rector\YamlParser\Contract\Rector\YamlRectorInterface;
|
||||
|
||||
final class RectorClassValidator
|
||||
{
|
||||
@ -36,10 +37,15 @@ final class RectorClassValidator
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_a($rector, YamlRectorInterface::class, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidRectorClassException(sprintf(
|
||||
'Rector "%s" is not supported. Use class that implements "%s".',
|
||||
'Rector "%s" is not supported. Use class that implements "%s" or "%s".',
|
||||
$rector,
|
||||
RectorInterface::class
|
||||
RectorInterface::class,
|
||||
YamlRectorInterface::class
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user