-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from gitlost/issue_4127
Shell:columns(): Better calc on Windows. Check TERM. Make testable.
- Loading branch information
Showing
2 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use cli\Shell; | ||
|
||
/** | ||
* Class TestShell | ||
*/ | ||
class TestShell extends PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* Test getting TERM columns. | ||
*/ | ||
function testColumns() { | ||
// Save. | ||
$env_term = getenv( 'TERM' ); | ||
$env_columns = getenv( 'COLUMNS' ); | ||
$env_is_windows = getenv( 'WP_CLI_TEST_IS_WINDOWS' ); | ||
$env_shell_columns_reset = getenv( 'PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET' ); | ||
|
||
putenv( 'PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET=1' ); | ||
|
||
// No TERM should result in default 80. | ||
|
||
putenv( 'TERM' ); | ||
|
||
putenv( 'WP_CLI_TEST_IS_WINDOWS=0' ); | ||
$columns = cli\Shell::columns(); | ||
$this->assertSame( 80, $columns ); | ||
|
||
putenv( 'WP_CLI_TEST_IS_WINDOWS=1' ); | ||
$columns = cli\Shell::columns(); | ||
$this->assertSame( 80, $columns ); | ||
|
||
// TERM and COLUMNS should result in whatever COLUMNS is. | ||
|
||
putenv( 'TERM=vt100' ); | ||
putenv( 'COLUMNS=100' ); | ||
|
||
putenv( 'WP_CLI_TEST_IS_WINDOWS=0' ); | ||
$columns = cli\Shell::columns(); | ||
$this->assertSame( 100, $columns ); | ||
|
||
putenv( 'WP_CLI_TEST_IS_WINDOWS=1' ); | ||
$columns = cli\Shell::columns(); | ||
$this->assertSame( 100, $columns ); | ||
|
||
// Restore. | ||
putenv( false === $env_term ? 'TERM' : "TERM=$env_term" ); | ||
putenv( false === $env_columns ? 'COLUMNS' : "COLUMNS=$env_columns" ); | ||
putenv( false === $env_is_windows ? 'WP_CLI_TEST_IS_WINDOWS' : "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" ); | ||
putenv( false === $env_shell_columns_reset ? 'PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET' : "PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET=$env_shell_columns_reset" ); | ||
} | ||
} |