Issues (57)

default/app/tests/KumbiaTestTrait.php (1 issue)

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.
9
 *
10
 * @category   Kumbia Tests
11
 * @package    Core
12
 *
13
 * @copyright  Copyright (c) 2005 - 2023 KumbiaPHP Team (http://www.kumbiaphp.com)
14
 * @license    https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE   New BSD License
15
 */
16
17
18
trait KumbiaTestTrait
19
{
20
    /**
21
     * Asserts HTTP response code
22
     *
23
     * @param int $code
24
     */
25
    public function assertResponseCode($code)
26
    {
27
        $actual = http_response_code();
28
        $this->assertSame(
0 ignored issues
show
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->/** @scrutinizer ignore-call */ 
29
               assertSame(
Loading history...
29
            $code,
30
            $actual,
31
            "Status code is not $code but $actual."
32
        );
33
    }
34
    /**
35
     * Request to Controller
36
     *
37
     * @param string       $method      HTTP method
38
     * @param string       $url         controller/method/arg|uri
39
     * @param array        $params      POST parameters/Query string
40
     */
41
    protected function request($method, $url, $params = [])
42
    {
43
        $_SERVER['REQUEST_METHOD'] = $method;
44
        
45
        ob_start();
46
        $start_ob_level = ob_get_level();
47
        ob_start();
48
        View::render(Router::execute($url));
49
        while (ob_get_level() > $start_ob_level) {
50
            ob_end_flush();
51
        }
52
53
        //$content = $this->getActualOutput();
54
        return ob_get_clean();
55
    }
56
    /**
57
     * GET Request to Controller
58
     *
59
     * @param string       $url         controller/method/arg|uri
60
     * @param array        $params      Query string
61
     */
62
    public function get($url, $params = [])
63
    {
64
        return $this->request('GET', $url, $params);
65
    }
66
}
67