/**
  * Get the name of the test to create.
  * Method has to begin with 'test'
  *
  * @param string $methodName
  * @param bool $useDefaultTestMethodName
  * @param \Box\TestScribe\Spec\SpecsPerClass $specPerClass
  *
  * @return string
  */
 public function getTestName($methodName, $useDefaultTestMethodName, SpecsPerClass $specPerClass)
 {
     $specsPerMethod = $specPerClass->getSpecsPerMethodByName($methodName);
     $specs = $specsPerMethod->getSpecs();
     if ($specs) {
         $existingTestNames = array_keys($specs);
         $testMethodName = $this->testNameSelector->selectTestName($existingTestNames);
         if ($testMethodName !== '') {
             $msg = "Updating existing test ( {$testMethodName} ).";
             $this->output->writeln($msg);
             return $testMethodName;
         }
     }
     $testMethodNamePart = $methodName;
     if (!$useDefaultTestMethodName) {
         $message = "\nEnter the name of the test. It will be prefixed with 'test_'\n" . "Press enter to use the method name ( {$methodName} ) as the default.";
         $this->output->writeln($message);
         // rawInput is used instead of InputWithHelp so that
         // users don't have to quote the name as instructed by the help.
         $input = $this->rawInputWithPrompt->getString();
         if ($input !== '') {
             $testMethodNamePart = $input;
         }
     }
     $testMethodName = "test_{$testMethodNamePart}";
     return $testMethodName;
 }
예제 #2
0
 /**
  * Get an input string.
  *
  * Handles interactive help and abort commands.
  *
  * @param string $msg
  *
  * @return string
  * @throws \Box\TestScribe\Exception\AbortException
  */
 public function getInputString($msg)
 {
     $this->output->writeln($msg);
     $str = '';
     while (true) {
         $str = $this->rawInputWithPrompt->getString();
         if ($str === 'h') {
             $this->showHelp();
         } else {
             if ($str === 'a') {
                 throw new AbortException('Abort upon a user request');
             } else {
                 break;
             }
         }
     }
     return $str;
 }
예제 #3
0
 /**
  * @param string[] $menu
  *
  * @param string $msg
  *
  * @return int
  * @throws \Box\TestScribe\Exception\TestScribeException
  */
 public function selectFromMenu(array $menu, $msg)
 {
     $itemCount = count($menu);
     if ($itemCount < 2) {
         // There is no point of selecting from a menu with one or no item.
         throw new TestScribeException('Selecting from a menu with less than 2 items is not allowed.');
     }
     $this->output->writeln($msg);
     for ($i = 0; $i < $itemCount; $i++) {
         /** @var string $name */
         $name = $menu[$i];
         $id = (string) $i;
         $msg = "{$id} : {$name}";
         $this->output->writeln($msg);
     }
     $selectionString = $this->rawInputWithPrompt->getString();
     // @TODO (Ray Yang 9/30/15) : error handling
     $selectionId = (int) $selectionString;
     return $selectionId;
 }