1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Axstrad library. |
4
|
|
|
* |
5
|
|
|
* (c) Dan Kempster <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @copyright 2014-2015 Dan Kempster <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
namespace Axstrad\Common\Tests\Exception; |
13
|
|
|
|
14
|
|
|
use Axstrad\Common\Exception\InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Axstrad\Common\Tests\Exception\InvalidArgumentExceptionTest |
18
|
|
|
* |
19
|
|
|
* @group unittests |
20
|
|
|
* covers Axstrad\Common\Exception\InvalidArgumentException::create |
21
|
|
|
* @uses Axstrad\Common\Util\Debug |
22
|
|
|
* @uses Axstrad\Common\Util\ArrayUtil |
23
|
|
|
* @uses Axstrad\Common\Util\StrUtil |
24
|
|
|
*/ |
25
|
|
|
class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
protected $fixture; |
28
|
|
|
|
29
|
|
|
public function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->fixture = InvalidArgumentException::create('String', 2, 1, 999); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCreatesSelf() |
35
|
|
|
{ |
36
|
|
|
$this->assertInstanceOf( |
37
|
|
|
'Axstrad\Common\Exception\InvalidArgumentException', |
38
|
|
|
$this->fixture |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testExceptionMessageContainsExpected() |
43
|
|
|
{ |
44
|
|
|
$this->assertStringMatchesFormat( |
45
|
|
|
'%AString%A', |
46
|
|
|
$this->fixture->getMessage() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testExceptionMessageContainsActual() |
51
|
|
|
{ |
52
|
|
|
$this->assertStringMatchesFormat( |
53
|
|
|
'%A2%A', |
54
|
|
|
$this->fixture->getMessage() |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testExceptionMessageContainsParameterNumber() |
59
|
|
|
{ |
60
|
|
|
$this->assertStringMatchesFormat( |
61
|
|
|
'%A1%A', |
62
|
|
|
$this->fixture->getMessage() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testExceptionMessageIsPrefixedWithCode() |
67
|
|
|
{ |
68
|
|
|
$this->assertStringMatchesFormat( |
69
|
|
|
'[999]%A', |
70
|
|
|
$this->fixture->getMessage() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testExceptionCodeIsSet() |
75
|
|
|
{ |
76
|
|
|
$this->assertEquals( |
77
|
|
|
999, |
78
|
|
|
$this->fixture->getCode() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|