Permalink
Browse files

Merge pull request #10860 from cakephp/issue-10858

Fix overwrite() not replacing longer content.
  • Loading branch information...
markstory committed Jul 8, 2017
2 parents 0c1bcf6 + 0b675b4 commit 93e0657d976ac624e68c43fa2feadb51061f6488
Showing with 56 additions and 0 deletions.
  1. +5 −0 src/Console/ConsoleIo.php
  2. +51 −0 tests/TestCase/Console/ConsoleIoTest.php
@@ -205,6 +205,11 @@ public function overwrite($message, $newlines = 1, $size = null)
if ($newlines) {
$this->out($this->nl($newlines), 0);
}
// 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;
}
/**
@@ -332,6 +332,57 @@ public function testOverwrite()
$this->io->overwrite('Less text');
}
/**
* Test overwriting content with shorter content
*
* @return void
*/
public function testOverwriteShorterContent()
{
$length = strlen('12345');
$this->out->expects($this->at(0))
->method('write')
->with('12345')
->will($this->returnValue($length));
// Backspaces
$this->out->expects($this->at(1))
->method('write')
->with(str_repeat("\x08", $length), 0)
->will($this->returnValue($length));
$this->out->expects($this->at(2))
->method('write')
->with('123', 0)
->will($this->returnValue(3));
// 2 spaces output to pad up to 5 bytes
$this->out->expects($this->at(3))
->method('write')
->with(str_repeat(' ', $length - 3), 0)
->will($this->returnValue($length - 3));
// Backspaces
$this->out->expects($this->at(4))
->method('write')
->with(str_repeat("\x08", $length), 0)
->will($this->returnValue($length));
$this->out->expects($this->at(5))
->method('write')
->with('12', 0)
->will($this->returnValue(2));
$this->out->expects($this->at(6))
->method('write')
->with(str_repeat(' ', $length - 2), 0);
$this->io->out('12345');
$this->io->overwrite('123', 0);
$this->io->overwrite('12', 0);
}
/**
* Tests that setLoggers works properly
*

0 comments on commit 93e0657

Please sign in to comment.