Skip to content

Commit 1e0104c

Browse files
authored
Fix tests (#1566)
1 parent 9440d7a commit 1e0104c

File tree

4 files changed

+60
-45
lines changed

4 files changed

+60
-45
lines changed

tests/Fixtures/app/AppKernel.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
declare(strict_types=1);
1313

1414
use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
15+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User;
1516
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
1617
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1718
use FOS\UserBundle\FOSUserBundle;
1819
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
1920
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
2021
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
22+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
2123
use Symfony\Bundle\SecurityBundle\SecurityBundle;
2224
use Symfony\Bundle\TwigBundle\TwigBundle;
2325
use Symfony\Component\Config\Loader\LoaderInterface;
26+
use Symfony\Component\DependencyInjection\ContainerBuilder;
2427
use Symfony\Component\HttpKernel\Kernel;
28+
use Symfony\Component\Routing\RouteCollectionBuilder;
29+
use Symfony\Component\Security\Core\User\UserInterface;
30+
use Symfony\Component\Security\Http\Firewall\ContextListener;
2531

2632
/**
2733
* AppKernel for tests.
@@ -30,7 +36,9 @@
3036
*/
3137
class AppKernel extends Kernel
3238
{
33-
public function registerBundles()
39+
use MicroKernelTrait;
40+
41+
public function registerBundles(): array
3442
{
3543
return [
3644
new FrameworkBundle(),
@@ -45,7 +53,12 @@ public function registerBundles()
4553
];
4654
}
4755

48-
public function registerContainerConfiguration(LoaderInterface $loader)
56+
protected function configureRoutes(RouteCollectionBuilder $routes)
57+
{
58+
$routes->import('config/routing.yml');
59+
}
60+
61+
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
4962
{
5063
$environment = $this->getEnvironment();
5164

@@ -55,5 +68,49 @@ public function registerContainerConfiguration(LoaderInterface $loader)
5568
}
5669

5770
$loader->load("{$this->getRootDir()}/config/config_{$environment}.yml");
71+
72+
$securityConfig = [
73+
'encoders' => [
74+
User::class => 'bcrypt',
75+
// Don't use plaintext in production!
76+
UserInterface::class => 'plaintext',
77+
],
78+
'providers' => [
79+
'chain_provider' => [
80+
'chain' => [
81+
'providers' => ['in_memory', 'fos_userbundle'],
82+
],
83+
],
84+
'in_memory' => [
85+
'memory' => [
86+
'users' => [
87+
'dunglas' => ['password' => 'kevin', 'roles' => 'ROLE_USER'],
88+
'admin' => ['password' => 'kitten', 'roles' => 'ROLE_ADMIN'],
89+
],
90+
],
91+
],
92+
'fos_userbundle' => ['id' => 'fos_user.user_provider.username_email'],
93+
],
94+
'firewalls' => [
95+
'dev' => [
96+
'pattern' => '^/(_(profiler|wdt|error)|css|images|js)/',
97+
'security' => false,
98+
],
99+
'default' => [
100+
'provider' => 'chain_provider',
101+
'http_basic' => null,
102+
'anonymous' => null,
103+
],
104+
],
105+
'access_control' => [
106+
['path' => '^/', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'],
107+
],
108+
];
109+
110+
if (method_exists(ContextListener::class, 'setLogoutOnUserChange')) {
111+
$securityConfig['firewalls']['default']['logout_on_user_change'] = true;
112+
}
113+
114+
$c->loadFromExtension('security', $securityConfig);
58115
}
59116
}

tests/Fixtures/app/config/config_test.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
imports:
2-
- { resource: security.yml }
3-
41
framework:
52
secret: 'dunglas.fr'
6-
router:
7-
resource: '%kernel.root_dir%/config/routing.yml'
8-
strict_requirements: '%kernel.debug%'
93
validation:
104
enable_annotations: true
115
serializer:

tests/Fixtures/app/config/routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ relation_embedded.custom_get:
1313
_controller: 'TestBundle:Custom:custom'
1414

1515
controller:
16-
resource: "@TestBundle/Controller"
16+
resource: '@TestBundle/Controller'
1717
type: annotation

tests/Fixtures/app/config/security.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)