Testing console output with #Laravel is really difficult. I can't seem to get my expectsOutput()
and expectsOutputToContain()
expectations to work properly, I can't figure out a way to see the actual output.
How does everyone else do this?
I've been referring to this: https://laravel.com/docs/11.x/console-tests
It looks like others have made efforts to solve this, but those efforts weren't accepted: https://github.com/laravel/framework/pull/32927
=> More informations about this toot | More toots from ramsey@phpc.social
From what I can tell, the expectsOutput*()
methods are stateful. If you have multiple lines of output, the first call tests the first line, the second tests the second line, and so on.
[#]Laravel #PHP
=> More informations about this toot | More toots from ramsey@phpc.social
I was able to get around the limitations using the following, but it doesn't feel like the #Laravel way.
$buffer = new BufferedOutput(); $result = Artisan::call('command', [], $buffer); $output = $buffer->fetch(); expect($output)->toContain('some string'); // If there's a problem, I can inspect $output.
=> More informations about this toot | More toots from ramsey@phpc.social
@ramsey At least a test doesn't fail just because a new line of output was prepended.
=> More informations about this toot | More toots from SenseException@phpc.social
@ramsey is this the problem where the command isn't actually run until destruct and you have to add an "->execute()" somewhere?
=> More informations about this toot | More toots from willpower232@phpc.social
@willpower232 Probably
=> More informations about this toot | More toots from ramsey@phpc.social This content has been proxied by September (3851b).Proxy Information
text/gemini