Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit-annotate untestable code in CLI #3264

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ public static function init()
{
// If the command is being called from a controller
// we need to define STDOUT ourselves
// @codeCoverageIgnoreStart
define('STDOUT', 'php://output');
// @codeCoverageIgnoreEnd
}
}

Expand Down Expand Up @@ -249,7 +251,8 @@ public static function input(string $prefix = null): string
* @param string|array $options String to a default value, array to a list of options (the first option will be the default value)
* @param string $validation Validation rules
*
* @return string The user input
* @return string The user input
*
* @codeCoverageIgnore
*/
public static function prompt(string $field, $options = null, string $validation = null): string
Expand Down Expand Up @@ -309,7 +312,8 @@ public static function prompt(string $field, $options = null, string $validation
* @param string $value Input value
* @param string $rules Validation rules
*
* @return boolean
* @return boolean
*
* @codeCoverageIgnore
*/
protected static function validate(string $field, string $value, string $rules): bool
Expand Down Expand Up @@ -488,7 +492,8 @@ public static function newLine(int $num = 1)
/**
* Clears the screen of output
*
* @return void
* @return void
*
* @codeCoverageIgnore
*/
public static function clearScreen()
Expand Down Expand Up @@ -759,8 +764,10 @@ public static function generateDimensions()
}
else
{
// @codeCoverageIgnoreStart
static::$height = (int) exec('tput lines');
static::$width = (int) exec('tput cols');
// @codeCoverageIgnoreEnd
}
}
}
Expand Down Expand Up @@ -1139,8 +1146,8 @@ public static function table(array $tbody, array $thead = [])
* For now, just echo the content, but look into a better
* solution down the road.
*
* @param $handle
* @param string $string
* @param resource $handle
* @param string $string
*/
protected static function fwrite($handle, string $string)
{
Expand All @@ -1150,7 +1157,9 @@ protected static function fwrite($handle, string $string)
return;
}

// @codeCoverageIgnoreStart
echo $string;
// @codeCoverageIgnoreEnd
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,14 @@ public function testParseCommandMultipleOptions()

public function testWindow()
{
$height = new \ReflectionProperty(CLI::class, 'height');
$height->setAccessible(true);
$height->setValue(null);
$this->assertTrue(is_int(CLI::getHeight()));

$width = new \ReflectionProperty(CLI::class, 'width');
$width->setAccessible(true);
$width->setValue(null);
$this->assertTrue(is_int(CLI::getWidth()));
}

Expand Down