mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Add system/CLI/CLI tests code
This commit is contained in:
parent
766996696d
commit
9ee8e6e7a1
@ -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;
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user