Merge pull request #6884 from cakephp/2.7-shell

Backport param() access.
This commit is contained in:
Mark Story 2015-06-24 21:45:09 -04:00
commit ab2f4c2cd5
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.
*