MethodTests::testApply()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Selector\Tests\Units;
11
12
/**
13
 * MethodTests class.
14
 *
15
 * @author Ivannis Suárez Jerez <[email protected]>
16
 */
17
class MethodTests extends FieldTestCase
18
{
19
    /**
20
     * @return bool
21
     */
22
    public function methodTrue()
23
    {
24
        return true;
25
    }
26
27
    /**
28
     * @return bool
29
     */
30
    public function methodFalse()
31
    {
32
        return false;
33
    }
34
35
    /**
36
     * @param number $arg1
37
     * @param number $arg2
38
     *
39
     * @return number
40
     */
41
    public function methodWithArgs($arg1, $arg2)
42
    {
43
        return $arg1 + $arg2;
44
    }
45
46
    protected function privateMethod()
47
    {
48
    }
49
50
    /**
51
     * Test apply.
52
     */
53
    public function testApply()
54
    {
55
        $this
56
            ->given($method = $this->newTestedInstance('name'))
57
            ->then()
58
                ->string($method->apply($method))
59
                    ->isEqualTo('name')
60
        ;
61
62
        $this
63
            ->given($method = $this->newTestedInstance('methodWithArgs'))
64
            ->then()
65
                ->integer($method->with(1, 2)->apply($this))
66
                    ->isEqualTo(3)
67
        ;
68
69
        $this
70
            ->given($method = $this->newTestedInstance('foo'))
71
            ->then()
72
                ->exception(function () use ($method) {
73
                    $method->apply(null);
74
                })->isInstanceOf(\RuntimeException::class)
75
                ->exception(function () use ($method) {
76
                    $method->apply($this);
77
                })->isInstanceOf(\RuntimeException::class)
78
        ;
79
80
        $this
81
            ->given($method = $this->newTestedInstance('privateMethod'))
82
            ->then()
83
                ->exception(function () use ($method) {
84
                    $method->apply($this);
85
                })->isInstanceOf(\RuntimeException::class)
86
        ;
87
    }
88
}
89