Completed
Pull Request — master (#169)
by Woody
02:45
created

AssertionChainTest::it_has_custom_shortcut()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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
class AssertionChainTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @test
20
     */
21
    public function it_chains_assertions()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_chains_assertions" is not in camel caps format
Loading history...
22
    {
23
        \Assert\that(10)->notEmpty()->integer();
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function it_shifts_arguments_to_assertions_by_one()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_shifts_arguments_to_assertions_by_one" is not in camel caps format
Loading history...
30
    {
31
        \Assert\that(10)->eq(10);
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function it_knowns_default_error_message()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_knowns_default_error_message" is not in camel caps format
Loading history...
38
    {
39
        $this->setExpectedException('Assert\InvalidArgumentException', 'Not Null and such');
40
41
        \Assert\that(null, 'Not Null and such')->notEmpty();
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function it_skips_assertions_on_valid_null()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_skips_assertions_on_valid_null" is not in camel caps format
Loading history...
48
    {
49
        \Assert\that(null)->nullOr()->integer()->eq(10);
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function it_validates_all_inputs()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_validates_all_inputs" is not in camel caps format
Loading history...
56
    {
57
        \Assert\that(array(1, 2, 3))->all()->integer();
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function it_has_thatall_shortcut()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_has_thatall_shortcut" is not in camel caps format
Loading history...
64
    {
65
        \Assert\ThatAll(array(1, 2, 3))->integer();
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function it_has_nullor_shortcut()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_has_nullor_shortcut" is not in camel caps format
Loading history...
72
    {
73
        \Assert\thatNullOr(null)->integer()->eq(10);
74
    }
75
76
    /**
77
     * @expectedException \RuntimeException
78
     * @expectedExceptionMessage Assertion 'unknownAssertion' does not exist.
79
     * @test
80
     */
81
    public function it_throws_exception_for_unknown_assertion()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_throws_exception_for_unknown_assertion" is not in camel caps format
Loading history...
82
    {
83
        \Assert\that(null)->unknownAssertion();
0 ignored issues
show
Documentation Bug introduced by
The method unknownAssertion does not exist on object<Assert\AssertionChain>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function it_has_custom_shortcut()
0 ignored issues
show
Coding Style introduced by
Method name "AssertionChainTest::it_has_custom_shortcut" is not in camel caps format
Loading history...
90
    {
91
        \Assert\that(null)->custom(function ($value) {
0 ignored issues
show
Documentation Bug introduced by
The method custom does not exist on object<Assert\AssertionChain>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92
            return is_null($value);
93
        });
94
    }
95
}
96