liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony

Home Page:http://liip.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CommandTester getDisplay has not output from monolog

gianiaz opened this issue · comments

Preconditions

Updated from 2.0.0-alpha8 to 2.0.0-alpha12 (it was present in 2.0.0-alpha10).

Steps to reproduce

In a symfony 3.4 application I'm testing a command that receives a LoggerInterface with DI (it is a monolog logger handler with type console - https://symfony.com/doc/current/logging/monolog_console.html).
Via Monolog Bridge logs are sent to OutputInterface.

Handler is configured in this way:

qworker:
      type: console
      level: info
      channels: ['qworker']
      formatter: monolog.formatter.line
      verbosity_levels:
        VERBOSITY_NORMAL: info

In previous version I was testing in this way:

Expected result

        $output = $this->runCommand(
            WorkerManagerConsumerCommand::NAME,
            [
                'data' => $this->encodePayload($data),
            ]
        );

        $this->assertContains('ERROR', $output);

Actual result

In latest version (2.0.0-alpha-12) I have changed my code to this:

        $commandTester = $this->runCommand(
            WorkerManagerConsumerCommand::NAME,
            [
                'data' => $this->encodePayload($data),
            ]
        );

        $output = $commandTester->getDisplay();

        $this->assertContains('ERROR', $output);

But the $output var now contains an empty string instead of the logged value.

In my integration test the output is always the same.

After some debug, it seems that the consoleHandler has $output setted to null instead of \Symfony\Component\Console\Output\StreamOutput with this version.

@gianiaz , did you solved the issue?

It seems that in tests, MonologBundle doesn't correctly set the OutputInterface and so no log is logged in the console.

A possible solution may be this: https://stackoverflow.com/a/31999172/1399706

But I'd like to make all autoconfigured as it is for dev and test envs...

I'm sorry, too much time has passed and my memory is very limited.
In the meanwhile, my colleagues did upgrade to Symfony 5 and I don't know if the bug was still present.

@gianiaz , ok, I understand...

Anyway, I'm on SF5, too and the problem is still there.

Maybe, if you can, you could ask one of your colleagues, asking him/her how did (s)he solved the issue... It would be very helpful... But if you can't, don't worry :)