Skip to content

Commit

Permalink
[DX] Remove PackageBuilder classes (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Sep 1, 2022
1 parent 6cdebe4 commit 5a28970
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Rector\Core\DependencyInjection\CompilerPass;

use Rector\Core\Contract\Rector\RectorInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class AutowireRectorCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder): void
{
$definitions = $containerBuilder->getDefinitions();

foreach ($definitions as $definition) {
if (! is_a((string) $definition->getClass(), RectorInterface::class, true)) {
continue;
}

$definition->setAutowired(true);
}
}
}
5 changes: 2 additions & 3 deletions src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Rector\Core\Kernel;

use Rector\Core\Config\Loader\ConfigureCallMergingLoaderFactory;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector;
use Rector\Core\DependencyInjection\CompilerPass\AutowireRectorCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\RemoveSkippedRectorsCompilerPass;
Expand All @@ -15,7 +15,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symplify\AutowireArrayParameter\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;
use Symplify\PackageBuilder\ValueObject\ConsoleColorDiffConfig;

final class RectorKernel
Expand Down Expand Up @@ -81,7 +80,7 @@ private function createCompilerPasses(): array
new RemoveSkippedRectorsCompilerPass(),

// autowire Rectors by default (mainly for tests)
new AutowireInterfacesCompilerPass([RectorInterface::class]),
new AutowireRectorCompilerPass(),
new MakeRectorsPublicCompilerPass(),

// add all merged arguments of Rector services
Expand Down
21 changes: 12 additions & 9 deletions tests/Configuration/ValueObjectInliner/ConfigFactoryNestedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
namespace Rector\Core\Tests\Configuration\ValueObjectInliner;

use PHPStan\Type\UnionType;
use PHPUnit\Framework\TestCase;
use Rector\Core\Kernel\RectorKernel;
use Rector\Core\Tests\Configuration\ValueObjectInliner\Source\ServiceWithValueObject;
use Rector\Core\Tests\Configuration\ValueObjectInliner\Source\ValueObjectInlinerTestKernel;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;

final class ConfigFactoryNestedTest extends AbstractKernelTestCase
final class ConfigFactoryNestedTest extends TestCase
{
private ServiceWithValueObject $serviceWithValueObject;

protected function setUp(): void
{
$this->bootKernelWithConfigs(ValueObjectInlinerTestKernel::class, [
__DIR__ . '/config/config_with_nested_union_type_value_objects.php',
]);
$rectorKernel = new RectorKernel();
$containerBuilder = $rectorKernel->createFromConfigs(
[__DIR__ . '/config/config_with_nested_union_type_value_objects.php']
);

$this->serviceWithValueObject = $containerBuilder->get(ServiceWithValueObject::class);
}

public function testInlineValueObjectFunction(): void
{
$serviceWithValueObject = $this->getService(ServiceWithValueObject::class);
$withType = $serviceWithValueObject->getWithType();

$withType = $this->serviceWithValueObject->getWithType();
$this->assertInstanceOf(UnionType::class, $withType->getType());
}
}
25 changes: 13 additions & 12 deletions tests/Configuration/ValueObjectInliner/ConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@

use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use PHPUnit\Framework\TestCase;
use Rector\Core\Kernel\RectorKernel;
use Rector\Core\Tests\Configuration\ValueObjectInliner\Source\ServiceWithValueObject;
use Rector\Core\Tests\Configuration\ValueObjectInliner\Source\ValueObjectInlinerTestKernel;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;

final class ConfigFactoryTest extends AbstractKernelTestCase
final class ConfigFactoryTest extends TestCase
{
private ServiceWithValueObject $serviceWithValueObject;

protected function setUp(): void
{
$this->bootKernelWithConfigs(ValueObjectInlinerTestKernel::class, [
__DIR__ . '/config/config_with_nested_value_objects.php',
]);
$rectorKernel = new RectorKernel();
$containerBuilder = $rectorKernel->createFromConfigs(
[__DIR__ . '/config/config_with_nested_value_objects.php']
);

$this->serviceWithValueObject = $containerBuilder->get(ServiceWithValueObject::class);
}

public function testInlineValueObjectFunction(): void
{
$serviceWithValueObject = $this->getService(ServiceWithValueObject::class);
$withType = $serviceWithValueObject->getWithType();
$withType = $this->serviceWithValueObject->getWithType();

$this->assertInstanceOf(IntegerType::class, $withType->getType());
}

public function testInlineValueObjectsFunction(): void
{
/** @var ServiceWithValueObject $serviceWithValueObject */
$serviceWithValueObject = $this->getService(ServiceWithValueObject::class);

$withTypes = $serviceWithValueObject->getWithTypes();
$withTypes = $this->serviceWithValueObject->getWithTypes();
$this->assertCount(1, $withTypes);

$singleWithType = $withTypes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();

$services->defaults()
->public()
->autowire()
Expand Down

0 comments on commit 5a28970

Please sign in to comment.