Skip to content

Commit 6a4ce6b

Browse files
committed
minor #879 Use testing container to access private service (dmaicher)
This PR was merged into the master branch. Discussion ---------- Use testing container to access private service This leverages https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing to make it easier to test the command service. Commits ------- 1c75aca Use testing container to access private service
2 parents e5c8d21 + 1c75aca commit 6a4ce6b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

tests/Command/AddUserCommandTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use App\Command\AddUserCommand;
1515
use App\Entity\User;
16-
use App\Utils\Validator;
17-
use Doctrine\Bundle\DoctrineBundle\Registry;
1816
use Symfony\Bundle\FrameworkBundle\Console\Application;
1917
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2018
use Symfony\Component\Console\Tester\CommandTester;
@@ -115,10 +113,8 @@ private function executeCommand(array $arguments, array $inputs = [])
115113
{
116114
self::bootKernel();
117115

118-
$container = self::$kernel->getContainer();
119-
/** @var Registry $doctrine */
120-
$doctrine = $container->get('doctrine');
121-
$command = new AddUserCommand($doctrine->getManager(), $container->get('security.password_encoder'), new Validator(), $doctrine->getRepository(User::class));
116+
// this uses a special testing container that allows you to fetch private services
117+
$command = self::$container->get(AddUserCommand::class);
122118
$command->setApplication(new Application(self::$kernel));
123119

124120
$commandTester = new CommandTester($command);

0 commit comments

Comments
 (0)