Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] add setInputs to ApplicationTester and share some code#24819

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@Simperfit
Copy link
Contributor

QA
Branch?4.1
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24784
LicenseMIT
Doc PRtodo

I didn't implemented the tests because I don't know how to write them on ApplicationTester.

@SimperfitSimperfitforce-pushed thefeature/refactor-application-and-command-tester-to-share-code branch frombe6fbc2 todbbf3fbCompareNovember 4, 2017 18:11
@SimperfitSimperfit changed the title[Console] add setInputs to ApplicationTest and share some code[Console] add setInputs to ApplicationTester and share some codeNov 5, 2017
@ogizanagiogizanagi added this to the4.1 milestoneNov 5, 2017
Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

here is a test case

diff --git a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.phpindex 062d414..0cc002d 100644--- a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php+++ b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php@@ -13,7 +13,9 @@ namespace Symfony\Component\Console\Tests\Tester;  use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application;+use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Output\Output;+use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Tester\ApplicationTester;  class ApplicationTesterTest extends TestCase@@ -65,6 +67,22 @@ class ApplicationTesterTest extends TestCase         $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');     }+    public function testSetInputs()+    {+        $this->application->register('foo')->setCode(function ($input, $output) {+            $helper = new QuestionHelper();+            $helper->ask($input, $output, new Question('Q1'));+            $helper->ask($input, $output, new Question('Q2'));+            $helper->ask($input, $output, new Question('Q3'));+        });++        $this->tester->setInputs(array('I1', 'I2', 'I3'));+        $this->tester->run(array('command' => 'foo'));++        $this->assertSame(0, $this->tester->getStatusCode());+        $this->assertEquals('Q1Q2Q3', $this->tester->getDisplay(true));+    }+     public function testGetStatusCode()     {         $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');

*
* @return self
*/
publicfunctionsetInputs(array$inputs)
Copy link
Member

Choose a reason for hiding this comment

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

For this to work in ApplicationTester, the tester needs to set the input stream from this value.
SoCommandTester::createInputStream() should be shared between both testers (that's my motivation for a trait) andthis line should be added toApplicationTester::run().

*/
publicfunctionsetInputs(array$inputs)
{
$this->inputs =$inputs;
Copy link
Member

Choose a reason for hiding this comment

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

the property does not exist in ApplicationTester, it should be created

Copy link
Contributor

@ogizanagiogizanagiNov 5, 2017
edited
Loading

Choose a reason for hiding this comment

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

or moved to the trait along with:

/** @var StreamOutput */private$output;

@Simperfit
Copy link
ContributorAuthor

@chalasr So it seems that the test is failling. Is here something the modify directly in the Application to make this work properly ?

@SimperfitSimperfitforce-pushed thefeature/refactor-application-and-command-tester-to-share-code branch 2 times, most recently from370851e toefe61ccCompareNovember 5, 2017 16:38
*/
trait TesterTrait
{
/** @var StreamOutput */
Copy link
Member

Choose a reason for hiding this comment

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

not useful and differs withgetOutput() return type, I would drop it

Copy link
Contributor

@ogizanagiogizanagiNov 5, 2017
edited
Loading

Choose a reason for hiding this comment

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

To me it is useful actually (for autocompletion and SCA). This trait needs aStreamOutput instance here, not anyOutputInterface. That's why I suggested this docblock in#24819 (comment) :)

screenshot 2017-11-05 a 19 27 06

}

if ($this->inputs) {
$this->input->setStream(self::createStream($this->inputs));
Copy link
Member

Choose a reason for hiding this comment

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

Here is the failure culprit, I suggest toputenv('SHELL_INTERACTIVE=1') here and, afterrun(), either destroy it or restore its previous value if any

@SimperfitSimperfitforce-pushed thefeature/refactor-application-and-command-tester-to-share-code branch fromefe61cc to8b59c06CompareNovember 5, 2017 19:44
@Simperfit
Copy link
ContributorAuthor

Thanks for the review guys, tests are now green ;).

private$inputs =array();

/**
* Gets the display returned by the last execution of the application.
Copy link
Member

Choose a reason for hiding this comment

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

command or application, same below

return$this;
}

publicstaticfunctioncreateStream(array$inputs)
Copy link
Member

Choose a reason for hiding this comment

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

this one must stay private

rewind($this->output->getStream());

$display =stream_get_contents($this->output->getStream());
putenv('SHELL_INTERACTIVE');
Copy link
Member

Choose a reason for hiding this comment

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

putenv($shellInteractive ? "SHELL_INTERACTIVE=$shellInteractive" : 'SHELL_INTERACTIVE'); instead, removing the condition below

@SimperfitSimperfitforce-pushed thefeature/refactor-application-and-command-tester-to-share-code branch from8b59c06 to3513236CompareNovember 5, 2017 20:20
Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

👍

publicfunctionrun(array$input,$options =array())
{
$this->input =newArrayInput($input);

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicking but should be reverted ^^

Simperfit reacted with thumbs up emoji
@SimperfitSimperfitforce-pushed thefeature/refactor-application-and-command-tester-to-share-code branch from3513236 toea86ed8CompareNovember 12, 2017 06:57
@chalasr
Copy link
Member

Thank you@Simperfit.

@chalasrchalasr merged commitea86ed8 intosymfony:masterNov 26, 2017
chalasr pushed a commit that referenced this pull requestNov 26, 2017
… some code (Simperfit)This PR was merged into the 4.1-dev branch.Discussion----------[Console] add setInputs to ApplicationTester and share some code| Q             | A| ------------- | ---| Branch?       | 4.1| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#24784| License       | MIT| Doc PR        | todoI didn't implemented the tests because I don't know how to write them on ApplicationTester.Commits-------ea86ed8 [Console] add setInputs to ApplicationTest and share some code
@SimperfitSimperfit deleted the feature/refactor-application-and-command-tester-to-share-code branchDecember 20, 2017 15:42
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr approved these changes

+2 more reviewers

@ogizanagiogizanagiogizanagi approved these changes

@20uf20uf20uf approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

5 participants

@Simperfit@chalasr@ogizanagi@20uf@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp