Skip to content

Fix tests #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
declare(strict_types=1);

use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use FOS\UserBundle\FOSUserBundle;
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Http\Firewall\ContextListener;

/**
* AppKernel for tests.
Expand All @@ -30,7 +36,9 @@
*/
class AppKernel extends Kernel
{
public function registerBundles()
use MicroKernelTrait;

public function registerBundles(): array
{
return [
new FrameworkBundle(),
Expand All @@ -45,7 +53,12 @@ public function registerBundles()
];
}

public function registerContainerConfiguration(LoaderInterface $loader)
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import('config/routing.yml');
}

protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$environment = $this->getEnvironment();

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

$loader->load("{$this->getRootDir()}/config/config_{$environment}.yml");

$securityConfig = [
'encoders' => [
User::class => 'bcrypt',
// Don't use plaintext in production!
UserInterface::class => 'plaintext',
],
'providers' => [
'chain_provider' => [
'chain' => [
'providers' => ['in_memory', 'fos_userbundle'],
],
],
'in_memory' => [
'memory' => [
'users' => [
'dunglas' => ['password' => 'kevin', 'roles' => 'ROLE_USER'],
'admin' => ['password' => 'kitten', 'roles' => 'ROLE_ADMIN'],
],
],
],
'fos_userbundle' => ['id' => 'fos_user.user_provider.username_email'],
],
'firewalls' => [
'dev' => [
'pattern' => '^/(_(profiler|wdt|error)|css|images|js)/',
'security' => false,
],
'default' => [
'provider' => 'chain_provider',
'http_basic' => null,
'anonymous' => null,
],
],
'access_control' => [
['path' => '^/', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'],
],
];

if (method_exists(ContextListener::class, 'setLogoutOnUserChange')) {
$securityConfig['firewalls']['default']['logout_on_user_change'] = true;
}

$c->loadFromExtension('security', $securityConfig);
}
}
6 changes: 0 additions & 6 deletions tests/Fixtures/app/config/config_test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
imports:
- { resource: security.yml }

framework:
secret: 'dunglas.fr'
router:
resource: '%kernel.root_dir%/config/routing.yml'
strict_requirements: '%kernel.debug%'
validation:
enable_annotations: true
serializer:
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ relation_embedded.custom_get:
_controller: 'TestBundle:Custom:custom'

controller:
resource: "@TestBundle/Controller"
resource: '@TestBundle/Controller'
type: annotation
36 changes: 0 additions & 36 deletions tests/Fixtures/app/config/security.yml

This file was deleted.