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
Bug
introduced
by
![]() |
|||
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 |