Skip to content

Commit

Permalink
Fix loading bundle with disabled impersonating
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Apr 11, 2021
1 parent 7a3cb7d commit af897ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/DependencyInjection/NucleosUserAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public function load(array $configs, ContainerBuilder $container): void
$this->configureTranslationDomain($config, $container);
$this->configureController($config, $container);

if (false !== $config['impersonating']) {
$loader->load('impersonating.php');
$loader->load('impersonating.php');

if (false !== $config['impersonating']) {
$container->getDefinition(ImpersonateExtension::class)
->replaceArgument(1, $config['impersonating']['route'])
->replaceArgument(2, $config['impersonating']['parameters'])
Expand All @@ -89,21 +89,6 @@ private function configureAvatar(array $config, ContainerBuilder $container): vo
$container->setParameter('nucleos_user_admin.default_avatar', $config['avatar']['default_avatar']);
}

/**
* Adds aliases for user & group managers depending on $managerType.
*/
private function aliasManagers(ContainerBuilder $container, string $managerType): void
{
$container
->setAlias('nucleos_user_admin.user_manager', sprintf('nucleos_user_admin.%s.user_manager', $managerType))
->setPublic(true)
;
$container
->setAlias('nucleos_user_admin.group_manager', sprintf('nucleos_user_admin.%s.group_manager', $managerType))
->setPublic(true)
;
}

/**
* @throws RuntimeException
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/DependencyInjection/NucleosUserAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Nucleos\UserAdminBundle\Admin\Entity\UserAdmin;
use Nucleos\UserAdminBundle\DependencyInjection\Configuration;
use Nucleos\UserAdminBundle\DependencyInjection\NucleosUserAdminExtension;
use Nucleos\UserAdminBundle\Twig\ImpersonateExtension;
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -90,6 +91,29 @@ public function testTwigConfigParameterIsNotSet(): void
static::assertArrayNotHasKey(0, $twigConfigurations);
}

public function testLoadWithoutImpersonating(): void
{
$this->load();

$this->assertContainerBuilderHasService(ImpersonateExtension::class);
}

public function testLoadWithImpersonating(): void
{
$this->load([
'impersonating' => [
'route' => 'my_route',
'parameters' => [
'foo' => 'bar',
],
],
]);

$this->assertContainerBuilderHasService(ImpersonateExtension::class);
$this->assertContainerBuilderHasServiceDefinitionWithArgument(ImpersonateExtension::class, 1, 'my_route');
$this->assertContainerBuilderHasServiceDefinitionWithArgument(ImpersonateExtension::class, 2, ['foo' => 'bar']);
}

/**
* @doesNotPerformAssertions
*/
Expand Down

0 comments on commit af897ff

Please sign in to comment.