2015-12-01 12:02:51 +00:00
|
|
|
<?php
|
2015-12-01 14:26:22 +00:00
|
|
|
/**
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2015-12-01 14:26:22 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2015-12-01 14:26:22 +00:00
|
|
|
* @since 2.8
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
|
*/
|
2015-12-01 12:02:51 +00:00
|
|
|
App::uses("ConsoleOutput", "Console");
|
|
|
|
|
|
|
|
/**
|
2015-12-01 14:26:22 +00:00
|
|
|
* StubOutput makes testing shell commands/shell helpers easier.
|
|
|
|
*
|
|
|
|
* You can use this class by injecting it into a Helper instance:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* App::uses("ConsoleOutputStub", "TestSuite/Stub");
|
|
|
|
*
|
|
|
|
* $output = new ConsoleOutputStub();
|
|
|
|
* $helper = new ProgressHelper($output);
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
class ConsoleOutputStub extends ConsoleOutput {
|
|
|
|
|
2015-12-01 12:02:51 +00:00
|
|
|
/**
|
2015-12-01 14:26:22 +00:00
|
|
|
* Buffered messages.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-12-01 15:16:54 +00:00
|
|
|
protected $_out = array();
|
2015-12-01 12:02:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of bytes written by last call to write
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2015-12-01 14:26:22 +00:00
|
|
|
protected $_lastWritten = 0;
|
2015-12-01 12:02:51 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-01 14:26:22 +00:00
|
|
|
* Write output to the buffer.
|
|
|
|
*
|
|
|
|
* @param string|array $message A string or an array of strings to output
|
|
|
|
* @param int $newlines Number of newlines to append
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function write($message, $newlines = 1) {
|
|
|
|
foreach ((array)$message as $line) {
|
|
|
|
$this->_out[] = $line;
|
|
|
|
$this->_lastWritten = strlen($line);
|
|
|
|
}
|
|
|
|
$newlines--;
|
|
|
|
while ($newlines > 0) {
|
|
|
|
$this->_out[] = '';
|
|
|
|
$this->_lastWritten = 0;
|
|
|
|
$newlines--;
|
|
|
|
}
|
|
|
|
}
|
2015-12-01 12:02:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overwrite output already written to the buffer.
|
|
|
|
*
|
|
|
|
* @param array|string $message The message to output.
|
|
|
|
* @param int $newlines Number of newlines to append.
|
|
|
|
* @param int $size The number of bytes to overwrite. Defaults to the
|
|
|
|
* length of the last message output.
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-12-01 14:26:22 +00:00
|
|
|
public function overwrite($message, $newlines = 1, $size = null) {
|
|
|
|
//insert an empty array to mock deletion of existing output
|
|
|
|
$this->_out[] = "";
|
|
|
|
//append new message to output
|
|
|
|
$this->write($message, $newlines);
|
|
|
|
}
|
2015-12-01 12:02:51 +00:00
|
|
|
|
2015-12-01 14:26:22 +00:00
|
|
|
/**
|
|
|
|
* Get the buffered output.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function messages() {
|
|
|
|
return $this->_out;
|
|
|
|
}
|
2015-12-01 12:02:51 +00:00
|
|
|
}
|