diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..d0a96c9
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,31 @@
+name: CI
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ tests:
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ env:
+ TERM: xterm-256color
+ strategy:
+ fail-fast: false
+ matrix:
+ php: ['8.2', '8.3', '8.4', '8.5']
+ steps:
+ - uses: actions/checkout@v4
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ coverage: none
+ - uses: ramsey/composer-install@v3
+ - run: vendor/bin/phpunit --stop-on-error
+ - run: composer cs
+ - run: composer static
diff --git a/.gitignore b/.gitignore
index 8969645..e3ec1a5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
vendor/
.idea
/composer.lock
+.phpunit.cache
+/.phpunit.result.cache
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index c098fd2..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-language: php
-
-php:
- - 7.1
- - 7.2
-
-install:
- - composer self-update
- - composer install
-
-before_script:
- - mkdir -p build/logs
-
-script:
- - ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- - composer cs
- - composer static
-
-after_script:
- - bash <(curl -s https://codecov.io/bash)
- - wget https://scrutinizer-ci.com/ocular.phar
- - php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml
diff --git a/README.md b/README.md
index c96b02a..d204283 100644
--- a/README.md
+++ b/README.md
@@ -5,14 +5,8 @@
-
-
-
-
-
-
-
+
+
diff --git a/composer.json b/composer.json
index 09b9c9f..c1efbf2 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,13 @@
{
"name": "php-school/terminal",
"description": "A command line terminal utility in PHP",
- "keywords": ["cli", "console", "terminal", "phpschool", "php-school"],
+ "keywords": [
+ "cli",
+ "console",
+ "terminal",
+ "phpschool",
+ "php-school"
+ ],
"license": "MIT",
"authors": [
{
@@ -14,27 +20,29 @@
}
],
"require": {
- "php" : ">=7.2"
+ "php": ">=8.2"
},
"require-dev": {
- "phpunit/phpunit": "^7.1",
- "squizlabs/php_codesniffer": "^3.2",
- "phpstan/phpstan": "^0.9.2"
+ "phpunit/phpunit": "^11.5",
+ "squizlabs/php_codesniffer": "^3.13",
+ "phpstan/phpstan": "^2.1"
},
- "autoload" : {
- "psr-4" : {
+ "autoload": {
+ "psr-4": {
"PhpSchool\\Terminal\\": "src"
}
},
"autoload-dev": {
- "psr-4": { "PhpSchool\\TerminalTest\\": "test" }
+ "psr-4": {
+ "PhpSchool\\TerminalTest\\": "test"
+ }
},
- "scripts" : {
- "cs" : [
- "phpcs src --standard=PSR2",
- "phpcs test --standard=PSR2"
+ "scripts": {
+ "cs": [
+ "phpcs src --standard=PSR12",
+ "phpcs test --standard=PSR12"
],
- "static" : [
+ "static": [
"phpstan analyse src --level=7"
]
}
diff --git a/phpunit.xml b/phpunit.xml
index 826bfc8..e9e1e8b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,12 +1,22 @@
+
+
+
+ test
+
+
-
-
- ./test
-
-
-
- ./src
-
-
-
\ No newline at end of file
+
+
+ src
+
+
+
diff --git a/src/Exception/NotInteractiveTerminal.php b/src/Exception/NotInteractiveTerminal.php
index 764cbf1..8eb69cf 100644
--- a/src/Exception/NotInteractiveTerminal.php
+++ b/src/Exception/NotInteractiveTerminal.php
@@ -7,12 +7,12 @@
*/
class NotInteractiveTerminal extends \RuntimeException
{
- public static function inputNotInteractive() : self
+ public static function inputNotInteractive(): self
{
return new self('Input stream is not interactive (non TTY)');
}
- public static function outputNotInteractive() : self
+ public static function outputNotInteractive(): self
{
return new self('Output stream is not interactive (non TTY)');
}
diff --git a/src/IO/BufferedOutput.php b/src/IO/BufferedOutput.php
index ad00297..2a50eca 100644
--- a/src/IO/BufferedOutput.php
+++ b/src/IO/BufferedOutput.php
@@ -7,6 +7,9 @@
*/
class BufferedOutput implements OutputStream
{
+ /**
+ * @var string
+ */
private $buffer = '';
public function write(string $buffer): void
@@ -14,7 +17,7 @@ public function write(string $buffer): void
$this->buffer .= $buffer;
}
- public function fetch(bool $clean = true) : string
+ public function fetch(bool $clean = true): string
{
$buffer = $this->buffer;
@@ -25,7 +28,7 @@ public function fetch(bool $clean = true) : string
return $buffer;
}
- public function __toString() : string
+ public function __toString(): string
{
return $this->fetch();
}
@@ -33,7 +36,7 @@ public function __toString() : string
/**
* Whether the stream is connected to an interactive terminal
*/
- public function isInteractive() : bool
+ public function isInteractive(): bool
{
return false;
}
diff --git a/src/IO/InputStream.php b/src/IO/InputStream.php
index 8fcd82a..4bb1902 100644
--- a/src/IO/InputStream.php
+++ b/src/IO/InputStream.php
@@ -11,10 +11,10 @@ interface InputStream
* Callback should be called with the number of bytes requested
* when ready.
*/
- public function read(int $numBytes, callable $callback) : void;
+ public function read(int $numBytes, callable $callback): void;
/**
* Whether the stream is connected to an interactive terminal
*/
- public function isInteractive() : bool;
+ public function isInteractive(): bool;
}
diff --git a/src/IO/OutputStream.php b/src/IO/OutputStream.php
index 9314cd5..397196c 100644
--- a/src/IO/OutputStream.php
+++ b/src/IO/OutputStream.php
@@ -10,10 +10,10 @@ interface OutputStream
/**
* Write the buffer to the stream
*/
- public function write(string $buffer) : void;
+ public function write(string $buffer): void;
/**
* Whether the stream is connected to an interactive terminal
*/
- public function isInteractive() : bool;
+ public function isInteractive(): bool;
}
diff --git a/src/IO/ResourceInputStream.php b/src/IO/ResourceInputStream.php
index fecd37e..41823f5 100644
--- a/src/IO/ResourceInputStream.php
+++ b/src/IO/ResourceInputStream.php
@@ -22,30 +22,41 @@ class ResourceInputStream implements InputStream
*/
private $blocking;
+ /**
+ * @param resource $stream
+ */
public function __construct($stream = \STDIN)
{
if (!is_resource($stream) || get_resource_type($stream) !== 'stream') {
throw new \InvalidArgumentException('Expected a valid stream');
}
+ /** @var array $meta Not every stream type (eg php://memory) reports 'blocked' */
$meta = stream_get_meta_data($stream);
if (strpos($meta['mode'], 'r') === false && strpos($meta['mode'], '+') === false) {
throw new \InvalidArgumentException('Expected a readable stream');
}
- $this->blocking = $meta['blocked'];
+ $this->blocking = (bool) ($meta['blocked'] ?? true);
$this->stream = $stream;
}
/**
* Restore the blocking state.
*/
- public function __destruct() {
- stream_set_blocking($this->stream, $this->blocking);
+ public function __destruct()
+ {
+ if (is_resource($this->stream)) {
+ stream_set_blocking($this->stream, $this->blocking);
+ }
}
- public function read(int $numBytes, callable $callback) : void
+ public function read(int $numBytes, callable $callback): void
{
+ if ($numBytes < 1) {
+ throw new \InvalidArgumentException('Number of bytes to read must be greater than 0');
+ }
+
$buffer = fread($this->stream, $numBytes);
if (!empty($buffer)) {
// Prevent blocking to handle pasted input.
@@ -61,7 +72,7 @@ public function read(int $numBytes, callable $callback) : void
/**
* Whether the stream is connected to an interactive terminal
*/
- public function isInteractive() : bool
+ public function isInteractive(): bool
{
return stream_isatty($this->stream);
}
diff --git a/src/IO/ResourceOutputStream.php b/src/IO/ResourceOutputStream.php
index f91134d..07b5ba8 100644
--- a/src/IO/ResourceOutputStream.php
+++ b/src/IO/ResourceOutputStream.php
@@ -17,6 +17,9 @@ class ResourceOutputStream implements OutputStream
*/
private $stream;
+ /**
+ * @param resource $stream
+ */
public function __construct($stream = \STDOUT)
{
if (!is_resource($stream) || get_resource_type($stream) !== 'stream') {
@@ -39,7 +42,7 @@ public function write(string $buffer): void
/**
* Whether the stream is connected to an interactive terminal
*/
- public function isInteractive() : bool
+ public function isInteractive(): bool
{
return stream_isatty($this->stream);
}
diff --git a/src/InputCharacter.php b/src/InputCharacter.php
index 7829512..394e908 100644
--- a/src/InputCharacter.php
+++ b/src/InputCharacter.php
@@ -6,6 +6,7 @@
/**
* @author Aydin Hassan
+ * @phpstan-consistent-constructor
*/
class InputCharacter
{
@@ -28,6 +29,9 @@ class InputCharacter
public const TAB = 'TAB';
public const ESC = 'ESC';
+ /**
+ * @var array
+ */
private static $controls = [
"\033[A" => self::UP,
"\033[B" => self::DOWN,
@@ -54,23 +58,23 @@ public function __construct(string $data)
$this->data = $data;
}
- public function isHandledControl() : bool
+ public function isHandledControl(): bool
{
- return isset(static::$controls[$this->data]);
+ return isset(self::$controls[$this->data]);
}
/**
* Is this character a control sequence?
*/
- public function isControl() : bool
+ public function isControl(): bool
{
- return preg_match('/[\x00-\x1F\x7F]/', $this->data);
+ return preg_match('/[\x00-\x1F\x7F]/', $this->data) === 1;
}
/**
* Is this character a normal character?
*/
- public function isNotControl() : bool
+ public function isNotControl(): bool
{
return ! $this->isControl();
}
@@ -78,7 +82,7 @@ public function isNotControl() : bool
/**
* Get the raw character or control sequence
*/
- public function get() : string
+ public function get(): string
{
return $this->data;
}
@@ -89,19 +93,19 @@ public function get() : string
*
* Throws an exception if the character is not actually a control sequence
*/
- public function getControl() : string
+ public function getControl(): string
{
- if (!isset(static::$controls[$this->data])) {
+ if (!isset(self::$controls[$this->data])) {
throw new \RuntimeException(sprintf('Character "%s" is not a control', $this->data));
}
- return static::$controls[$this->data];
+ return self::$controls[$this->data];
}
/**
* Get the raw character or control sequence
*/
- public function __toString() : string
+ public function __toString(): string
{
return $this->get();
}
@@ -109,29 +113,31 @@ public function __toString() : string
/**
* Does the given control name exist? eg self::UP.
*/
- public static function controlExists(string $controlName) : bool
+ public static function controlExists(string $controlName): bool
{
- return in_array($controlName, static::$controls, true);
+ return in_array($controlName, self::$controls, true);
}
/**
* Get all of the available control names
+ *
+ * @return list
*/
- public static function getControls() : array
+ public static function getControls(): array
{
- return array_values(array_unique(static::$controls));
+ return array_values(array_unique(self::$controls));
}
/**
* Create a instance from a given control name. Throws an exception if the
* control name does not exist.
*/
- public static function fromControlName(string $controlName) : self
+ public static function fromControlName(string $controlName): self
{
if (!static::controlExists($controlName)) {
throw new \InvalidArgumentException(sprintf('Control "%s" does not exist', $controlName));
}
- return new static(array_search($controlName, static::$controls, true));
+ return new static((string) array_search($controlName, self::$controls, true));
}
}
diff --git a/src/NonCanonicalReader.php b/src/NonCanonicalReader.php
index 6d26666..6e39c37 100644
--- a/src/NonCanonicalReader.php
+++ b/src/NonCanonicalReader.php
@@ -27,7 +27,7 @@ class NonCanonicalReader
* Map of characters to controls.
* Eg map 'w' to the up control.
*
- * @var array
+ * @var array
*/
private $mappings = [];
@@ -38,7 +38,7 @@ public function __construct(Terminal $terminal)
$this->terminal->disableCanonicalMode();
}
- public function addControlMapping(string $character, string $mapToControl) : void
+ public function addControlMapping(string $character, string $mapToControl): void
{
if (!InputCharacter::controlExists($mapToControl)) {
throw new \InvalidArgumentException(sprintf('Control "%s" does not exist', $mapToControl));
@@ -47,7 +47,10 @@ public function addControlMapping(string $character, string $mapToControl) : voi
$this->mappings[$character] = $mapToControl;
}
- public function addControlMappings(array $mappings) : void
+ /**
+ * @param array $mappings
+ */
+ public function addControlMappings(array $mappings): void
{
foreach ($mappings as $character => $mapToControl) {
$this->addControlMapping($character, $mapToControl);
@@ -59,7 +62,7 @@ public function addControlMappings(array $mappings) : void
*
* @return InputCharacter
*/
- public function readCharacter() : InputCharacter
+ public function readCharacter(): InputCharacter
{
$char = $this->terminal->read(4);
diff --git a/src/Terminal.php b/src/Terminal.php
index 96d1603..2c5e768 100644
--- a/src/Terminal.php
+++ b/src/Terminal.php
@@ -11,52 +11,52 @@ interface Terminal
/**
* Get the available width of the terminal
*/
- public function getWidth() : int;
+ public function getWidth(): int;
/**
* Get the available height of the terminal
*/
- public function getHeight() : int;
+ public function getHeight(): int;
/**
* Get the number of colours the terminal supports (1, 8, 256, true colours)
*/
- public function getColourSupport() : int;
+ public function getColourSupport(): int;
/**
* Disables echoing every character back to the terminal. This means
* we do not have to clear the line when reading.
*/
- public function disableEchoBack() : void;
+ public function disableEchoBack(): void;
/**
* Enable echoing back every character input to the terminal.
*/
- public function enableEchoBack() : void;
+ public function enableEchoBack(): void;
/**
* Is echo back mode enabled
*/
- public function isEchoBack() : bool;
+ public function isEchoBack(): bool;
/**
* Disable canonical input (allow each key press for reading, rather than the whole line)
*
* @see https://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html
*/
- public function disableCanonicalMode() : void;
+ public function disableCanonicalMode(): void;
/**
* Enable canonical input - read input by line
*
* @see https://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html
*/
- public function enableCanonicalMode() : void;
+ public function enableCanonicalMode(): void;
/**
* Is canonical mode enabled or not
*/
- public function isCanonicalMode() : bool;
+ public function isCanonicalMode(): bool;
/**
* Check if the Input & Output streams are interactive. Eg - they are
@@ -64,70 +64,70 @@ public function isCanonicalMode() : bool;
*
* @return bool
*/
- public function isInteractive() : bool;
+ public function isInteractive(): bool;
/**
* Restore the terminals original configuration
*/
- public function restoreOriginalConfiguration() : void;
+ public function restoreOriginalConfiguration(): void;
/**
* Test whether terminal supports colour output
*/
- public function supportsColour() : bool;
+ public function supportsColour(): bool;
/**
* Clear the terminal window
*/
- public function clear() : void;
+ public function clear(): void;
/**
* Clear the current cursors line
*/
- public function clearLine() : void;
+ public function clearLine(): void;
/**
* Erase screen from the current line down to the bottom of the screen
*/
- public function clearDown() : void;
+ public function clearDown(): void;
/**
* Clean the whole console without jumping the window
*/
- public function clean() : void;
+ public function clean(): void;
/**
* Enable cursor display
*/
- public function enableCursor() : void;
+ public function enableCursor(): void;
/**
* Disable cursor display
*/
- public function disableCursor() : void;
+ public function disableCursor(): void;
/**
* Move the cursor to the top left of the window
*/
- public function moveCursorToTop() : void;
+ public function moveCursorToTop(): void;
/**
* Move the cursor to the start of a specific row
*/
- public function moveCursorToRow(int $rowNumber) : void;
+ public function moveCursorToRow(int $rowNumber): void;
/**
* Move the cursor to a specific column
*/
- public function moveCursorToColumn(int $columnNumber) : void;
+ public function moveCursorToColumn(int $columnNumber): void;
/**
* Read from the input stream
*/
- public function read(int $bytes) : string;
+ public function read(int $bytes): string;
/**
* Write to the output stream
*/
- public function write(string $buffer) : void;
+ public function write(string $buffer): void;
}
diff --git a/src/UnixTerminal.php b/src/UnixTerminal.php
index 879b1a7..6e4a1a1 100644
--- a/src/UnixTerminal.php
+++ b/src/UnixTerminal.php
@@ -34,9 +34,9 @@ class UnixTerminal implements Terminal
* @var int
*/
private $height;
-
+
/**
- * @var int;
+ * @var int|null
*/
private $colourSupport;
@@ -63,37 +63,37 @@ public function __construct(InputStream $input, OutputStream $output)
$this->output = $output;
}
- private function getOriginalCanonicalMode() : void
+ private function getOriginalCanonicalMode(): void
{
exec('stty -a', $output);
$this->isCanonical = (strpos(implode("\n", $output), ' icanon') !== false);
}
- public function getWidth() : int
+ public function getWidth(): int
{
return $this->width ?: $this->width = (int) exec('tput cols');
}
- public function getHeight() : int
+ public function getHeight(): int
{
return $this->height ?: $this->height = (int) exec('tput lines');
}
- public function getColourSupport() : int
+ public function getColourSupport(): int
{
return $this->colourSupport ?: $this->colourSupport = (int) exec('tput colors');
}
- private function getOriginalConfiguration() : string
+ private function getOriginalConfiguration(): string
{
- return $this->originalConfiguration ?: $this->originalConfiguration = exec('stty -g');
+ return $this->originalConfiguration ?: $this->originalConfiguration = (string) exec('stty -g');
}
/**
* Disables echoing every character back to the terminal. This means
* we do not have to clear the line when reading.
*/
- public function disableEchoBack() : void
+ public function disableEchoBack(): void
{
exec('stty -echo');
$this->echoBack = false;
@@ -102,7 +102,7 @@ public function disableEchoBack() : void
/**
* Enable echoing back every character input to the terminal.
*/
- public function enableEchoBack() : void
+ public function enableEchoBack(): void
{
exec('stty echo');
$this->echoBack = true;
@@ -111,7 +111,7 @@ public function enableEchoBack() : void
/**
* Is echo back mode enabled
*/
- public function isEchoBack() : bool
+ public function isEchoBack(): bool
{
return $this->echoBack;
}
@@ -121,7 +121,7 @@ public function isEchoBack() : bool
*
* @see https://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html
*/
- public function disableCanonicalMode() : void
+ public function disableCanonicalMode(): void
{
if ($this->isCanonical) {
exec('stty -icanon');
@@ -134,7 +134,7 @@ public function disableCanonicalMode() : void
*
* @see https://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html
*/
- public function enableCanonicalMode() : void
+ public function enableCanonicalMode(): void
{
if (!$this->isCanonical) {
exec('stty icanon');
@@ -145,7 +145,7 @@ public function enableCanonicalMode() : void
/**
* Is canonical mode enabled or not
*/
- public function isCanonicalMode() : bool
+ public function isCanonicalMode(): bool
{
return $this->isCanonical;
}
@@ -153,7 +153,7 @@ public function isCanonicalMode() : bool
/**
* Restore the original terminal configuration
*/
- public function restoreOriginalConfiguration() : void
+ public function restoreOriginalConfiguration(): void
{
exec('stty ' . $this->getOriginalConfiguration());
}
@@ -164,7 +164,7 @@ public function restoreOriginalConfiguration() : void
*
* @return bool
*/
- public function isInteractive() : bool
+ public function isInteractive(): bool
{
return $this->input->isInteractive() && $this->output->isInteractive();
}
@@ -173,7 +173,7 @@ public function isInteractive() : bool
* Assert that both the Input & Output streams are interactive. Throw
* `NotInteractiveTerminal` if not.
*/
- public function mustBeInteractive() : void
+ public function mustBeInteractive(): void
{
if (!$this->input->isInteractive()) {
throw NotInteractiveTerminal::inputNotInteractive();
@@ -187,7 +187,7 @@ public function mustBeInteractive() : void
/**
* @see https://github.com/symfony/Console/blob/master/Output/StreamOutput.php#L95-L102
*/
- public function supportsColour() : bool
+ public function supportsColour(): bool
{
if (DIRECTORY_SEPARATOR === '\\') {
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
@@ -196,12 +196,12 @@ public function supportsColour() : bool
return $this->isInteractive();
}
- public function clear() : void
+ public function clear(): void
{
$this->output->write("\033[2J");
}
- public function clearLine() : void
+ public function clearLine(): void
{
$this->output->write("\033[2K");
}
@@ -209,12 +209,12 @@ public function clearLine() : void
/**
* Erase screen from the current line down to the bottom of the screen
*/
- public function clearDown() : void
+ public function clearDown(): void
{
$this->output->write("\033[J");
}
- public function clean() : void
+ public function clean(): void
{
foreach (range(0, $this->getHeight()) as $rowNum) {
$this->moveCursorToRow($rowNum);
@@ -222,37 +222,37 @@ public function clean() : void
}
}
- public function enableCursor() : void
+ public function enableCursor(): void
{
$this->output->write("\033[?25h");
}
- public function disableCursor() : void
+ public function disableCursor(): void
{
$this->output->write("\033[?25l");
}
- public function moveCursorToTop() : void
+ public function moveCursorToTop(): void
{
$this->output->write("\033[H");
}
- public function moveCursorToRow(int $rowNumber) : void
+ public function moveCursorToRow(int $rowNumber): void
{
$this->output->write(sprintf("\033[%d;0H", $rowNumber));
}
- public function moveCursorToColumn(int $column) : void
+ public function moveCursorToColumn(int $column): void
{
$this->output->write(sprintf("\033[%dC", $column));
}
- public function showSecondaryScreen() : void
+ public function showSecondaryScreen(): void
{
$this->output->write("\033[?47h");
}
- public function showPrimaryScreen() : void
+ public function showPrimaryScreen(): void
{
$this->output->write("\033[?47l");
}
diff --git a/test/Exception/NotInteractiveTerminalTest.php b/test/Exception/NotInteractiveTerminalTest.php
index 6ace151..f87f0e0 100644
--- a/test/Exception/NotInteractiveTerminalTest.php
+++ b/test/Exception/NotInteractiveTerminalTest.php
@@ -10,14 +10,14 @@
*/
class NotInteractiveTerminalTest extends TestCase
{
- public function testInputNotInteractive() : void
+ public function testInputNotInteractive(): void
{
$e = NotInteractiveTerminal::inputNotInteractive();
self::assertEquals('Input stream is not interactive (non TTY)', $e->getMessage());
}
- public function testOutputNotInteractive() : void
+ public function testOutputNotInteractive(): void
{
$e = NotInteractiveTerminal::outputNotInteractive();
diff --git a/test/IO/BufferedOutputTest.php b/test/IO/BufferedOutputTest.php
index 9e116b7..4c6479e 100644
--- a/test/IO/BufferedOutputTest.php
+++ b/test/IO/BufferedOutputTest.php
@@ -10,35 +10,35 @@
*/
class BufferedOutputTest extends TestCase
{
- public function testFetch() : void
+ public function testFetch(): void
{
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$output->write('one');
static::assertEquals('one', $output->fetch());
}
- public function testFetchWithMultipleWrites() : void
+ public function testFetchWithMultipleWrites(): void
{
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$output->write('one');
$output->write('two');
static::assertEquals('onetwo', $output->fetch());
}
- public function testFetchCleansBufferByDefault() : void
+ public function testFetchCleansBufferByDefault(): void
{
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$output->write('one');
static::assertEquals('one', $output->fetch());
static::assertEquals('', $output->fetch());
}
- public function testFetchWithoutCleaning() : void
+ public function testFetchWithoutCleaning(): void
{
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$output->write('one');
static::assertEquals('one', $output->fetch(false));
@@ -48,9 +48,9 @@ public function testFetchWithoutCleaning() : void
static::assertEquals('onetwo', $output->fetch(false));
}
- public function testToString() : void
+ public function testToString(): void
{
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$output->write('one');
static::assertEquals('one', (string) $output);
diff --git a/test/IO/ResourceInputStreamTest.php b/test/IO/ResourceInputStreamTest.php
index 952573e..27c50f0 100644
--- a/test/IO/ResourceInputStreamTest.php
+++ b/test/IO/ResourceInputStreamTest.php
@@ -10,21 +10,21 @@
*/
class ResourceInputStreamTest extends TestCase
{
- public function testNonStream() : void
+ public function testNonStream(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected a valid stream');
new ResourceInputStream(42);
}
- public function testNotReadable() : void
+ public function testNotReadable(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected a readable stream');
new ResourceInputStream(\STDOUT);
}
- public function testRead() : void
+ public function testRead(): void
{
$stream = fopen('php://memory', 'r+');
fwrite($stream, '1234');
diff --git a/test/IO/ResourceOutputStreamTest.php b/test/IO/ResourceOutputStreamTest.php
index a0c590c..7a61772 100644
--- a/test/IO/ResourceOutputStreamTest.php
+++ b/test/IO/ResourceOutputStreamTest.php
@@ -10,21 +10,21 @@
*/
class ResourceOutputStreamTest extends TestCase
{
- public function testNonStream() : void
+ public function testNonStream(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected a valid stream');
new ResourceOutputStream(42);
}
- public function testNotWritable() : void
+ public function testNotWritable(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected a writable stream');
new ResourceOutputStream(\STDIN);
}
- public function testWrite() : void
+ public function testWrite(): void
{
$stream = fopen('php://memory', 'r+');
$outputStream = new ResourceOutputStream($stream);
diff --git a/test/InputCharacterTest.php b/test/InputCharacterTest.php
index 0adabd5..1b01981 100644
--- a/test/InputCharacterTest.php
+++ b/test/InputCharacterTest.php
@@ -10,7 +10,7 @@
*/
class InputCharacterTest extends TestCase
{
- public function testWhenCharacterIsAControl() : void
+ public function testWhenCharacterIsAControl(): void
{
$char = new InputCharacter("\n");
@@ -22,7 +22,7 @@ public function testWhenCharacterIsAControl() : void
self::assertEquals("\n", $char->__toString());
}
- public function testWhenCharacterIsNotAControl() : void
+ public function testWhenCharacterIsNotAControl(): void
{
$char = new InputCharacter('p');
@@ -33,7 +33,7 @@ public function testWhenCharacterIsNotAControl() : void
self::assertEquals('p', $char->__toString());
}
- public function testExceptionIsThrownIfGetControlCalledWhenNotAControl() : void
+ public function testExceptionIsThrownIfGetControlCalledWhenNotAControl(): void
{
self::expectException(\RuntimeException::class);
self::expectExceptionMessage('Character "p" is not a control');
@@ -42,7 +42,7 @@ public function testExceptionIsThrownIfGetControlCalledWhenNotAControl() : void
$char->getControl();
}
- public function testGetControls() : void
+ public function testGetControls(): void
{
self::assertEquals(
[
@@ -64,7 +64,7 @@ public function testGetControls() : void
);
}
- public function testFromControlNameThrowsExceptionIfControlDoesNotExist() : void
+ public function testFromControlNameThrowsExceptionIfControlDoesNotExist(): void
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('Control "w" does not exist');
@@ -72,7 +72,7 @@ public function testFromControlNameThrowsExceptionIfControlDoesNotExist() : void
InputCharacter::fromControlName('w');
}
- public function testFromControlName() : void
+ public function testFromControlName(): void
{
$char = InputCharacter::fromControlName(InputCharacter::UP);
@@ -81,13 +81,13 @@ public function testFromControlName() : void
self::assertEquals("\033[A", $char->get());
}
- public function testControlExists() : void
+ public function testControlExists(): void
{
self::assertTrue(InputCharacter::controlExists(InputCharacter::UP));
self::assertFalse(InputCharacter::controlExists('w'));
}
- public function testIsControlOnNotExplicitlyHandledControls() : void
+ public function testIsControlOnNotExplicitlyHandledControls(): void
{
$char = new InputCharacter("\016"); //ctrl + p (I think)
@@ -100,7 +100,7 @@ public function testIsControlOnNotExplicitlyHandledControls() : void
self::assertFalse($char->isHandledControl());
}
- public function testUnicodeCharacter() : void
+ public function testUnicodeCharacter(): void
{
$char = new InputCharacter('ß');
diff --git a/test/NonCanonicalReaderTest.php b/test/NonCanonicalReaderTest.php
index f4fa91d..a77f507 100644
--- a/test/NonCanonicalReaderTest.php
+++ b/test/NonCanonicalReaderTest.php
@@ -12,7 +12,7 @@
*/
class NonCanonicalReaderTest extends TestCase
{
- public function testExceptionIsThrownIfMappingAddedForNonControlCharacter() : void
+ public function testExceptionIsThrownIfMappingAddedForNonControlCharacter(): void
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('Control "w" does not exist');
@@ -22,7 +22,7 @@ public function testExceptionIsThrownIfMappingAddedForNonControlCharacter() : vo
$terminalReader->addControlMapping('p', 'w');
}
- public function testExceptionIsThrownIfMappingsAddedForNonControlCharacter() : void
+ public function testExceptionIsThrownIfMappingsAddedForNonControlCharacter(): void
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('Control "w" does not exist');
@@ -32,7 +32,7 @@ public function testExceptionIsThrownIfMappingsAddedForNonControlCharacter() : v
$terminalReader->addControlMappings(['p' => 'w']);
}
- public function testCustomMappingToUpControl() : void
+ public function testCustomMappingToUpControl(): void
{
$terminal = $this->createMock(Terminal::class);
$terminal
@@ -51,7 +51,7 @@ public function testCustomMappingToUpControl() : void
self::assertEquals("\033[A", $char->get());
}
- public function testReadNormalCharacter() : void
+ public function testReadNormalCharacter(): void
{
$terminal = $this->createMock(Terminal::class);
$terminal
diff --git a/test/UnixTerminalTest.php b/test/UnixTerminalTest.php
index 7302da6..4a8916d 100644
--- a/test/UnixTerminalTest.php
+++ b/test/UnixTerminalTest.php
@@ -13,7 +13,7 @@
class UnixTerminalTest extends TestCase
{
- public function testIsInteractiveReturnsTrueIfInputAndOutputAreTTYs() : void
+ public function testIsInteractiveReturnsTrueIfInputAndOutputAreTTYs(): void
{
$input = $this->createMock(InputStream::class);
$output = $this->createMock(OutputStream::class);
@@ -32,7 +32,7 @@ public function testIsInteractiveReturnsTrueIfInputAndOutputAreTTYs() : void
self::assertTrue($terminal->isInteractive());
}
- public function testIsInteractiveReturnsFalseIfInputNotTTY() : void
+ public function testIsInteractiveReturnsFalseIfInputNotTTY(): void
{
$input = $this->createMock(InputStream::class);
$output = $this->createMock(OutputStream::class);
@@ -51,7 +51,7 @@ public function testIsInteractiveReturnsFalseIfInputNotTTY() : void
self::assertFalse($terminal->isInteractive());
}
- public function testIsInteractiveReturnsFalseIfOutputNotTTY() : void
+ public function testIsInteractiveReturnsFalseIfOutputNotTTY(): void
{
$input = $this->createMock(InputStream::class);
$output = $this->createMock(OutputStream::class);
@@ -70,7 +70,7 @@ public function testIsInteractiveReturnsFalseIfOutputNotTTY() : void
self::assertFalse($terminal->isInteractive());
}
- public function testIsInteractiveReturnsFalseIfInputAndOutputNotTTYs() : void
+ public function testIsInteractiveReturnsFalseIfInputAndOutputNotTTYs(): void
{
$input = $this->createMock(InputStream::class);
$output = $this->createMock(OutputStream::class);
@@ -89,7 +89,7 @@ public function testIsInteractiveReturnsFalseIfInputAndOutputNotTTYs() : void
self::assertFalse($terminal->isInteractive());
}
- public function testMustBeInteractiveThrowsExceptionIfInputNotTTY() : void
+ public function testMustBeInteractiveThrowsExceptionIfInputNotTTY(): void
{
self::expectException(NotInteractiveTerminal::class);
self::expectExceptionMessage('Input stream is not interactive (non TTY)');
@@ -106,7 +106,7 @@ public function testMustBeInteractiveThrowsExceptionIfInputNotTTY() : void
$terminal->mustBeInteractive();
}
- public function testMustBeInteractiveThrowsExceptionIfOutputNotTTY() : void
+ public function testMustBeInteractiveThrowsExceptionIfOutputNotTTY(): void
{
self::expectException(NotInteractiveTerminal::class);
self::expectExceptionMessage('Output stream is not interactive (non TTY)');
@@ -128,10 +128,10 @@ public function testMustBeInteractiveThrowsExceptionIfOutputNotTTY() : void
$terminal->mustBeInteractive();
}
- public function testClear() : void
+ public function testClear(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->clear();
@@ -139,10 +139,10 @@ public function testClear() : void
self::assertEquals("\033[2J", $output->fetch());
}
- public function testClearLine() : void
+ public function testClearLine(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->clearLine();
@@ -150,10 +150,10 @@ public function testClearLine() : void
self::assertEquals("\033[2K", $output->fetch());
}
- public function testClearDown() : void
+ public function testClearDown(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->clearDown();
@@ -161,18 +161,16 @@ public function testClearDown() : void
self::assertEquals("\033[J", $output->fetch());
}
- public function testClean() : void
+ public function testClean(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$rf = new \ReflectionObject($terminal);
$rp = $rf->getProperty('width');
- $rp->setAccessible(true);
$rp->setValue($terminal, 23);
$rp = $rf->getProperty('height');
- $rp->setAccessible(true);
$rp->setValue($terminal, 2);
$terminal->clean();
@@ -180,10 +178,10 @@ public function testClean() : void
self::assertEquals("\033[0;0H\033[2K\033[1;0H\033[2K\033[2;0H\033[2K", $output->fetch());
}
- public function testEnableCursor() : void
+ public function testEnableCursor(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->enableCursor();
@@ -191,10 +189,10 @@ public function testEnableCursor() : void
self::assertEquals("\033[?25h", $output->fetch());
}
- public function testDisableCursor() : void
+ public function testDisableCursor(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->disableCursor();
@@ -202,10 +200,10 @@ public function testDisableCursor() : void
self::assertEquals("\033[?25l", $output->fetch());
}
- public function testMoveCursorToTop() : void
+ public function testMoveCursorToTop(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->moveCursorToTop();
@@ -213,10 +211,10 @@ public function testMoveCursorToTop() : void
self::assertEquals("\033[H", $output->fetch());
}
- public function testMoveCursorToRow() : void
+ public function testMoveCursorToRow(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->moveCursorToRow(2);
@@ -224,10 +222,10 @@ public function testMoveCursorToRow() : void
self::assertEquals("\033[2;0H", $output->fetch());
}
- public function testMoveCursorToColumn() : void
+ public function testMoveCursorToColumn(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->moveCursorToColumn(10);
@@ -235,10 +233,10 @@ public function testMoveCursorToColumn() : void
self::assertEquals("\033[10C", $output->fetch());
}
- public function testShowAlternateScreen() : void
+ public function testShowAlternateScreen(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->showSecondaryScreen();
@@ -246,10 +244,10 @@ public function testShowAlternateScreen() : void
self::assertEquals("\033[?47h", $output->fetch());
}
- public function testShowMainScreen() : void
+ public function testShowMainScreen(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->showPrimaryScreen();
@@ -257,7 +255,7 @@ public function testShowMainScreen() : void
self::assertEquals("\033[?47l", $output->fetch());
}
- public function testRead() : void
+ public function testRead(): void
{
$tempStream = fopen('php://temp', 'r+');
fwrite($tempStream, 'mystring');
@@ -274,10 +272,10 @@ public function testRead() : void
fclose($tempStream);
}
- public function testWriteForwardsToOutput() : void
+ public function testWriteForwardsToOutput(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);
$terminal->write('My awesome string');
@@ -285,10 +283,10 @@ public function testWriteForwardsToOutput() : void
self::assertEquals('My awesome string', $output->fetch());
}
- public function testGetColourSupport() : void
+ public function testGetColourSupport(): void
{
$input = $this->createMock(InputStream::class);
- $output = new BufferedOutput;
+ $output = new BufferedOutput();
$terminal = new UnixTerminal($input, $output);