diff --git a/.gitattributes b/.gitattributes index aa522ca..b640645 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,4 @@ .gitignore export-ignore .travis.yml export-ignore build.xml export-ignore -phpunit.xml export-ignore +phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 05ab16b..50f8d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build vendor composer.lock +phpunit.xml diff --git a/.travis.yml b/.travis.yml index c775c11..56519fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,13 @@ cache: - $HOME/.composer/cache before_script: - - composer install --no-interaction --prefer-source + - | + if [[ $TRAVIS_PHP_VERSION != "nightly" ]]; then + composer install --no-suggest --no-interaction + else + # Ignore platform requirements to allow PHPUnit to install on PHP 8. + composer install --no-suggest --no-interaction --ignore-platform-reqs + fi script: - ant phplint diff --git a/build.xml b/build.xml index 6db22b7..9d95c2e 100644 --- a/build.xml +++ b/build.xml @@ -64,8 +64,8 @@ - - + + @@ -78,8 +78,8 @@ - - + + diff --git a/composer.json b/composer.json index b65462c..94aba0f 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.3", + "phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0", "php-parallel-lint/php-parallel-lint": "^1.0", "php-parallel-lint/php-var-dump-check": "0.*", "squizlabs/php_codesniffer": "1.*", diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 54% rename from phpunit.xml rename to phpunit.xml.dist index f1105cc..c694fb2 100644 --- a/phpunit.xml +++ b/phpunit.xml.dist @@ -1,16 +1,17 @@ + - + tests - - - vendor - + + src + diff --git a/tests/ConsoleColorTest.php b/tests/ConsoleColorTest.php index aaa1a22..f9a5398 100644 --- a/tests/ConsoleColorTest.php +++ b/tests/ConsoleColorTest.php @@ -1,5 +1,6 @@ uut->apply('none', 'text'); - $this->assertEquals("text", $output); + $this->assertSame("text", $output); } public function testBold() { $output = $this->uut->apply('bold', 'text'); - $this->assertEquals("\033[1mtext\033[0m", $output); + $this->assertSame("\033[1mtext\033[0m", $output); } public function testBoldColorsAreNotSupported() @@ -55,7 +56,7 @@ public function testBoldColorsAreNotSupported() $this->uut->setIsSupported(false); $output = $this->uut->apply('bold', 'text'); - $this->assertEquals("text", $output); + $this->assertSame("text", $output); } public function testBoldColorsAreNotSupportedButAreForced() @@ -64,25 +65,25 @@ public function testBoldColorsAreNotSupportedButAreForced() $this->uut->setForceStyle(true); $output = $this->uut->apply('bold', 'text'); - $this->assertEquals("\033[1mtext\033[0m", $output); + $this->assertSame("\033[1mtext\033[0m", $output); } public function testDark() { $output = $this->uut->apply('dark', 'text'); - $this->assertEquals("\033[2mtext\033[0m", $output); + $this->assertSame("\033[2mtext\033[0m", $output); } public function testBoldAndDark() { $output = $this->uut->apply(array('bold', 'dark'), 'text'); - $this->assertEquals("\033[1;2mtext\033[0m", $output); + $this->assertSame("\033[1;2mtext\033[0m", $output); } public function test256ColorForeground() { $output = $this->uut->apply('color_255', 'text'); - $this->assertEquals("\033[38;5;255mtext\033[0m", $output); + $this->assertSame("\033[38;5;255mtext\033[0m", $output); } public function test256ColorWithoutSupport() @@ -90,47 +91,47 @@ public function test256ColorWithoutSupport() $this->uut->setAre256ColorsSupported(false); $output = $this->uut->apply('color_255', 'text'); - $this->assertEquals("text", $output); + $this->assertSame("text", $output); } public function test256ColorBackground() { $output = $this->uut->apply('bg_color_255', 'text'); - $this->assertEquals("\033[48;5;255mtext\033[0m", $output); + $this->assertSame("\033[48;5;255mtext\033[0m", $output); } public function test256ColorForegroundAndBackground() { $output = $this->uut->apply(array('color_200', 'bg_color_255'), 'text'); - $this->assertEquals("\033[38;5;200;48;5;255mtext\033[0m", $output); + $this->assertSame("\033[38;5;200;48;5;255mtext\033[0m", $output); } public function testSetOwnTheme() { $this->uut->setThemes(array('bold_dark' => array('bold', 'dark'))); $output = $this->uut->apply(array('bold_dark'), 'text'); - $this->assertEquals("\033[1;2mtext\033[0m", $output); + $this->assertSame("\033[1;2mtext\033[0m", $output); } public function testAddOwnTheme() { $this->uut->addTheme('bold_own', 'bold'); $output = $this->uut->apply(array('bold_own'), 'text'); - $this->assertEquals("\033[1mtext\033[0m", $output); + $this->assertSame("\033[1mtext\033[0m", $output); } public function testAddOwnThemeArray() { $this->uut->addTheme('bold_dark', array('bold', 'dark')); $output = $this->uut->apply(array('bold_dark'), 'text'); - $this->assertEquals("\033[1;2mtext\033[0m", $output); + $this->assertSame("\033[1;2mtext\033[0m", $output); } public function testOwnWithStyle() { $this->uut->addTheme('bold_dark', array('bold', 'dark')); $output = $this->uut->apply(array('bold_dark', 'italic'), 'text'); - $this->assertEquals("\033[1;2;3mtext\033[0m", $output); + $this->assertSame("\033[1;2;3mtext\033[0m", $output); } public function testHasAndRemoveTheme() @@ -146,25 +147,25 @@ public function testHasAndRemoveTheme() public function testApplyInvalidArgument() { - $this->setExpectedException('\InvalidArgumentException'); + $this->exceptionHelper('\InvalidArgumentException'); $this->uut->apply(new stdClass(), 'text'); } public function testApplyInvalidStyleName() { - $this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); + $this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); $this->uut->apply('invalid', 'text'); } public function testApplyInvalid256Color() { - $this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); + $this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); $this->uut->apply('color_2134', 'text'); } public function testThemeInvalidStyle() { - $this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); + $this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException'); $this->uut->addTheme('invalid', array('invalid')); } @@ -180,5 +181,23 @@ public function testGetPossibleStyles() $this->assertInternalType('array', $this->uut->getPossibleStyles()); $this->assertNotEmpty($this->uut->getPossibleStyles()); } + + public function exceptionHelper($exception, $msg = null) + { + if (\method_exists($this, 'expectException')) { + // PHPUnit 5+. + $this->expectException($exception); + if (isset($msg)) { + $this->expectExceptionMessage($msg); + } + } else { + // PHPUnit 4. + if (isset($msg)) { + $this->setExpectedException($exception, $msg); + } else { + $this->setExpectedException($exception); + } + } + } }