mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Backport param() access.
This commit is contained in:
parent
26b3713bd6
commit
1c56c723f5
2 changed files with 58 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue