-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPatching_on_method_test.php
87 lines (81 loc) · 1.97 KB
/
Patching_on_method_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @group patcher
*/
class Patching_on_method_test extends TestCase
{
public function test_index_return_is_array()
{
MonkeyPatch::patchMethod(
'Category_model',
['get_category_list' => [(object) ['name' => 'Nothing']]]
);
MonkeyPatch::verifyInvoked(
'Category_model::get_category_list'
);
MonkeyPatch::verifyNeverInvoked(
'Welcome::index'
);
$output = $this->request('GET', 'patching_on_method');
$this->assertStringContainsString('Nothing', $output);
}
public function test_index_return_is_clouser()
{
MonkeyPatch::patchMethod(
'Category_model',
['get_category_list' =>
function ($arg = null) {
return $arg === null ? [(object) ['name' => 'Nothing']]
: [(object) ['name' => 'Everything']];
}
]
);
MonkeyPatch::verifyInvokedOnce(
'Category_model::get_category_list'
);
$output = $this->request('GET', 'patching_on_method');
$this->assertStringContainsString('Nothing', $output);
}
public function test_index_return_null()
{
MonkeyPatch::patchMethod(
'Patching_on_method',
['index' => null]
);
MonkeyPatch::verifyInvokedOnce(
'Patching_on_method::index'
);
$output = $this->request('GET', 'patching_on_method');
$this->assertEquals('', $output);
}
public function test_auth()
{
MonkeyPatch::patchMethod(
'Ion_auth_model',
['login' => true]
);
MonkeyPatch::verifyInvoked(
'Ion_auth_model::login', ['foo', 'bar']
);
MonkeyPatch::verifyInvokedOnce(
'Ion_auth_model::login', ['foo', 'bar']
);
MonkeyPatch::verifyNeverInvoked(
'Ion_auth_model::login', ['username', 'PHS/DL1m6OMYg']
);
MonkeyPatch::verifyInvokedOnce(
'CI_Input::post', ['id']
);
MonkeyPatch::verifyInvokedOnce(
'CI_Input::post', ['password']
);
MonkeyPatch::verifyInvokedMultipleTimes(
'CI_Input::post', 2
);
$output = $this->request(
'POST', 'patching_on_method/auth',
['id' => 'foo', 'password' => 'bar']
);
$this->assertStringContainsString('Okay!', $output);
}
}