Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandTester getDisplay has not output from monolog #483

Open
gianiaz opened this issue Jan 15, 2019 · 4 comments
Open

CommandTester getDisplay has not output from monolog #483

gianiaz opened this issue Jan 15, 2019 · 4 comments
Milestone

Comments

@gianiaz
Copy link

gianiaz commented Jan 15, 2019

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.

@alexislefebvre alexislefebvre added this to the 2.0 milestone Jan 15, 2019
@gianiaz
Copy link
Author

gianiaz commented Jan 15, 2019

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

@Aerendir
Copy link

@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
Copy link
Author

gianiaz commented Sep 28, 2020

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants