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

Added getter and setter of QuestionHelper to SymfonyStyle#17136

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

Closed
SCIF wants to merge1 commit intosymfony:masterfromSCIF:symfonystyle-patch

Conversation

@SCIF
Copy link
Contributor

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

Current SymfonyStyle implementation disallow to test interactively input of command accordingdocs.

@SCIF
Copy link
ContributorAuthor

I did./phpunit src/Symfony/Component/Console/ according contribute docs and it said «Ok». Also, process fail seems odd and not related to my changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

could also be null

@Tobion
Copy link
Contributor

What do you need the getter for?

@ogizanagi
Copy link
Contributor

IMO, this should be merged in 2.7 and should add SymfonyStyle tests for the questions rendering, as done for other methods inSymfonyStyleTest.

As@Tobion said, I also think the getter won't be useful.

However, even with this PR, commands using theSymfonyStyle helper cannot be easily tested interactively, because on the contrary of theQuestionHelper,SymfonyQuestionHelper isn't registered in the helper set. So it'll require asetInputStream method or whatever in the command class. :/

@SCIF
Copy link
ContributorAuthor

@Tobion,here is one example of using getter. Getter required to allow passthrough input stream though different helpers if you want to replace ones.

@ogizanagi

SymfonyQuestionHelper isn't registered in the helper set

It used by laravel framework for example (btw, as main helper, not in helperset). Symfony is component kit and should provide flexible features as i think.

@SCIF
Copy link
ContributorAuthor

Fixed phpdoc. Thanks!

@xabbuh
Copy link
Member

@SCIF The code you linked to doesn't make use of such a getter and I don't see why that would be necessary (the console helper set is something different).

@SCIF
Copy link
ContributorAuthor

@xabbuh , that example shown that input stream sometimes required. If i want to replace QuestionHelper via setter — i would want to passtrough input stream hinted to original version of QuestionHelper to my own. It's not only testing purposes. Testing can be done without setter but substitution of QuestionHelper by different implementation can't be done without getter (to take user's input stream from it) and setter (to set new helper with hinted user's input stream).

@localheinz
Copy link
Contributor

@SCIF

Do you want to have a look at#17468?@xabbuh was so friendly to point out that the referenced PR is a duplicate of this one here, do you have an opinion (would you like to follow up with tests here, shall I close mine)?

@xabbuh
Copy link
Member

@SCIF Imho then it makes more sense to let theSymfonyStyle class return the input stream directly (via some method likegetInputStream()).

@SCIF
Copy link
ContributorAuthor

@xabbuh , i really don't know why you think that getter of QuestionHelper is bad idea. But i can replace getter of Helper with InputStream getter if you insist. My arguments are above, you decide please something and it should be closed.

@localheinz , thank you for your tests and work! Let i cherry pick commit with your tests and#17468 can be closed, isn't it?

@localheinz
Copy link
Contributor

@SCIF

👍 If you like, go ahead!

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally dislike the idea of creating a getter which can return either an object or null. It will introduce additional complexity above - the need of checking if the given result is an instance ofQuestionHelper

Choose a reason for hiding this comment

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

Maybe just create aSymfonyQuestionHelper in__construct(),
sogetQuestionHelp() can always return an instance ofQuestionHelper

for example:

diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.phpindex 47d7d12..3402918 100644--- a/Style/SymfonyStyle.php+++ b/Style/SymfonyStyle.php@@ -47,6 +47,7 @@ class SymfonyStyle extends OutputStyle     public function __construct(InputInterface $input, OutputInterface $output)     {         $this->input = $input;+        $this->questionHelper = new SymfonyQuestionHelper();         $this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());         // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not.         $this->lineLength = min($this->getTerminalWidth() - (int) (DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);@@ -323,10 +324,6 @@ class SymfonyStyle extends OutputStyle             $this->autoPrependBlock();         }-        if (!$this->questionHelper) {-            $this->questionHelper = new SymfonyQuestionHelper();-        }-         $answer = $this->questionHelper->ask($this->input, $this, $question);         if ($this->input->isInteractive()) {@@ -356,6 +353,14 @@ class SymfonyStyle extends OutputStyle     }     /**+     * @return QuestionHelper+     */+    public function getQuestionHelper()+    {+        return $this->questionHelper;+    }++    /**      * {@inheritdoc}      */     public function newLine($count = 1)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel like creating aSymfonyQuestionHelper object in the constructor is a good idea. There are many use cases where it's not used at all. Still,getQuestionHelper use case is very unclear for me, could you explain your point of view a little bit more please?

Choose a reason for hiding this comment

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

i want to test the action of interactively input:

  1. creating aSymfonyQuestionHelper object in the constructor for making code simpler.
  2. usegetQuestionHelper() to get theSymfonyQuestionHelper object for test interactively input with mock viasetInputStream()

@SCIF
Copy link
ContributorAuthor

SCIF commentedMar 3, 2016

@javiereguiluz , which style getter do you want to be added by me? I askedthat but didn't get any answer. Just don't want to push fixes forgetQuestionHelper() and get decline of it by some of symfony members. I want to arrive at any decision and implement it.

@sstok
Copy link
Contributor

sstok commentedMay 12, 2016
edited
Loading

Is there any chance of getting this merged? I'm currently using a hack to make my tests work, but I want to use a custom class to display a help text below the label and remove the "required" validator.

@fabpot
Copy link
Member

Closing in favor of#18710 and#18999

@fabpotfabpot closed thisJun 15, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

11 participants

@SCIF@Tobion@ogizanagi@xabbuh@localheinz@sstok@fabpot@marek-pietrzak-tg@edentsai@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp