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

Bug: Command output not captured when testing #9457

Closed
purdy opened this issue Feb 21, 2025 · 4 comments
Closed

Bug: Command output not captured when testing #9457

purdy opened this issue Feb 21, 2025 · 4 comments

Comments

@purdy
Copy link

purdy commented Feb 21, 2025

PHP Version

8.1

CodeIgniter4 Version

4.6.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

MySQL 5.7

What happened?

According to the doc, you can call command() and all output is captured. However, I have a command that uses CLI::write() to output various messages as the command is executed and those outputs are still written to the console. My use case is that I'm writing a test script, which calls the command() function, and it generates output.

Steps to Reproduce

  1. write a command that just does a CLI::write('hello world') to the console
  2. write a test script that calls command() with the command
  3. run tests and see that hello world shows up in the testing output.

Expected Output

I'm expecting no output unless I'm manually outputting the return value from the command() call.

Anything else?

No response

@purdy purdy added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 21, 2025
@michalsn
Copy link
Member

@michalsn michalsn removed the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 21, 2025
@purdy
Copy link
Author

purdy commented Feb 21, 2025

Oh, cool! That should help, thanks! Is this still an issue, though, since the output isn't captured as documented?

@michalsn
Copy link
Member

Is this still an issue, though, since the output isn't captured as documented?

No, there is no issue.

When you run a command using command('whatever'), its output is printed directly to STDOUT.
In a normal web request or CLI execution, this works fine. However, in a testing environment, you need to capture this output for assertions because PHPUnit does not naturally capture STDOUT.

@purdy
Copy link
Author

purdy commented Feb 21, 2025

That makes sense ... thank you! Thanks also for the quick triaging and responses! :)

@purdy purdy closed this as completed Feb 21, 2025
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

2 participants