1
1
<?php
2
2
use JakubOnderka \PhpConsoleColor \ConsoleColor ;
3
+ use PHPUnit \Framework \TestCase ;
3
4
4
5
class ConsoleColorWithForceSupport extends ConsoleColor
5
6
{
@@ -28,7 +29,7 @@ public function are256ColorsSupported()
28
29
}
29
30
}
30
31
31
- class ConsoleColorTest extends \PHPUnit_Framework_TestCase
32
+ class ConsoleColorTest extends TestCase
32
33
{
33
34
/** @var ConsoleColorWithForceSupport */
34
35
private $ uut ;
@@ -146,25 +147,25 @@ public function testHasAndRemoveTheme()
146
147
147
148
public function testApplyInvalidArgument ()
148
149
{
149
- $ this ->setExpectedException ('\InvalidArgumentException ' );
150
+ $ this ->exceptionHelper ('\InvalidArgumentException ' );
150
151
$ this ->uut ->apply (new stdClass (), 'text ' );
151
152
}
152
153
153
154
public function testApplyInvalidStyleName ()
154
155
{
155
- $ this ->setExpectedException ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
156
+ $ this ->exceptionHelper ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
156
157
$ this ->uut ->apply ('invalid ' , 'text ' );
157
158
}
158
159
159
160
public function testApplyInvalid256Color ()
160
161
{
161
- $ this ->setExpectedException ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
162
+ $ this ->exceptionHelper ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
162
163
$ this ->uut ->apply ('color_2134 ' , 'text ' );
163
164
}
164
165
165
166
public function testThemeInvalidStyle ()
166
167
{
167
- $ this ->setExpectedException ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
168
+ $ this ->exceptionHelper ('\JakubOnderka\PhpConsoleColor\InvalidStyleException ' );
168
169
$ this ->uut ->addTheme ('invalid ' , array ('invalid ' ));
169
170
}
170
171
@@ -180,5 +181,23 @@ public function testGetPossibleStyles()
180
181
$ this ->assertInternalType ('array ' , $ this ->uut ->getPossibleStyles ());
181
182
$ this ->assertNotEmpty ($ this ->uut ->getPossibleStyles ());
182
183
}
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
+ }
183
202
}
184
203
0 commit comments