diff --git a/composer.json b/composer.json index cf77ef4..26ffde8 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": ">=5.3.2" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0", "php-parallel-lint/php-parallel-lint": "^1.0", "php-parallel-lint/php-var-dump-check": "0.*", "squizlabs/php_codesniffer": "3.*", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 27c3447..9671209 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,18 @@ @@ -18,9 +28,9 @@ - + diff --git a/src/ConsoleColor.php b/src/ConsoleColor.php index b7234ed..1f87326 100644 --- a/src/ConsoleColor.php +++ b/src/ConsoleColor.php @@ -196,6 +196,8 @@ public function removeTheme($name) } /** + * @codeCoverageIgnore + * * @return bool */ public function isSupported() @@ -213,6 +215,8 @@ public function isSupported() } /** + * @codeCoverageIgnore + * * @return bool */ public function are256ColorsSupported() diff --git a/tests/ConsoleColorTest.php b/tests/ConsoleColorTest.php index 1d2a520..8acfdff 100644 --- a/tests/ConsoleColorTest.php +++ b/tests/ConsoleColorTest.php @@ -5,6 +5,10 @@ use PHP_Parallel_Lint\PhpConsoleColor\Test\Fixtures\ConsoleColorWithForceSupport; use PHPUnit\Framework\TestCase; +/** + * @coversDefaultClass \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor + * @covers ::__construct + */ class ConsoleColorTest extends TestCase { /** @var ConsoleColorWithForceSupport */ @@ -18,18 +22,28 @@ protected function setUpConsoleColor() $this->uut = new ConsoleColorWithForceSupport(); } + /** + * @covers ::apply + */ public function testNone() { $output = $this->uut->apply('none', 'text'); $this->assertSame("text", $output); } + /** + * @covers ::apply + * @covers ::escSequence + */ public function testBold() { $output = $this->uut->apply('bold', 'text'); $this->assertSame("\033[1mtext\033[0m", $output); } + /** + * @covers ::apply + */ public function testBoldColorsAreNotSupported() { $this->uut->setIsSupported(false); @@ -38,6 +52,10 @@ public function testBoldColorsAreNotSupported() $this->assertSame("text", $output); } + /** + * @covers ::apply + * @covers ::setForceStyle + */ public function testBoldColorsAreNotSupportedButAreForced() { $this->uut->setIsSupported(false); @@ -47,24 +65,41 @@ public function testBoldColorsAreNotSupportedButAreForced() $this->assertSame("\033[1mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::escSequence + */ public function testDark() { $output = $this->uut->apply('dark', 'text'); $this->assertSame("\033[2mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::escSequence + */ public function testBoldAndDark() { $output = $this->uut->apply(array('bold', 'dark'), 'text'); $this->assertSame("\033[1;2mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::styleSequence + * @covers ::escSequence + */ public function test256ColorForeground() { $output = $this->uut->apply('color_255', 'text'); $this->assertSame("\033[38;5;255mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::styleSequence + */ public function test256ColorWithoutSupport() { $this->uut->setAre256ColorsSupported(false); @@ -73,18 +108,32 @@ public function test256ColorWithoutSupport() $this->assertSame("text", $output); } + /** + * @covers ::apply + * @covers ::styleSequence + * @covers ::escSequence + */ public function test256ColorBackground() { $output = $this->uut->apply('bg_color_255', 'text'); $this->assertSame("\033[48;5;255mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::styleSequence + * @covers ::escSequence + */ public function test256ColorForegroundAndBackground() { $output = $this->uut->apply(array('color_200', 'bg_color_255'), 'text'); $this->assertSame("\033[38;5;200;48;5;255mtext\033[0m", $output); } + /** + * @covers ::setThemes + * @covers ::themeSequence + */ public function testSetOwnTheme() { $this->uut->setThemes(array('bold_dark' => array('bold', 'dark'))); @@ -92,6 +141,10 @@ public function testSetOwnTheme() $this->assertSame("\033[1;2mtext\033[0m", $output); } + /** + * @covers ::addTheme + * @covers ::themeSequence + */ public function testAddOwnTheme() { $this->uut->addTheme('bold_own', 'bold'); @@ -99,6 +152,11 @@ public function testAddOwnTheme() $this->assertSame("\033[1mtext\033[0m", $output); } + /** + * @covers ::apply + * @covers ::addTheme + * @covers ::themeSequence + */ public function testAddOwnThemeArray() { $this->uut->addTheme('bold_dark', array('bold', 'dark')); @@ -106,6 +164,23 @@ public function testAddOwnThemeArray() $this->assertSame("\033[1;2mtext\033[0m", $output); } + /** + * @covers ::addTheme + */ + public function testAddOwnThemeInvalidInput() + { + $this->exceptionHelper('\InvalidArgumentException', 'Style must be string or array.'); + + $this->uut->addTheme('invalid', new \ArrayIterator(array('bold', 'dark'))); + } + + /** + * @covers ::apply + * @covers ::addTheme + * @covers ::themeSequence + * @covers ::styleSequence + * @covers ::isValidStyle + */ public function testOwnWithStyle() { $this->uut->addTheme('bold_dark', array('bold', 'dark')); @@ -113,6 +188,32 @@ public function testOwnWithStyle() $this->assertSame("\033[1;2;3mtext\033[0m", $output); } + /** + * @covers ::getThemes + */ + public function testGetThemes() + { + $this->assertSame(array(), $this->uut->getThemes()); + + $this->uut->addTheme('bold_dark', array('bold', 'dark')); + $this->uut->addTheme('dark_italic', array('dark', 'italic')); + + $themes = $this->uut->getThemes(); + if (\method_exists($this, 'assertIsArray')) { + // PHPUnit 7.5+. + $this->assertIsArray($themes); + } else { + // PHPUnit < 7.5. + $this->assertInternalType('array', $themes); + } + + $this->assertCount(2, $themes); + } + + /** + * @covers ::hasTheme + * @covers ::removeTheme + */ public function testHasAndRemoveTheme() { $this->assertFalse($this->uut->hasTheme('bold_dark')); @@ -124,30 +225,50 @@ public function testHasAndRemoveTheme() $this->assertFalse($this->uut->hasTheme('bold_dark')); } + /** + * @covers ::apply + */ public function testApplyInvalidArgument() { $this->exceptionHelper('\InvalidArgumentException'); $this->uut->apply(new \stdClass(), 'text'); } + /** + * @covers ::apply + * @covers \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException + */ public function testApplyInvalidStyleName() { $this->exceptionHelper('\PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException'); $this->uut->apply('invalid', 'text'); } + /** + * @covers ::apply + * @covers \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException + */ public function testApplyInvalid256Color() { $this->exceptionHelper('\PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException'); $this->uut->apply('color_2134', 'text'); } + /** + * @covers ::addTheme + * @covers ::isValidStyle + * @covers \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException + */ public function testThemeInvalidStyle() { $this->exceptionHelper('\PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException'); $this->uut->addTheme('invalid', array('invalid')); } + /** + * @covers ::setForceStyle + * @covers ::isStyleForced + */ public function testForceStyle() { $this->assertFalse($this->uut->isStyleForced()); @@ -155,6 +276,9 @@ public function testForceStyle() $this->assertTrue($this->uut->isStyleForced()); } + /** + * @covers ::getPossibleStyles + */ public function testGetPossibleStyles() { if (\method_exists($this, 'assertIsArray')) {