Skip to content

Commit

Permalink
Use PHP test config
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 4, 2024
1 parent edcfb92 commit 666f349
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 67 deletions.
3 changes: 1 addition & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ protected function configureRoutes(RoutingConfigurator $routes): void

protected function configureContainer(ContainerConfigurator $container): void
{
$container->import(__DIR__.'/config/config.yaml');
$container->import(__DIR__.'/config/security.yaml');
$container->import(__DIR__.'/config/config.php');
}

private function getBaseDir(): string
Expand Down
62 changes: 62 additions & 0 deletions tests/App/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\UserBundle\Model\UserInterface;
use Nucleos\UserBundle\Tests\App\Entity\TestGroup;
use Nucleos\UserBundle\Tests\App\Entity\TestUser;
use Symfony\Component\Security\Http\Attribute\IsGranted;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('framework', ['secret' => 'secret']);

$containerConfigurator->extension('framework', ['test' => true]);

$containerConfigurator->extension('framework', ['session' => ['storage_factory_id' => 'session.storage.factory.mock_file', 'handler_id' => null]]);

$containerConfigurator->extension('twig', ['strict_variables' => true]);

$containerConfigurator->extension('twig', ['exception_controller' => null]);

$securityConfig = [
'firewalls' => ['main' => ['security' => true]],
];

// TODO: Remove if when dropping support of Symfony 5.4
if (!class_exists(IsGranted::class)) {
$securityConfig['enable_authenticator_manager'] = true;
}

$containerConfigurator->extension('security', $securityConfig);

$containerConfigurator->extension('security', [
'providers' => ['nucleos_userbundle' => ['id' => 'nucleos_user.user_provider.username']],
]);

$containerConfigurator->extension('security', ['access_control' => [['path' => '^/.*', 'role' => 'PUBLIC_ACCESS']]]);

$containerConfigurator->extension('security', ['password_hashers' => [UserInterface::class => [
'algorithm' => 'plaintext',
]]]);

$containerConfigurator->extension('nucleos_user', ['firewall_name' => 'main']);

$containerConfigurator->extension('nucleos_user', ['from_email' => 'no-reply@localhost']);

$containerConfigurator->extension('nucleos_user', ['user_class' => TestUser::class]);

$containerConfigurator->extension('nucleos_user', ['group' => ['group_class' => TestGroup::class]]);

$containerConfigurator->extension('nucleos_user', ['loggedin' => ['route' => 'home']]);
};
28 changes: 0 additions & 28 deletions tests/App/config/config.yaml

This file was deleted.

37 changes: 0 additions & 37 deletions tests/App/config/security.yaml

This file was deleted.

0 comments on commit 666f349

Please sign in to comment.