Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-35238 Fix getting input option value

  • Loading branch information...
commit 11c3c579a1456584495eb1a047921d9dba7c5add 1 parent c99910b
@mudrd8mz mudrd8mz authored
Showing with 20 additions and 4 deletions.
  1. +4 −4 mdeploy.php
  2. +16 −0 mdeploytest.php
View
8 mdeploy.php
@@ -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);
}
@@ -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;
}
View
16 mdeploytest.php
@@ -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);
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.