Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

user defined output not propagated #214

Closed
cgsmcmlxxv opened this Issue · 4 comments

4 participants

@cgsmcmlxxv

Hi

I created a command based on Behat:

// to load the Behat environment as well:
$behat = new BehatApplication();
// $input and $output redefined based on InputInterface and OutputInterface:
$behat->doRun($input, $output);

In this case, "doRun" method doesn't propagate $output (Symfony2 redefines $output in "run" method). I added method "run" to BehatApplication (and I accessed it in my Symfony2 console command):

public function run(InputInterface $input, OutputInterface $output)
{
parent::run($input,$output);
}

Now, it propagates correctly the $output variable till BehatCommand::execute(InputInterface $input, OutputInterface $output) where it is lost because the methods accessed in it do not make use of the given $output.

In this moment, to redirect the output to wherever I need it, I use exec() function, but that is not a nice solution (more like a hack). So, can anyone direct me to where this output is used to write the results of the test? I got lost somewhere at the hooks in tracing down the source of the problem. If it is too much of a problem explaining me where I should look, at least, is there any chance this to be remedied in a future release? Thanks a lot!

CGS

@stof
Owner

why do you need to add a run method doing nothing more than calling the parent method with the same arguments ? This is useless. Simply rely on the method defined in the parent class.

doRun is not meant to be called directly. It is called inside run. I don't know why this method is public in the Console component.

The issue with the output is that behat formatters are not using the console output to manage their output. They are writing to php://stout directly (still using the Console component StreamOutput).

@xmeltrut

It does seem a bit confusing that doRun is public even though it doesn't seem to have any need to be called directly. Maybe I'm missing something though. I've raised an issue on the Symfony issue tracker - symfony/symfony#6026

@cgsmcmlxxv

doRun() and run() are not my problem (yeah, I admit it didn't come to my mind to call directly run(), my bad). My real problem here is the output class instance propagation.

@stof Thanks for the explanation, but I didn't quite get its conclusion in this context. If Behat uses Console component (more precisely, StreamOutput class) why not to forward the OutputInterface implementation user provides with? Especially that there is implemented a switch for different output types (raw, formatted and plain - if memory serves).

My main problem with this output propagation is parallel threads reports which become pretty messy if I do not buffer them somehow (or any other output controlling method). As I said, the solution I have in this moment is to call exec("behat_command",$log) in each thread instead of calling run(), but this is more a hack than the correct way.

@everzet
Owner

If you want to fine-tune formatters output, you should extend formatters layer. That's because single execution flow of behat could have more than one formatter with different output streams associated with it. Good news is that today-tomorrow will land huge formatters refactoring that will add multiple additional extension points to default formatters in addition to currently existing ones.

@everzet everzet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.