Skip to content

Commit

Permalink
Fix for overwriting with longer content.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pustułka committed Jul 11, 2017
1 parent a6bf3f0 commit e5a0be6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Console/ConsoleIo.php
Expand Up @@ -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;
}
}

/**
Expand Down
41 changes: 40 additions & 1 deletion tests/TestCase/Console/ConsoleIoTest.php
Expand Up @@ -337,7 +337,7 @@ public function testOverwrite()
*
* @return void
*/
public function testOverwriteShorterContent()
public function testOverwriteWithShorterContent()
{
$length = strlen('12345');

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit e5a0be6

Please sign in to comment.