Best way to test a command that calls another command. #499
Unanswered
adampatterson
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Howdy folks,
I forked a project and added some features. And like a good developer I felt I should include some unit tests.
This is for the Spinup WP CLI tool, they are using Laravel Zero 9.2 and Pest 1.3.
The tests were really easy to get going until I hit my main feature and am unsure how to proceed.
The command lets me search through a list of sites, choose one from the results, and the prompts asking if I want to SSH into the server.
If I hit yes I'd expect an output matching another command ( I am calling that command from mine. )
https://github.com/adampatterson/spinupwp-cli/blob/add-site-and-server-search/app/Commands/Sites/SearchCommand.php#L104
My test passes up to the point of confirming that the SSH step was successful.
https://github.com/adampatterson/spinupwp-cli/blob/add-site-and-server-search/tests/Feature/Commands/SitesSearchCommandTest.php#L91
I spent a bunch of time looking for a way to reveal what the CLI was seeing, like I expected Establishing a secure connection to [hellfishmedia] as [hellfish]... but I got something totally different this would help me figure out what's going on.
I think this may exist in newer versions of PEST as I saw
ray()
but this is using PEST 1.3 as I mentioned.Next, this is more of an opinion. If my command calls another command I can probably rely on that commands tests, but I would like to know if that command was called.
Beta Was this translation helpful? Give feedback.
All reactions