minor #24385 [FrameworkBundle] Register a NullLogger from test kernels (ogizanagi)
This PR was merged into the 3.4 branch.
Discussion
----------
[FrameworkBundle] Register a NullLogger from test kernels
| Q | A
| ------------- | ---
| Branch? | 3.4 <!-- see comment below -->
| Bug fix? | no
| New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks? | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | N/A
Relates to #24300
This will avoid unnecessary output on Travis or when running FrameworkBundle tests locally:
- before: https://travis-ci.org/symfony/symfony/jobs/281624658#L3594-L3635
- after: https://travis-ci.org/symfony/symfony/jobs/281643868#L3599-L3617
but also needed for anyone running functional tests on their project and using the default logger, in order to not get garbage output.
Do we need to find a more generic solution (like exposing a `framework.default_logger` option so users can set it to false for test)? Or just documenting this?
Commits
-------
c109dcd5ae
[FrameworkBundle] Register a NullLogger from test kernels
This commit is contained in:
commit
cd91b8f120
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture;
|
||||||
|
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\HttpKernel\Kernel;
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
|
||||||
class TestAppKernel extends Kernel
|
class TestAppKernel extends Kernel
|
||||||
@ -33,4 +35,9 @@ class TestAppKernel extends Kernel
|
|||||||
{
|
{
|
||||||
$loader->load(__DIR__.DIRECTORY_SEPARATOR.'config.yml');
|
$loader->load(__DIR__.DIRECTORY_SEPARATOR.'config.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function build(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->register('logger', NullLogger::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;
|
||||||
|
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\HttpKernel\Kernel;
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
|
||||||
@ -72,6 +74,11 @@ class AppKernel extends Kernel
|
|||||||
$loader->load($this->rootConfig);
|
$loader->load($this->rootConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function build(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->register('logger', NullLogger::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function serialize()
|
public function serialize()
|
||||||
{
|
{
|
||||||
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
|
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel;
|
||||||
|
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
@ -77,6 +78,7 @@ class ConcreteMicroKernel extends Kernel implements EventSubscriberInterface
|
|||||||
|
|
||||||
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
|
||||||
{
|
{
|
||||||
|
$c->register('logger', NullLogger::class);
|
||||||
$c->loadFromExtension('framework', array(
|
$c->loadFromExtension('framework', array(
|
||||||
'secret' => '$ecret',
|
'secret' => '$ecret',
|
||||||
));
|
));
|
||||||
|
Reference in New Issue
Block a user