Skip to content

Commit

Permalink
MDL-35238 Fix getting input option value
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 8, 2012
1 parent c99910b commit 11c3c57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mdeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ protected function validate_option_name($name) {
* @param string $type the parameter type, e.g. {@link input_manager::TYPE_INT}
* @return mixed
*/
protected function get_required_option($name, $type) {
protected function get_required_option($name) {
if ($this->inputprovider->has_option($name)) {
return $this->cast_value($this->inputprovider->get_raw_option($name), $type);
return $this->inputprovider->get_option($name);
} else {
throw new missing_option_exception('Missing required option: '.$name);
}
Expand All @@ -283,9 +283,9 @@ protected function get_required_option($name, $type) {
* @param mixed $default the default value.
* @return mixed
*/
protected function get_optional_option($name, $type, $default) {
protected function get_optional_option($name, $default) {
if ($this->inputprovider->has_option($name)) {
return $this->inputprovider->get_raw_option($name);
return $this->inputprovider->get_option($name);
} else {
return $default;
}
Expand Down
16 changes: 16 additions & 0 deletions mdeploytest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,20 @@ public function test_has_option() {
$this->assertTrue($provider->has_option('help')); // help passed and it is a flag (value ignored)
$this->assertTrue($provider->has_option('h')); // 'h' is a shortname for 'help'
}

public function test_get_option() {
$input = testable_input_manager::instance();
$provider = input_fake_provider::instance();

$provider->set_fake_options(array('help' => false, 'passfile' => '_mdeploy.123456'));
$this->assertTrue($input->get_option('h'));
$this->assertEquals($input->get_option('passfile'), '_mdeploy.123456');
$this->assertEquals($input->get_option('password', 'admin123'), 'admin123');
try {
$this->assertEquals($input->get_option('password'), 'admin123'); // must throw exception (not passed but required)
$this->assertTrue(false);
} catch (missing_option_exception $e) {
$this->assertTrue(true);
}
}
}

0 comments on commit 11c3c57

Please sign in to comment.