Ancestors

Written by Ben Ramsey on 2025-01-25 at 19:12

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

Written by Ben Ramsey on 2025-01-25 at 19:16

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

Toot

Written by Ben Ramsey on 2025-01-25 at 21:21

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

Descendants

Written by Claudio Zizza 🦜 on 2025-01-26 at 10:20

@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

Written by willpower232 on 2025-01-26 at 22:30

@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

Written by Ben Ramsey on 2025-01-26 at 22:33

@willpower232 Probably

=> More informations about this toot | More toots from ramsey@phpc.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113891089400016239
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
290.495483 milliseconds
Gemini-to-HTML Time
1.104685 milliseconds

This content has been proxied by September (3851b).