1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Assert\Tests; |
4
|
|
|
|
5
|
|
|
use Assert\LazyAssertionException; |
6
|
|
|
|
7
|
|
|
class LazyAssertionTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @test |
11
|
|
|
*/ |
12
|
|
|
public function it_collects_errors_until_assertall() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$this->setExpectedException('Assert\LazyAssertionException', <<<EXC |
15
|
|
|
The following 3 assertions failed: |
16
|
|
|
1) foo: Value "10" expected to be string, type integer given. |
17
|
|
|
2) bar: Value "<NULL>" is empty, but non empty value was expected. |
18
|
|
|
3) baz: Value "string" is not an array. |
19
|
|
|
EXC |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
\Assert\lazy() |
23
|
|
|
->that(10, 'foo')->string() |
24
|
|
|
->that(null, 'bar')->notEmpty() |
25
|
|
|
->that('string', 'baz')->isArray() |
26
|
|
|
->verifyNow(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
*/ |
32
|
|
|
public function it_skips_assertions_of_current_chain_after_failure() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->setExpectedException('Assert\LazyAssertionException', <<<EXC |
35
|
|
|
The following 1 assertions failed: |
36
|
|
|
1) foo: Value "<NULL>" is empty, but non empty value was expected. |
37
|
|
|
EXC |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
\Assert\lazy() |
41
|
|
|
->that(null, 'foo')->notEmpty()->string() |
42
|
|
|
->verifyNow(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testLazyAssertionExceptionCanReturnAllErrors() |
46
|
|
|
{ |
47
|
|
|
try { |
48
|
|
|
\Assert\lazy() |
49
|
|
|
->that(10, 'foo')->string() |
50
|
|
|
->that(null, 'bar')->notEmpty() |
51
|
|
|
->that('string', 'baz')->isArray() |
52
|
|
|
->verifyNow(); |
53
|
|
|
} catch (LazyAssertionException $ex) { |
54
|
|
|
self::assertEquals(array( |
55
|
|
|
'Value "10" expected to be string, type integer given.', |
56
|
|
|
'Value "<NULL>" is empty, but non empty value was expected.', |
57
|
|
|
'Value "string" is not an array.', |
58
|
|
|
), array_map(function (\Exception $ex) { |
59
|
|
|
return $ex->getMessage(); |
60
|
|
|
}, $ex->getErrorExceptions())); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|