Completed
Pull Request — master (#167)
by
unknown
02:30
created

testLazyAssertionExceptionIsAnAssertionException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
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()
0 ignored issues
show
Coding Style introduced by
Method name "LazyAssertionTest::it_collects_errors_until_assertall" is not in camel caps format
Loading history...
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
20
EXC
21
        );
22
23
        \Assert\lazy()
24
            ->that(10, 'foo')->string()
25
            ->that(null, 'bar')->notEmpty()
26
            ->that('string', 'baz')->isArray()
27
            ->verifyNow();
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function it_skips_assertions_of_current_chain_after_failure()
0 ignored issues
show
Coding Style introduced by
Method name "LazyAssertionTest::it_skips_assertions_of_current_chain_after_failure" is not in camel caps format
Loading history...
34
    {
35
        $this->setExpectedException('Assert\LazyAssertionException', <<<EXC
36
The following 1 assertions failed:
37
1) foo: Value "<NULL>" is empty, but non empty value was expected.
38
39
EXC
40
        );
41
42
        \Assert\lazy()
43
            ->that(null, 'foo')->notEmpty()->string()
44
            ->verifyNow();
45
    }
46
47
    public function testLazyAssertionExceptionCanReturnAllErrors()
48
    {
49
        try {
50
            \Assert\lazy()
51
                ->that(10, 'foo')->string()
52
                ->that(null, 'bar')->notEmpty()
53
                ->that('string', 'baz')->isArray()
54
                ->verifyNow();
55
        } catch (LazyAssertionException $ex) {
56
            self::assertEquals(array(
57
                'Value "10" expected to be string, type integer given.',
58
                'Value "<NULL>" is empty, but non empty value was expected.',
59
                'Value "string" is not an array.',
60
            ), array_map(function (\Exception $ex) {
61
                return $ex->getMessage();
62
            }, $ex->getErrorExceptions()));
63
        }
64
    }
65
66
    /**
67
     * @test
68
     * @expectedException Assert\AssertionException
69
     */
70
    public function testLazyAssertionExceptionIsAnAssertionException()
71
    {
72
        \Assert\lazy()
73
            ->that(10, 'foo')->string()
74
            ->that(null, 'bar')->notEmpty()
75
            ->that('string', 'baz')->isArray()
76
            ->verifyNow();
77
    }
78
}
79