Completed
Push — master ( ef8414...a67d49 )
by Richard
10s
created

CustomAssertionClassTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 95
rs 10
c 3
b 0
f 0
wmc 7
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A it_uses_custom_exception_class() 0 5 1
A it_uses_custom_assertion_class_for_assertion_chains() 0 9 1
A it_uses_custom_exception_for_lazy_assertion_chains() 0 8 1
A it_uses_custom_exception_for_lazy_assertion_chains_when_first_assertion_does_not_fail() 0 9 1
A it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions_per_chain() 0 16 1
A it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions() 0 17 1
1
<?php
2
/**
3
 * Assert
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * If you did not receive a copy of the license and are unable to
10
 * obtain it through the world-wide-web, please send an email
11
 * to [email protected] so I can send you a copy immediately.
12
 */
13
14
namespace Assert\Tests;
15
16
use Assert\Assert;
17
use Assert\InvalidArgumentException;
18
19
class CustomAssertionClassTest extends \PHPUnit_Framework_TestCase
20
{
21
    protected function setUp()
22
    {
23
        CustomAssertion::clearCalls();
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function it_uses_custom_exception_class()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_class" is not in camel caps format
Loading history...
30
    {
31
        $this->setExpectedException('Assert\Tests\CustomException');
32
        CustomAssertion::integer('foo');
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function it_uses_custom_assertion_class_for_assertion_chains()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_assertion_class_for_assertion_chains" is not in camel caps format
Loading history...
39
    {
40
        $string = 's' . uniqid();
41
        CustomAssert::that($string)->string();
42
        $this->assertSame(array(array('string', $string)), CustomAssertion::getCalls());
43
44
        $this->setExpectedException('Assert\Tests\CustomException');
45
        CustomAssert::that($string)->integer();
46
    }
47
48
    /**
49
     * @test
50
     */
51
    public function it_uses_custom_exception_for_lazy_assertion_chains()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains" is not in camel caps format
Loading history...
52
    {
53
        $this->setExpectedException('Assert\Tests\CustomLazyAssertionException');
54
        CustomAssert::lazy()
55
            ->that('foo', 'foo')->integer()
56
            ->verifyNow()
57
        ;
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function it_uses_custom_exception_for_lazy_assertion_chains_when_first_assertion_does_not_fail()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains_when_first_assertion_does_not_fail" is not in camel caps format
Loading history...
64
    {
65
        $this->setExpectedException('Assert\Tests\CustomLazyAssertionException');
66
        CustomAssert::lazy()
67
            ->that('foo', 'foo')->string()
68
            ->that('bar', 'bar')->integer()
69
            ->verifyNow()
70
        ;
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions_per_chain()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions_per_chain" is not in camel caps format
Loading history...
77
    {
78
        $this->setExpectedException('Assert\Tests\CustomLazyAssertionException', <<< MESSAGE
79
The following 4 assertions failed:
80
1) foo: Value "foo" is not an integer.
81
2) foo: Value "foo" is not an array.
82
3) bar: Value "123" expected to be string, type integer given.
83
4) bar: Value "123" is not an array.
84
MESSAGE
85
);
86
        CustomAssert::lazy()
87
            ->that('foo', 'foo')->tryAll()->integer()->isArray()
88
            ->that(123, 'bar')->tryAll()->string()->isArray()
89
            ->verifyNow()
90
        ;
91
    }
92
93
    /**
94
     * @test
95
     */
96
    public function it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains_that_try_all_assertions" is not in camel caps format
Loading history...
97
    {
98
        $this->setExpectedException('Assert\Tests\CustomLazyAssertionException', <<< MESSAGE
99
The following 4 assertions failed:
100
1) foo: Value "foo" is not an integer.
101
2) foo: Value "foo" is not an array.
102
3) bar: Value "123" expected to be string, type integer given.
103
4) bar: Value "123" is not an array.
104
MESSAGE
105
);
106
        CustomAssert::lazy()
107
            ->tryAll()
108
            ->that('foo', 'foo')->integer()->isArray()
109
            ->that(123, 'bar')->string()->isArray()
110
            ->verifyNow()
111
        ;
112
    }
113
}
114
115
class CustomException extends InvalidArgumentException
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
116
{
117
}
118
119
class CustomAssert extends Assert
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
120
{
121
    protected static $assertionClass = 'Assert\Tests\CustomAssertion';
122
    protected static $lazyAssertionExceptionClass = 'Assert\Tests\CustomLazyAssertionException';
123
}
124