Completed
Push — extending_assert ( 3ffee9...7e0c63 )
by Richard
04:22
created

LazyAssertionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 57
rs 10
wmc 4
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_collects_errors_until_assertall() 0 16 1
A it_skips_assertions_of_current_chain_after_failure() 0 12 1
A testLazyAssertionExceptionCanReturnAllErrors() 0 18 2
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
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()
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...
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