/** * @param \DataSift\Storyplayer\ConfigLib\SystemsUnderTestList $sutList * @param string $defaultSutName */ public function __construct($sutList, $defaultSutName) { // define our name, and our description $this->setName('sut'); $this->setShortDescription('set the system-under-test to test'); $this->setLongDesc("If you have a test repository that contains tests for multiple " . "pieces of software, you can use this switch to choose which " . "of those systems-under-test to deploy to the test environment." . PHP_EOL . PHP_EOL . "If you omit this switch, Storyplayer will use the default system-under-test " . "listed in your storyplayer.json[.dist] config file. And if you don't have " . "a default system-under-test in your config file, then Storyplayer will " . "remind you that you need to tell it which system-under-test to target." . PHP_EOL . PHP_EOL . "If you only have one system-under-test defined, then this switch has no " . "effect when used, and Storyplayer will always use the system-under-test " . "that you have defined." . PHP_EOL . PHP_EOL . "See http://datasift.github.io/storyplayer/ " . "for how to define systems-under-test."); // what are the short switches? $this->addShortSwitch('s'); // what are the long switches? $this->addLongSwitch('sut'); $this->addLongSwitch('system-under-test'); // what is the required argument? $requiredArgMsg = "the system-under-test to test; one of:" . PHP_EOL . PHP_EOL; foreach ($sutList->getEntryNames() as $sutName) { $requiredArgMsg .= "* {$sutName}" . PHP_EOL; } if ($defaultSutName) { $requiredArgMsg .= PHP_EOL . ' '; } $this->setRequiredArg('<system-under-test>', $requiredArgMsg); $this->setArgValidator(new Feature_SystemUnderTestConfigValidator($sutList, $defaultSutName)); if ($defaultSutName) { $this->setArgHasDefaultValueOf($defaultSutName); } // all done }
/** * * @param mixed $value * @param ValidationResult $result * @return ValidationResult */ public function validate($value, ValidationResult $result = null) { if ($result === null) { $result = new ValidationResult($value); } // strip off .json if it is there $value = basename($value, ".json"); // the $value must be a valid system-under-test name if (!$this->sutList->hasEntry($value)) { $result->addError(static::MSG_NOTVALIDSUT); return $result; } return $result; }