Skip to content

Commit 96fad8f

Browse files
jrfnlgrogy
authored andcommitted
PHPUnit: widen the version requirements
Made the unit tests compatible with PHPUnit 4.x - 7.x.
1 parent 13251d5 commit 96fad8f

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=5.4.0"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "~4.3",
17+
"phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0",
1818
"php-parallel-lint/php-parallel-lint": "^1.0",
1919
"php-parallel-lint/php-var-dump-check": "0.*",
2020
"squizlabs/php_codesniffer": "1.*",

tests/ConsoleColorTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
use JakubOnderka\PhpConsoleColor\ConsoleColor;
3+
use PHPUnit\Framework\TestCase;
34

45
class ConsoleColorWithForceSupport extends ConsoleColor
56
{
@@ -28,7 +29,7 @@ public function are256ColorsSupported()
2829
}
2930
}
3031

31-
class ConsoleColorTest extends \PHPUnit_Framework_TestCase
32+
class ConsoleColorTest extends TestCase
3233
{
3334
/** @var ConsoleColorWithForceSupport */
3435
private $uut;
@@ -146,25 +147,25 @@ public function testHasAndRemoveTheme()
146147

147148
public function testApplyInvalidArgument()
148149
{
149-
$this->setExpectedException('\InvalidArgumentException');
150+
$this->exceptionHelper('\InvalidArgumentException');
150151
$this->uut->apply(new stdClass(), 'text');
151152
}
152153

153154
public function testApplyInvalidStyleName()
154155
{
155-
$this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
156+
$this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
156157
$this->uut->apply('invalid', 'text');
157158
}
158159

159160
public function testApplyInvalid256Color()
160161
{
161-
$this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
162+
$this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
162163
$this->uut->apply('color_2134', 'text');
163164
}
164165

165166
public function testThemeInvalidStyle()
166167
{
167-
$this->setExpectedException('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
168+
$this->exceptionHelper('\JakubOnderka\PhpConsoleColor\InvalidStyleException');
168169
$this->uut->addTheme('invalid', array('invalid'));
169170
}
170171

@@ -180,5 +181,23 @@ public function testGetPossibleStyles()
180181
$this->assertInternalType('array', $this->uut->getPossibleStyles());
181182
$this->assertNotEmpty($this->uut->getPossibleStyles());
182183
}
184+
185+
public function exceptionHelper($exception, $msg = null)
186+
{
187+
if (\method_exists($this, 'expectException')) {
188+
// PHPUnit 5+.
189+
$this->expectException($exception);
190+
if (isset($msg)) {
191+
$this->expectExceptionMessage($msg);
192+
}
193+
} else {
194+
// PHPUnit 4.
195+
if (isset($msg)) {
196+
$this->setExpectedException($exception, $msg);
197+
} else {
198+
$this->setExpectedException($exception);
199+
}
200+
}
201+
}
183202
}
184203

0 commit comments

Comments
 (0)