MyController::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * DronePHP (http://www.dronephp.com)
4
 *
5
 * @link      http://github.com/Pleets/DronePHP
6
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
7
 * @license   http://www.dronephp.com/license
8
 * @author    Darío Rivera <[email protected]>
9
 */
10
11
namespace DroneTest\Util;
12
13
use Drone\Util\ParamTrait;
14
use PHPUnit\Framework\TestCase;
15
16
class ParamTraitTest extends TestCase
17
{
18
    /**
19
     * Tests cheking and accessing to individual params
20
     *
21
     * @return null
22
     */
23
    public function testGettingIndividualParams()
24
    {
25
        $ctrl = new MyController();
26
        $ctrl->init([
27
            "user" => "fermius",
28
            "date" => new \DateTime("now"),
29
        ]);
30
31
        $this->assertTrue($ctrl->isParam('date'));
32
        $this->assertEquals('fermius', $ctrl->getParam('user'));
33
34
        # alias
35
        $this->assertEquals('fermius', $ctrl->param('user'));
36
    }
37
38
    /**
39
     * Tests cheking and accessing to all params
40
     *
41
     * @return null
42
     */
43
    public function testGettingAllParams()
44
    {
45
        $ctrl = new MyController();
46
47
        $params = [
48
            "user" => "fermius",
49
            "age"  => 26,
50
        ];
51
52
        $ctrl->init($params);
53
54
        $this->assertSame(["user" => "fermius", "age" => 26], $params);
55
    }
56
}
57
58
class MyController
59
{
60
    use ParamTrait;
61
62
    public function init($params)
63
    {
64
        $this->setParams($params);
65
    }
66
}
67