Permalink
Browse files

Adding newline param to Shell::err

The signature of ::err is now identical to ::out
Adding tests for ::err
  • Loading branch information...
1 parent 73cbdf0 commit 4faa9d3b21de78c4d637673014894423d64e67f0 @davidpersson davidpersson committed Apr 16, 2009
Showing with 16 additions and 2 deletions.
  1. +3 −2 cake/console/libs/shell.php
  2. +13 −0 cake/tests/cases/console/libs/shell.test.php
View
5 cake/console/libs/shell.php
@@ -358,17 +358,18 @@ function out($string, $newline = true) {
* Outputs to the stderr filehandle.
*
* @param string $string Error text to output.
+ * @param boolean $newline If true, the outputs gets an added newline.
* @access public
*/
- function err($string) {
+ function err($string, $newline = true) {
if (is_array($string)) {
$str = '';
foreach ($string as $message) {
$str .= $message ."\n";
}
$string = $str;
}
- return $this->Dispatch->stderr($string."\n");
+ return $this->Dispatch->stderr($string . ($newline ? "\n" : ''));
}
/**
* Outputs a series of minus characters to the standard output, acts as a visual separator.
View
13 cake/tests/cases/console/libs/shell.test.php
@@ -161,6 +161,19 @@ function testOut() {
$this->Shell->out(array('Just', 'a', 'test'));
}
/**
+ * testErr method
+ *
+ * @return void
+ * @access public
+ */
+ function testErr() {
+ $this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n"));
+ $this->Shell->err('Just a test');
+
+ $this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n\n"));
+ $this->Shell->err(array('Just', 'a', 'test'));
+ }
+/**
* testIn method
*
* @return void

0 comments on commit 4faa9d3

Please sign in to comment.