Skip to content

Commit

Permalink
Merge pull request #132 from alexislefebvre/update-kernels
Browse files Browse the repository at this point in the history
Update kernels
  • Loading branch information
alexislefebvre authored Jun 21, 2021
2 parents da7a451 + 593792e commit 5ffd76b
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ vendor
# Ignore files created during tests
/cov/
!.gitkeep

tests/App*/var/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doctrine/doctrine-bundle": "^2.1",
"doctrine/doctrine-fixtures-bundle": "^3.0.2",
"doctrine/orm": "^2.7",
"doctrine/phpcr-bundle": "^2.0",
"doctrine/phpcr-bundle": "^2.0.2",
"doctrine/phpcr-odm": "^1.3",
"jackalope/jackalope-doctrine-dbal": "^1.5",
"monolog/monolog": "^1.25.1 || ^2.0",
Expand Down
45 changes: 16 additions & 29 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,37 @@

namespace Liip\Acme\Tests\App;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use Liip\TestFixturesBundle\LiipTestFixturesBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use ReflectionClass;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

abstract class AppKernel extends Kernel
{
public function registerBundles(): array
{
return [
new FrameworkBundle(),
new MonologBundle(),
new DoctrineBundle(),
new DoctrineFixturesBundle(),
new NelmioAliceBundle(),
new FidryAliceDataFixturesBundle(),
new LiipTestFixturesBundle(),
new AcmeBundle(),
];
}
use MicroKernelTrait;

public function registerContainerConfiguration(LoaderInterface $loader): void
public function registerBundles(): iterable
{
$loader->load(__DIR__.'/config.yml');
$contents = require __DIR__.'/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getCacheDir()
public function getProjectDir(): string
{
return $this->getBaseDir().'cache';
return __DIR__;
}

public function getLogDir()
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
return $this->getBaseDir().'log';
$loader->load($this->getProjectDir().'/config.yml');
}

protected function getBaseDir()
protected function configureRoutes(RoutingConfigurator $routes): void
{
return sys_get_temp_dir().'/LiipTestFixturesBundle/'.(new ReflectionClass($this))->getShortName().'/var/';
}
}
4 changes: 2 additions & 2 deletions tests/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ doctrine:
mappings:
LiipAcme:
type: php
dir: "%kernel.project_dir%/tests/App/Entity"
dir: "%kernel.project_dir%/Entity"
prefix: 'Liip\Acme\Tests\App\Entity'
is_bundle: false
LiipAcmeYml:
type: "yml"
dir: "%kernel.project_dir%/tests/App/Resources/config/doctrine"
dir: "%kernel.project_dir%/Resources/config/doctrine"
prefix: 'Liip\Acme\Tests\App\Entity'
is_bundle: false

Expand Down
24 changes: 24 additions & 0 deletions tests/App/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true],
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['all' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['all' => true],
Liip\TestFixturesBundle\LiipTestFixturesBundle::class => ['all' => true],
Liip\Acme\Tests\App\AcmeBundle::class => ['all' => true],
Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle::class => ['phpcr' => true],
];
12 changes: 9 additions & 3 deletions tests/AppConfig/AppConfigKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\AppConfigSqlite\AppConfigSqliteKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigKernel extends AppConfigSqliteKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with "liip_test_fixtures" parameters
$loader->load(__DIR__.'/config.yml');
Expand Down
12 changes: 9 additions & 3 deletions tests/AppConfigEvents/AppConfigEventsKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\AppConfig\AppConfigKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigEventsKernel extends AppConfigKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with the FixturesSubscriber service
$loader->load(__DIR__.'/config.yml');
Expand Down
12 changes: 9 additions & 3 deletions tests/AppConfigMysql/AppConfigMysqlKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\App\AppKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigMysqlKernel extends AppKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with MySQL configuration
$loader->load(__DIR__.'/config.yml');
Expand Down
14 changes: 10 additions & 4 deletions tests/AppConfigMysqlCacheDb/AppConfigMysqlKernelCacheDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@

use Liip\Acme\Tests\AppConfigMysql\AppConfigMysqlKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigMysqlKernelCacheDb extends AppConfigMysqlKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with MySQL configuration
// Load the file with specific configuration
$loader->load(__DIR__.'/config.yml');
}
}
12 changes: 9 additions & 3 deletions tests/AppConfigMysqlUrl/AppConfigMysqlUrlKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\App\AppKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigMysqlUrlKernel extends AppKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with MySQL configuration
$loader->load(__DIR__.'/config.yml');
Expand Down
12 changes: 9 additions & 3 deletions tests/AppConfigPgsql/AppConfigPgsqlKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\App\AppKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigPgsqlKernel extends AppKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with PostgreSQL configuration
$loader->load(__DIR__.'/config.yml');
Expand Down
30 changes: 10 additions & 20 deletions tests/AppConfigPhpcr/AppConfigPhpcrKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,24 @@
namespace Liip\Acme\Tests\AppConfigPhpcr;

use Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle;
use Liip\Acme\Tests\AppConfigSqlite\AppConfigSqliteKernel;
use Liip\Acme\Tests\AppConfig\AppConfigKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigPhpcrKernel extends AppConfigSqliteKernel
class AppConfigPhpcrKernel extends AppConfigKernel
{
public function registerBundles(): array
/**
* {@inheritdoc}
*/
public function getCacheDir(): string
{
$bundles = [];

if (class_exists(DoctrinePHPCRBundle::class)) {
$bundles = [
new DoctrinePHPCRBundle(),
];
}

return array_merge(
parent::registerBundles(),
$bundles
);
return __DIR__.'/var/cache/';
}

/**
* Load the config.yml from the current directory.
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with PHPCR configuration
if (class_exists(DoctrinePHPCRBundle::class)) {
Expand Down
3 changes: 2 additions & 1 deletion tests/AppConfigPhpcr/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ doctrine_phpcr:
mappings:
LiipAcme:
type: annotation
dir: "%kernel.project_dir%/tests/AppConfigPhpcr/Document"
dir: "%kernel.project_dir%/../AppConfigPhpcr/Document"
prefix: 'Liip\Acme\Tests\AppConfigPhpcr\Document'
is_bundle: false

services:
Liip\Acme\Tests\AppConfigPhpcr\DataFixtures\PHPCR\:
Expand Down
12 changes: 9 additions & 3 deletions tests/AppConfigSqlite/AppConfigSqliteKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Liip\Acme\Tests\App\AppKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppConfigSqliteKernel extends AppKernel
{
/**
* Load the config.yml from the current directory.
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
public function getCacheDir(): string
{
return __DIR__.'/var/cache/';
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// Load the default file.
parent::registerContainerConfiguration($loader);
parent::configureContainer($container, $loader);

// Load the file with SQLite configuration
$loader->load(__DIR__.'/config.yml');
Expand Down
4 changes: 3 additions & 1 deletion tests/Test/ConfigPhpcrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ protected function setUp(): void

parent::setUp();

self::bootKernel();
self::bootKernel([
'environment' => 'phpcr',
]);

$entityManager = self::$container->get('doctrine')->getManager();

Expand Down

0 comments on commit 5ffd76b

Please sign in to comment.