Completed
Push — master ( ed2248...76a385 )
by joanhey
05:39
created

KumbiaTestTrait::request()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 3
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia Tests
16
 * @copyright  Copyright (c) 2005 - 2018 Kumbia Team (http://www.kumbiaphp.com)
17
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
18
 */
19
20
21
trait KumbiaTestTrait
22
{
23
    /**
24
     * Asserts HTTP response code
25
     *
26
     * @param int $code
27
     */
28
    public function assertResponseCode($code)
29
    {
30
        $actual = http_response_code();
31
        $this->assertSame(
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
            $code,
33
            $actual,
34
            "Status code is not $code but $actual."
35
        );
36
    }
37
    /**
38
     * Request to Controller
39
     *
40
     * @param string       $method      HTTP method
41
     * @param string       $url         controller/method/arg|uri
42
     * @param array        $params      POST parameters/Query string
43
     */
44
    protected function request($method, $url, $params = [])
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        $_SERVER['REQUEST_METHOD'] = $method;
47
        
48
        ob_start();
49
        $start_ob_level = ob_get_level();
50
        ob_start();
51
        View::render(Router::execute($url));
52
        while (ob_get_level() > $start_ob_level) {
53
            ob_end_flush();
54
        }
55
56
        //$content = $this->getActualOutput();
57
        return ob_get_clean();
58
    }
59
    /**
60
     * GET Request to Controller
61
     *
62
     * @param string       $url         controller/method/arg|uri
63
     * @param array        $params      Query string
64
     */
65
    public function get($url, $params = [])
66
    {
67
        return $this->request('GET', $url, $params);
68
    }
69
}
70