Add system/CLI/CLI tests code

This commit is contained in:
KazuakiM 2017-06-16 00:14:57 +09:00
parent 766996696d
commit 9ee8e6e7a1
2 changed files with 65 additions and 6 deletions

View File

@ -583,7 +583,7 @@ class CLI
if ($pad_left > 0)
{
$lines = explode("\n", $lines);
$lines = explode(PHP_EOL, $lines);
$first = true;
@ -599,7 +599,7 @@ class CLI
}
});
$lines = implode("\n", $lines);
$lines = implode(PHP_EOL, $lines);
}
return $lines;

View File

@ -21,6 +21,64 @@ class CLITest extends \CIUnitTestCase
$this->assertInstanceOf(CLI::class, $actual);
}
public function testBeep()
{
$this->expectOutputString("\x07");
CLI::beep();
}
public function testBeep4()
{
$this->expectOutputString("\x07\x07\x07\x07");
CLI::beep(4);
}
public function testWait()
{
$time = time();
CLI::wait(1, true);
$this->assertEquals(1, time() - $time);
$time = time();
CLI::wait(1);
$this->assertEquals(1, time() - $time);
}
public function testIsWindows()
{
$this->assertEquals(('\\' === DIRECTORY_SEPARATOR), CLI::isWindows());
$this->assertEquals(defined('PHP_WINDOWS_VERSION_MAJOR'), CLI::isWindows());
}
public function testNewLine()
{
$this->expectOutputString('');
CLI::newLine();
}
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Invalid CLI foreground color: Foreground
*/
public function testColorExceptionForeground()
{
CLI::color('test', 'Foreground');
}
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Invalid CLI background color: Background
*/
public function testColorExceptionBackground()
{
CLI::color('test', 'white', 'Background');
}
public function testColor()
{
$this->assertEquals("\033[1;37m\033[42m\033[4mtest\033[0m", CLI::color('test', 'white', 'green', 'underline'));
}
public function testShowProgress()
{
CLI::write('first.');
@ -64,11 +122,12 @@ EOT;
$this->assertEquals($expected, CLITestStreamFilter::$buffer);
}
public function testWait()
public function testWrap()
{
$time = time();
CLI::wait(1, true);
$this->assertEquals(1, time() - $time);
$this->assertEquals('', CLI::wrap(''));
$this->assertEquals('1234'. PHP_EOL .' 5678'. PHP_EOL .' 90'. PHP_EOL .' abc'. PHP_EOL .' de'. PHP_EOL .' fghij'. PHP_EOL .' 0987654321', CLI::wrap('1234 5678 90'. PHP_EOL .'abc de fghij'. PHP_EOL .'0987654321', 5, 1));
$this->assertEquals('1234 5678 90'. PHP_EOL .' abc de fghij'. PHP_EOL .' 0987654321', CLI::wrap('1234 5678 90'. PHP_EOL .'abc de fghij'. PHP_EOL .'0987654321', 999, 2));
$this->assertEquals('1234 5678 90'. PHP_EOL .'abc de fghij'. PHP_EOL .'0987654321', CLI::wrap('1234 5678 90'. PHP_EOL .'abc de fghij'. PHP_EOL .'0987654321'));
}
}