Skip to content

Conversation

@jeremyharris
Copy link
Member

Closes #5071

This PR expects cakephp/cakephp#10850 to be merged.

@markstory markstory added this to the 3.x milestone Jul 4, 2017

.. versionadded:: 3.5.0

The ``ConsoleIntegrationTestCase`` was added.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in 3.5.0.

Copy link
Member Author

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 :)

Copy link
Member

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');
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool.

Copy link
Member

@ravage84 ravage84 left a 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;
Copy link
Member

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)


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::
Copy link
Member

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;
Copy link
Member

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)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Testing Interactive Shells/Consoles"?


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
Copy link
Member

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\./");
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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()?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@markstory markstory merged commit fc3dd16 into cakephp:3.next Jul 12, 2017
@jeremyharris jeremyharris deleted the issue-5071 branch July 12, 2017 01:22
@HavokInspiration HavokInspiration modified the milestones: 3.next, 3.x Jul 12, 2017
HavokInspiration added a commit that referenced this pull request Jul 16, 2017
ryoichi-u added a commit to ryoichi-u/docs that referenced this pull request Sep 2, 2017
ryoichi-u added a commit to ryoichi-u/docs that referenced this pull request Sep 2, 2017
ryoichi-u added a commit to ryoichi-u/docs that referenced this pull request Sep 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants