Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 722309d

Browse files
committed
Adds unit tests for GetCompatibleExceptionName class.
1 parent d0f37fe commit 722309d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Potherca\PhpUnit\Shim;
4+
5+
class GetCompatibleExceptionNameTest extends AbstractTraitShimTest
6+
{
7+
////////////////////////////////// FIXTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
8+
9+
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
10+
11+
/** @noinspection PhpDocMissingThrowsInspection
12+
*
13+
* @dataProvider provideExpectedExceptions
14+
*
15+
* @param string $exceptionName
16+
* @param string|array $expected
17+
*/
18+
final public function testShimShouldGetCompatibleExceptionNameWhenGivenExceptionName($exceptionName, $expected)
19+
{
20+
if (is_array($expected) === true) {
21+
/* Grab version specific value */
22+
$key = PHP_MAJOR_VERSION;
23+
if (array_key_exists(PHP_MAJOR_VERSION . PHP_MINOR_VERSION, $expected) === true) {
24+
$key = PHP_MAJOR_VERSION . PHP_MINOR_VERSION;
25+
}
26+
$expected = $expected[$key];
27+
}
28+
29+
if (class_exists($expected) === false) {
30+
$expected = str_replace('_', '\\', $expected);
31+
}
32+
33+
$mockTestCase = $this->getMockTestCase();
34+
35+
$shim = new GetCompatibleExceptionName($mockTestCase);
36+
37+
/** @noinspection PhpUnhandledExceptionInspection */
38+
$actual = $shim->getCompatibleExceptionName($exceptionName);
39+
40+
$this->assertSame($expected, $actual);
41+
}
42+
43+
////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
44+
45+
/////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
46+
47+
public function provideExpectedExceptions()
48+
{
49+
return array(
50+
'ArgumentCountError' => array('\\ArgumentCountError', array(
51+
'5' => '\\PHPUnit_Framework_Error',
52+
'7' => '\\ArgumentCountError',
53+
'70' => '\\TypeError',
54+
)),
55+
'ArithmeticError' => array('\\ArithmeticError', array(
56+
'5' => '\\PHPUnit_Framework_Error',
57+
'7' => '\\ArithmeticError',
58+
)),
59+
'DivisionByZeroError' => array('\\DivisionByZeroError', '\\PHPUnit_Framework_Error_Warning'),
60+
'Exception' => array('\\Exception', '\\Exception'),
61+
);
62+
}
63+
64+
}
65+
/*EOF*/

0 commit comments

Comments
 (0)