Skip to content

Commit

Permalink
Merge pull request #35 from gregoirepaqueron/fix/command-option-hide-…
Browse files Browse the repository at this point in the history
…multiple-choice

change wrong option --show-multiple-choice in --hide-multiple-choice
  • Loading branch information
mickaelandrieu authored Mar 7, 2017
2 parents 91b102e + 58f5988 commit 3d5b204
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ protected function configure()
$this
->setName('start')
->setDescription('Starts a new question set')
->addArgument('categories', InputArgument::IS_ARRAY, 'Which categories do you want (separate multiple with a space)', array())
->addOption('number', null, InputOption::VALUE_OPTIONAL, 'How many questions do you want?', 20)
->addOption('list', 'l', InputOption::VALUE_NONE, 'List categories')
->addOption("training", null, InputOption::VALUE_NONE, "Training mode: the solution is displayed after each question")
->addOption('show-multiple-choice', null, InputOption::VALUE_OPTIONAL, 'Should we tell you when the question is multiple choice?', true)
->addArgument('categories', InputArgument::IS_ARRAY, 'Which categories do you want (separate multiple with a space)', array())
->addOption('hide-multiple-choice', null, InputOption::VALUE_NONE, 'Should we hide the information that the question is multiple choice?')
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom config', null)
;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
protected function askQuestions(Set $set, InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getHelper('question');
$showMultipleChoice = $input->getOption('show-multiple-choice');
$hideMultipleChoice = $input->getOption('hide-multiple-choice');
$questionCount = 1;

foreach ($set->getQuestions() as $i => $question) {
Expand All @@ -102,12 +102,12 @@ protected function askQuestions(Set $set, InputInterface $input, OutputInterface
$questionCount++,
$question->getCategory(),
$question->getQuestion(),
($showMultipleChoice === true ? "\n".'This question <comment>'.($question->isMultipleChoice() === true ? 'IS' : 'IS NOT')."</comment> multiple choice." : "")
($hideMultipleChoice === true ? "" : "\n".'This question <comment>'.($question->isMultipleChoice() === true ? 'IS' : 'IS NOT')."</comment> multiple choice.")
),
$question->getAnswersLabels()
);

$multiSelect = $showMultipleChoice === true ? $question->isMultipleChoice() : true;
$multiSelect = true === $hideMultipleChoice ? true : $question->isMultipleChoice();
$numericOnly = 1 === array_product(array_map('is_numeric', $question->getAnswersLabels()));
$choiceQuestion->setMultiselect($multiSelect);
$choiceQuestion->setErrorMessage('Answer %s is invalid.');
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ Will only get the questions from the categories "Automated tests" and "Bundles"

Use the category list from [List categories](#list-categories)

### Show if a question has multiple choices
### Hide the information that questions are/aren't multiple choice
```
$ php certificationy.php start --show-multiple-choice
$ php certificationy.php start --hide-multiple-choice
```

![Multiple choices](https://cloud.githubusercontent.com/assets/795661/3308225/721b5324-f679-11e3-8d9d-62ba32cd8e32.png "Multiple choices")
As default, the information will be displayed

![Multiple choice](https://cloud.githubusercontent.com/assets/795661/3308225/721b5324-f679-11e3-8d9d-62ba32cd8e32.png "Multiple choice")

### Set custom configuration file
```
Expand All @@ -59,11 +61,11 @@ Will set custom config file

### And all combined
```
$ php certificationy.php start --number=5 --show-multiple-choice "Automated tests" "Bundles"
$ php certificationy.php start --number=5 --hide-multiple-choice "Automated tests" "Bundles"
```

* 5 questions
* We will show if a questions has multiple choices
* We will hide the information that questions are/aren't multiple choice
* Only get questions from category "Automated tests" and "Bundles"

> Note: if you pass --list [-l] then you will ONLY get the category list, regarding your other settings
16 changes: 16 additions & 0 deletions Tests/Command/StartCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ public function testCanGetQuestions()
$this->assertRegExp('/Starting a new set of 20 questions/', $commandTester->getDisplay());
}

public function testCanHideInformationAboutMultipleChoice()
{
$helper = $this->command->getHelper('question');
$helper->setInputStream($this->getInputStream(str_repeat("0\n", 1)));

$commandTester = new CommandTester($this->command);
$commandTester->execute(array(
'command' => $this->command->getName(),
'--hide-multiple-choice' => null,
'--number' => 1,
));

$output = $commandTester->getDisplay();
$this->assertNotRegExp('/This question IS( NOT)? multiple choice/', $output);
}

protected function getInputStream($input)
{
$stream = fopen('php://memory', 'r+', false);
Expand Down

0 comments on commit 3d5b204

Please sign in to comment.