rvanlaak / SettingsBundle

Database centric Symfony2 configuration management bundle. Global and per-entity settings supported.
MIT License
113 stars 61 forks source link

Provide symfony 4 support #102

Closed nikophil closed 4 years ago

nikophil commented 6 years ago

@rvanlaak i checked and :

nikophil commented 6 years ago

guys, i'm sorry, but i can't find out how to make these tests work for symfony 4

i always got the following error :

Class "AppKernel" doesn't exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the Dmishh\SettingsBundle\Tests\Functional\ServiceInstantiationTest::createKernel() method

CoalaJoe commented 6 years ago

@nikophil Symfony 4 uses .env instead of paramters.yml. You have to add the environment variables in the phpunit.xml.dist. Here is what I use on my projects:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.1/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <ini name="memory_limit" value="512M" />
        <env name="KERNEL_CLASS" value="App\Kernel" />
        <env name="APP_ENV" value="test" />
        <env name="APP_DEBUG" value="1" />
        <env name="APP_SECRET" value="s$cretf0rt3st" />
        <env name="SHELL_VERBOSITY" value="-1" />
        <env name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/cache/test/data.db" />
        <env name="MAILER_SENDER" value="REDACTED@jkweb.ch" />
        <env name="DATABASE_DSN" value="sqlite:%kernel.project_dir%/var/cache/test/data.db" />
        <env name="DATABASE_USERNAME" value="" />
        <env name="DATABASE_PASSWORD" value="" />
        <!-- define your env variables for the test env here -->
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests/</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>./src/</directory>
        </whitelist>
    </filter>

    <listeners>
        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
    </listeners>

    <groups>
        <exclude>
            <group>ignore</group>
        </exclude>
    </groups>
</phpunit>
CoalaJoe commented 6 years ago

@nikophil Just update the KERNEL_CLASS value and add this Kernel.php:

<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';

    public function getCacheDir()
    {
        return $this->getProjectDir().'/var/cache/'.$this->environment;
    }

    public function getLogDir()
    {
        return $this->getProjectDir().'/var/log';
    }

    public function registerBundles()
    {
        $contents = require $this->getProjectDir().'/config/bundles.php';
        foreach ($contents as $class => $envs) {
            if (isset($envs['all']) || isset($envs[$this->environment])) {
                yield new $class();
            }
        }
    }

    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
    {
        $container->setParameter('container.autowiring.strict_mode', true);
        $container->setParameter('container.dumper.inline_class_loader', true);
        $confDir = $this->getProjectDir().'/config';
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
        if (is_dir($confDir.'/packages/'.$this->environment)) {
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
        }
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
    }

    protected function configureRoutes(RouteCollectionBuilder $routes)
    {
        $confDir = $this->getProjectDir().'/config';
        if (is_dir($confDir.'/routes/')) {
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
        }
        if (is_dir($confDir.'/routes/'.$this->environment)) {
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
        }
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
    }
}
nikophil commented 6 years ago

@CoalaJoe thank you, i added the new symfony 4 kernel, but i still get the error : Class "App\Kernel" doesn't exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the Dmishh\SettingsBundle\Tests\Functional\ServiceInstantiationTest::createKernel() method. in /var/www/symfony/vendor/symfony/framework-bundle/Test/KernelTestCase.php:45

I wonder if i shouldn't have two different phpunit.xml depending on each sf version ? And shouldn't i add something to composer to tell the autoloader where to find the App\Kernel file ?

thanks

CoalaJoe commented 6 years ago

@nikophil Maybe try the new guide since 4.0: https://symfony.com/doc/current/bundles/best_practices.html#content_wrapper

fcaraballo commented 6 years ago

Any reason why this PR hasn't been merged yet?

Zoopme commented 6 years ago

Hi, Any chance for another test run soon ? I would really like to be able to integrate the bundle to my sf4 upgrade. Thanks for you help & work.

emulienfou commented 5 years ago

Undefined text type for form, tested in SF4.1.
The next line:

->scalarNode('type')->defaultValue('text')->end()

should be

->scalarNode('type')->defaultValue(TextType::class)->end()

In class: Dmishh\SettingsBundle\DependencyInjection\Configuration

Related to https://github.com/dmishh/SettingsBundle/pull/96

Nyholm commented 4 years ago

I'll merge this and fix the rest in separate PRs.

Thank you