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( |
|
|
|
|
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 = []) |
|
|
|
|
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
|
|
|
|
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
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. 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.