-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Added section on Console Integration Testing #5075
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
Conversation
|
|
||
| .. versionadded:: 3.5.0 | ||
|
|
||
| The ``ConsoleIntegrationTestCase`` was added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in 3.5.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version added block already adds that information: https://cl.ly/1K2l1u2P1E0Y
It's a bit redundant to see it twice. There are some inconsistencies in the usage within the docs though, I've seen it with the redundant version (https://cl.ly/32043z00392F) and without (https://cl.ly/1M1L2y190z40) and just plain (https://cl.ly/2G0O0p3M3g06)
If we pick one, I'll go with it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only once is fine. I forgot that sphinx added the words as well.
| { | ||
| public function testDescriptionOutput() | ||
| { | ||
| $this->exec('my_console'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this need a -h to output the help text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not, apparently. I created these shells and test case when writing this to ensure they worked like I'm promising here.
The shell seems to skip startup/main since it doesn't exist: https://api.cakephp.org/3.4/source-class-Cake.Console.Shell.html#468-475
And just outputs $this->OptionParser->help($command) which in turn outputs HelpFormatter::text which includes the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool.
ravage84
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks, @jeremyharris
| { | ||
| $parser = new ConsoleOptionParser(); | ||
| $parser->setDescription('My cool console app'); | ||
| return $parser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
white line before (code style)
en/development/testing.rst
Outdated
|
|
||
| Our test passes! While this is very trivial example, it shows that creating an | ||
| integration test case for console applications is quite easy. Let's continue by | ||
| adding some subcommands and options to our parser:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parser -> shell?
| ->addSubcommand('updateModified', [ | ||
| 'parser' => $updateModifiedParser | ||
| ]); | ||
| return $parser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
white line before (code style)
en/development/testing.rst
Outdated
| Remember, ``exec()`` will take the same string you type into your CLI, so you | ||
| can include options and arguments in your command string. | ||
|
|
||
| Testing input responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Testing Interactive Shells/Consoles"?
en/development/testing.rst
Outdated
|
|
||
| Consoles are often interactive. Testing interactive shells with the | ||
| ``Cake\TestSuite\ConsoleIntegrationTestCase`` class only requires passing the | ||
| responses you expect as the second parameter of ``exec()``. They should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
responses -> inputs?
| 'my homemade framework' | ||
| ]); | ||
| $this->assertExitCode(Shell::CODE_ERROR); | ||
| $this->assertErrorRegExp("/I disagree that \'(.+)\' is the best\./"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| // assert that the shell exited with the expected code | ||
| $this->assertExitCode($expected); | ||
|
|
||
| // assert that stdout contains a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a literal string?
| // assert that stdout contains a string | ||
| $this->assertOutputContains($expected); | ||
|
|
||
| // assert that stderr contains a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a literal string?
| assertion methods that make it easy to assert against console output:: | ||
|
|
||
| // assert that the shell exited with the expected code | ||
| $this->assertExitCode($expected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a assertSuccessExitCode()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with that, but probably assetExitCodeSuccess so it more closely resembles assertResponseOk, assertResponseError, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
Closes #5071
This PR expects cakephp/cakephp#10850 to be merged.