Exemplo n.º 1
0
 public function testResetExclusions()
 {
     $option_1 = new ezcConsoleOption("a", "aaa");
     $option_2 = new ezcConsoleOption("b", "bbb");
     $rule = new ezcConsoleOptionRule($option_2, array("c"));
     $option_1->addExclusion($rule);
     $option_1->resetExclusions();
     $this->assertAttributeEquals(array(), "exclusions", $option_1);
 }
Exemplo n.º 2
0
 public function testProcessFailureExclusionValues()
 {
     $rule = new ezcConsoleOptionRule($this->input->getOption("y"), array("foo", "bar"));
     $option = new ezcConsoleOption("x", "execute");
     $option->addExclusion($rule);
     $this->input->registerOption($option);
     $args = array('foo.php', '-y', 'bar', '-x');
     $this->commonProcessTestFailure($args, 'ezcConsoleOptionExclusionViolationException');
 }
Exemplo n.º 3
0
 /**
  * Validated option exclusions.
  *
  * Validates exclusions by $option.
  *
  * @param ezcConsoleOption $option.
  */
 private function validateExclusions(ezcConsoleOption $option)
 {
     $optSet = $option->value !== false && (!is_array($option->value) || $option->value !== array());
     foreach ($option->getExclusions() as $excl) {
         if ($excl->ifSet === $optSet) {
             $this->validateExclusion($option, $excl);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Returns the synopsis string for a single option and its dependencies.
  *
  * This method returns a part of the program synopsis, specifically for a
  * certain parameter. The method recursively adds depending parameters up
  * to the 2nd depth level to the synopsis. The second parameter is used
  * to store the short names of all options that have already been used in 
  * the synopsis (to avoid adding an option twice). The 3rd parameter 
  * determines the actual deps in the option dependency recursion to 
  * terminate that after 2 recursions.
  * 
  * @param ezcConsoleOption $option        The option to include.
  * @param array(string) $usedOptions Array of used option short names.
  * @param int $depth                      Current recursion depth.
  * @return string The synopsis for this parameter.
  *
  * @apichange This method is deprecates. Implement your own {@link 
  *            ezcConsoleInputHelpGenerator} instead, as soon as the 
  *            interface is made public.
  */
 protected function createOptionSynopsis(ezcConsoleOption $option, &$usedOptions, $depth = 0)
 {
     $synopsis = '';
     // Break after a nesting level of 2
     if ($depth++ > 2 || in_array($option->short, $usedOptions['short']) && in_array($option->long, $usedOptions['long'])) {
         return $synopsis;
     }
     $usedOptions['short'][] = $option->short;
     $usedOptions['long'][] = $option->long;
     $synopsis .= $option->short !== "" ? "-{$option->short}" : "--{$option->long}";
     if (isset($option->default)) {
         $synopsis .= " " . ($option->type === ezcConsoleInput::TYPE_STRING ? '"' : '') . $option->default . ($option->type === ezcConsoleInput::TYPE_STRING ? '"' : '');
     } else {
         if ($option->type !== ezcConsoleInput::TYPE_NONE) {
             $synopsis .= " ";
             switch ($option->type) {
                 case ezcConsoleInput::TYPE_STRING:
                     $synopsis .= "<string>";
                     break;
                 case ezcConsoleInput::TYPE_INT:
                     $synopsis .= "<int>";
                     break;
             }
         }
     }
     foreach ($option->getDependencies() as $rule) {
         $deeperSynopsis = $this->createOptionSynopsis($rule->option, $usedOptions, $depth);
         $synopsis .= iconv_strlen(trim($deeperSynopsis), 'UTF-8') > 0 ? ' ' . $deeperSynopsis : '';
     }
     if ($option->arguments === false) {
         $allowsArgs = false;
     }
     // Make the whole thing optional?
     if ($option->mandatory === false) {
         $synopsis = "[{$synopsis}]";
     }
     return $synopsis . ' ';
 }