mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-20 16:30:22 +00:00
remove unused RectorContainerFactoryTest, also createFromSet() method
This commit is contained in:
parent
97571e6159
commit
f1d54301a3
@ -36,10 +36,10 @@ final class DoctrineRepositoryAsServiceTest extends AbstractRectorTestCase
|
||||
{
|
||||
return [
|
||||
# order matters, this needs to be first to correctly detect parent repository
|
||||
MoveRepositoryFromParentToConstructorRector::class => null,
|
||||
ServiceLocatorToDIRector::class => null,
|
||||
ReplaceParentRepositoryCallsByRepositoryPropertyRector::class => null,
|
||||
RemoveRepositoryFromEntityAnnotationRector::class => null,
|
||||
MoveRepositoryFromParentToConstructorRector::class => [],
|
||||
ServiceLocatorToDIRector::class => [],
|
||||
ReplaceParentRepositoryCallsByRepositoryPropertyRector::class => [],
|
||||
RemoveRepositoryFromEntityAnnotationRector::class => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -5,44 +5,11 @@ declare(strict_types=1);
|
||||
namespace Rector\Core\DependencyInjection;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\Core\Set\Set;
|
||||
use Symplify\PackageBuilder\Console\Input\InputDetector;
|
||||
use Symplify\SetConfigResolver\SetResolver;
|
||||
|
||||
final class RectorContainerFactory
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
* local config has priority
|
||||
*/
|
||||
private const LOCAL_CONFIGS = ['rector.yml', 'rector.yaml'];
|
||||
|
||||
/**
|
||||
* @var SetResolver
|
||||
*/
|
||||
private $setResolver;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setResolver = new SetResolver();
|
||||
}
|
||||
|
||||
public function createFromSet(string $set): ContainerInterface
|
||||
{
|
||||
$configs = [];
|
||||
$configs[] = $this->resolveConfigFromSet($set);
|
||||
|
||||
$localConfigs = $this->resolveLocalConfigs();
|
||||
if ($localConfigs !== []) {
|
||||
// local config has priority, so it's first here
|
||||
$configs = array_merge($localConfigs, $configs);
|
||||
}
|
||||
|
||||
return $this->createFromConfigs($configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @param string[] $configFiles
|
||||
@ -62,32 +29,4 @@ final class RectorContainerFactory
|
||||
|
||||
return $rectorKernel->getContainer();
|
||||
}
|
||||
|
||||
private function resolveConfigFromSet(string $set): string
|
||||
{
|
||||
$config = $this->setResolver->detectFromNameAndDirectory($set, Set::SET_DIRECTORY);
|
||||
if ($config === null) {
|
||||
throw new ShouldNotHappenException(sprintf('Config file for "%s" set was not found', $set));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function resolveLocalConfigs(): array
|
||||
{
|
||||
$configs = [];
|
||||
foreach (self::LOCAL_CONFIGS as $localConfig) {
|
||||
$configRealPath = getcwd() . DIRECTORY_SEPARATOR . $localConfig;
|
||||
if (! file_exists($configRealPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$configs[] = $configRealPath;
|
||||
}
|
||||
|
||||
return $configs;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\Core\DependencyInjection\RectorContainerFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symplify\SetConfigResolver\Exception\SetNotFoundException;
|
||||
|
||||
final class RectorContainerFactoryTest extends TestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$rectorContainerFactory = new RectorContainerFactory();
|
||||
|
||||
$rectorContainer = $rectorContainerFactory->createFromSet('doctrine');
|
||||
$this->assertInstanceOf(ContainerInterface::class, $rectorContainer);
|
||||
}
|
||||
|
||||
public function testMissingSet(): void
|
||||
{
|
||||
$rectorContainerFactory = new RectorContainerFactory();
|
||||
|
||||
$this->expectException(SetNotFoundException::class);
|
||||
$rectorContainerFactory->createFromSet('bla');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user