Skip to content

Commit

Permalink
minor #879 Use testing container to access private service (dmaicher)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Oct 29, 2018
2 parents e5c8d21 + 1c75aca commit 6a4ce6b
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tests/Command/AddUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

use App\Command\AddUserCommand;
use App\Entity\User;
use App\Utils\Validator;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
Expand Down Expand Up @@ -115,10 +113,8 @@ private function executeCommand(array $arguments, array $inputs = [])
{
self::bootKernel();

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

$commandTester = new CommandTester($command);
Expand Down

0 comments on commit 6a4ce6b

Please sign in to comment.