1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Assert |
5
|
|
|
* |
6
|
|
|
* LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this package in the file LICENSE.txt. |
10
|
|
|
* If you did not receive a copy of the license and are unable to |
11
|
|
|
* obtain it through the world-wide-web, please send an email |
12
|
|
|
* to [email protected] so I can send you a copy immediately. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Assert\Tests; |
16
|
|
|
|
17
|
|
|
use Assert\Assertion; |
18
|
|
|
use Assert\AssertionFailedException; |
19
|
|
|
|
20
|
|
|
class AssertionExceptionCallbackTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
public function testMessageUsingCallbackForString() |
23
|
|
|
{ |
24
|
|
|
$this->setExpectedException(AssertionFailedException::class, 'The assertion Assert\Assertion::string() failed for 3.1415926535898'); |
25
|
|
|
Assertion::string( |
26
|
|
|
M_PI, |
27
|
|
|
function (array $parameters) { |
28
|
|
|
return sprintf( |
29
|
|
|
'The assertion %s() failed for %s', |
30
|
|
|
$parameters['::assertion'], |
31
|
|
|
$parameters['value'] |
32
|
|
|
); |
33
|
|
|
}, |
34
|
|
|
'M_PI' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testMessageUsingCallbackForRegexFailingAtTheStringAssertion() |
39
|
|
|
{ |
40
|
|
|
$this->setExpectedException(AssertionFailedException::class, 'The assertion Assert\Assertion::string() failed for 3.1415926535898'); |
41
|
|
|
Assertion::regex( |
42
|
|
|
M_PI, |
43
|
|
|
'`[A-Z]++`', |
44
|
|
|
function (array $parameters) { |
45
|
|
|
return sprintf( |
46
|
|
|
'The assertion %s() failed for %s', |
47
|
|
|
$parameters['::assertion'], |
48
|
|
|
$parameters['value'] |
49
|
|
|
); |
50
|
|
|
}, |
51
|
|
|
'M_PI' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testMessageUsingCallbackForRegexFailingAtTheRegexAssertion() |
56
|
|
|
{ |
57
|
|
|
$this->setExpectedException(AssertionFailedException::class, 'The assertion Assert\Assertion::regex() failed for 3.1415926535898 against the pattern `^[0-9]++$`'); |
58
|
|
|
Assertion::regex( |
59
|
|
|
(string) M_PI, |
60
|
|
|
'`^[0-9]++$`', |
61
|
|
|
function (array $parameters) { |
62
|
|
|
return sprintf( |
63
|
|
|
'The assertion %s() failed for %s against the pattern %s', |
64
|
|
|
$parameters['::assertion'], |
65
|
|
|
$parameters['value'], |
66
|
|
|
$parameters['pattern'] |
67
|
|
|
); |
68
|
|
|
}, |
69
|
|
|
'M_PI' |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|