diff --git a/src/Console/ConsoleIo.php b/src/Console/ConsoleIo.php index 883d2e28b8f..cfcadb5a517 100644 --- a/src/Console/ConsoleIo.php +++ b/src/Console/ConsoleIo.php @@ -209,7 +209,9 @@ public function overwrite($message, $newlines = 1, $size = null) // Store length of content + fill so if the new content // is shorter than the old content the next overwrite // will work. - $this->_lastWritten = $newBytes + $fill; + if ($fill > 0) { + $this->_lastWritten = $newBytes + $fill; + } } /** diff --git a/tests/TestCase/Console/ConsoleIoTest.php b/tests/TestCase/Console/ConsoleIoTest.php index 84740c3a418..f2bcfe27fdc 100644 --- a/tests/TestCase/Console/ConsoleIoTest.php +++ b/tests/TestCase/Console/ConsoleIoTest.php @@ -337,7 +337,7 @@ public function testOverwrite() * * @return void */ - public function testOverwriteShorterContent() + public function testOverwriteWithShorterContent() { $length = strlen('12345'); @@ -383,6 +383,45 @@ public function testOverwriteShorterContent() $this->io->overwrite('12', 0); } + /** + * Test overwriting content with longer content + * + * @return void + */ + public function testOverwriteWithLongerContent() + { + $this->out->expects($this->at(0)) + ->method('write') + ->with('1') + ->will($this->returnValue(1)); + + // Backspaces + $this->out->expects($this->at(1)) + ->method('write') + ->with(str_repeat("\x08", 1), 0) + ->will($this->returnValue(1)); + + $this->out->expects($this->at(2)) + ->method('write') + ->with('123', 0) + ->will($this->returnValue(3)); + + // Backspaces + $this->out->expects($this->at(3)) + ->method('write') + ->with(str_repeat("\x08", 3), 0) + ->will($this->returnValue(3)); + + $this->out->expects($this->at(4)) + ->method('write') + ->with('12345', 0) + ->will($this->returnValue(5)); + + $this->io->out('1'); + $this->io->overwrite('123', 0); + $this->io->overwrite('12345', 0); + } + /** * Tests that setLoggers works properly *