Skip to content

Commit

Permalink
minor #24385 [FrameworkBundle] Register a NullLogger from test kernel…
Browse files Browse the repository at this point in the history
…s (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
-------

c109dcd [FrameworkBundle] Register a NullLogger from test kernels
  • Loading branch information
fabpot committed Sep 30, 2017
2 parents a2ae9a4 + c109dcd commit cd91b8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture;

use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class TestAppKernel extends Kernel
Expand All @@ -33,4 +35,9 @@ public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.DIRECTORY_SEPARATOR.'config.yml');
}

protected function build(ContainerBuilder $container)
{
$container->register('logger', NullLogger::class);
}
}
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;

use Psr\Log\NullLogger;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;

Expand Down Expand Up @@ -72,6 +74,11 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load($this->rootConfig);
}

protected function build(ContainerBuilder $container)
{
$container->register('logger', NullLogger::class);
}

public function serialize()
{
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
Expand Down
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel;

use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
Expand Down Expand Up @@ -77,6 +78,7 @@ protected function configureRoutes(RouteCollectionBuilder $routes)

protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$c->register('logger', NullLogger::class);
$c->loadFromExtension('framework', array(
'secret' => '$ecret',
));
Expand Down

0 comments on commit cd91b8f

Please sign in to comment.