Backport param() access.

This commit is contained in:
Mark Scherer 2015-06-25 00:52:33 +02:00
parent 26b3713bd6
commit 1c56c723f5
2 changed files with 58 additions and 0 deletions

View file

@ -499,6 +499,19 @@ class Shell extends Object {
return $this->{$name};
}
/**
* Safely access the values in $this->params.
*
* @param string $name The name of the parameter to get.
* @return string|bool|null Value. Will return null if it doesn't exist.
*/
public function param($name) {
if (!isset($this->params[$name])) {
return null;
}
return $this->params[$name];
}
/**
* Prompts the user for input, and returns it.
*

View file

@ -855,6 +855,51 @@ TEXT;
$this->assertEquals($expected, $this->Shell->TestApple->name);
}
/**
* Test reading params
*
* @dataProvider paramReadingDataProvider
*/
public function testParamReading($toRead, $expected) {
$this->Shell->params = array(
'key' => 'value',
'help' => false,
'emptykey' => '',
'truthy' => true
);
$this->assertSame($expected, $this->Shell->param($toRead));
}
/**
* Data provider for testing reading values with Shell::param()
*
* @return array
*/
public function paramReadingDataProvider() {
return array(
array(
'key',
'value',
),
array(
'help',
false,
),
array(
'emptykey',
'',
),
array(
'truthy',
true,
),
array(
'does_not_exist',
null,
)
);
}
/**
* Test that option parsers are created with the correct name/command.
*