Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Composer\Semver\Semver;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -100,10 +99,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
$this->kernel->boot();
}

// a cheap way to guess the service id
$serviceId ??= \sprintf('maker.maker.%s', Str::asSnakeCase((new \ReflectionClass($makerClass))->getShortName()));

return $this->kernel->getContainer()->get($serviceId);
return $this->kernel->getContainer()->get('maker_locator_for_tests')->get($makerClass);
}

protected function createKernel(): KernelInterface
Expand Down
13 changes: 10 additions & 3 deletions src/Test/MakerTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

Expand Down Expand Up @@ -77,10 +79,15 @@ public function getRootDir(): string

public function process(ContainerBuilder $container): void
{
// makes all makers public to help the tests
// Add a service locator to find makers by class name
$makers = [];
foreach ($container->findTaggedServiceIds(MakeCommandRegistrationPass::MAKER_TAG) as $id => $tags) {
$defn = $container->getDefinition($id);
$defn->setPublic(true);
$makers[$container->getDefinition($id)->getClass()] = new Reference($id);
}

$container->register('maker_locator_for_tests', ServiceLocator::class)
->setPublic(true)
->addArgument($makers)
->addTag('container.service_locator');
}
}
Loading