Skip to content
Permalink
Browse files

Backport param() access.

  • Loading branch information...
dereuromark committed Jun 24, 2015
1 parent 26b3713 commit 1c56c723f5e21ba1abf8977ba070ec97217382a5
Showing with 58 additions and 0 deletions.
  1. +13 −0 lib/Cake/Console/Shell.php
  2. +45 −0 lib/Cake/Test/Case/Console/ShellTest.php
@@ -499,6 +499,19 @@ public function __get($name) {
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 @@ public function testShellNaming() {
$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.
*

0 comments on commit 1c56c72

Please sign in to comment.
You can’t perform that action at this time.