liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
639 stars 181 forks source link

CommandTester getDisplay has not output from monolog #483

Open gianiaz opened 5 years ago

gianiaz commented 5 years ago

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.

gianiaz commented 5 years ago

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

Aerendir commented 4 years ago

@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...

gianiaz commented 4 years ago

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.

Aerendir commented 4 years ago

@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 :)