• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

krakjoe / uopz / 12858148161

19 Jan 2025 11:31PM UTC coverage: 95.502%. Remained the same
12858148161

push

github

web-flow
Fix CI regarding lcov 2.0 (#189)

Recently, ubuntu-latest has been upgraded to Ubuntu 24.04, and that
upgraded lcov from 1.15 to 2.0, which is apparently more picky regarding
exclude patterns.  We silence that for now; should probably have a look
why the exclude pattern is unused, though.

913 of 956 relevant lines covered (95.5%)

9207.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.12
/src/class.c
1
/*
2
  +----------------------------------------------------------------------+
3
  | uopz                                                                 |
4
  +----------------------------------------------------------------------+
5
  | Copyright (c) Joe Watkins 2016-2021                                  |
6
  +----------------------------------------------------------------------+
7
  | This source file is subject to version 3.01 of the PHP license,      |
8
  | that is bundled with this package in the file LICENSE, and is        |
9
  | available through the world-wide-web at the following url:           |
10
  | http://www.php.net/license/3_01.txt                                  |
11
  | If you did not receive a copy of the PHP license and are unable to   |
12
  | obtain it through the world-wide-web, please send a note to          |
13
  | license@php.net so we can mail you a copy immediately.               |
14
  +----------------------------------------------------------------------+
15
  | Author: Joe Watkins <krakjoe@php.net>                                |
16
  +----------------------------------------------------------------------+
17
 */
18

19
#ifndef UOPZ_CLASS
20
#define UOPZ_CLASS
21

22
#include "php.h"
23
#include "uopz.h"
24

25
#include "util.h"
26
#include "class.h"
27

28
ZEND_EXTERN_MODULE_GLOBALS(uopz);
29

30
#define uopz_get_scope(e) ((e) ? zend_get_executed_scope() : EG(fake_scope))
31
#define uopz_set_scope(s) EG(fake_scope) = (s)
32

33
void uopz_set_mock(zend_string *clazz, zval *mock) { /* {{{ */
160✔
34
        zend_string *key = zend_string_tolower(clazz);
160✔
35

36
        if (zend_hash_update(&UOPZ(mocks), key, mock)) {
160✔
37
                zval_copy_ctor(mock);
160✔
38
        }
39

40
        zend_string_release(key);
160✔
41
} /* }}} */
160✔
42

43
void uopz_unset_mock(zend_string *clazz) { /* {{{ */
64✔
44
        zend_string *key = zend_string_tolower(clazz);
64✔
45
        
46
        if (!zend_hash_exists(&UOPZ(mocks), key)) {
64✔
47
                uopz_exception(
16✔
48
                        "the class provided (%s) has no mock set",
49
                        ZSTR_VAL(clazz));
50
                zend_string_release(key);
16✔
51
                return;
16✔
52
        }
53

54
        zend_hash_del(&UOPZ(mocks), key);
48✔
55
        zend_string_release(key);
48✔
56
} /* }}} */
57

58
int uopz_get_mock(zend_string *clazz, zval *return_value) { /* {{{ */
64✔
59
        zval *mock = NULL;
64✔
60
        zend_string *key = zend_string_tolower(clazz);
64✔
61
        
62
        if (!(mock = zend_hash_find(&UOPZ(mocks), key))) {
64✔
63
                zend_string_release(key);
16✔
64
                return FAILURE;
16✔
65
        }
66

67
        ZVAL_COPY(return_value, mock);
48✔
68
        zend_string_release(key);
48✔
69

70
        return SUCCESS;
24✔
71
} /* }}} */
72

73
int uopz_find_mock(zend_string *clazz, zend_object **object, zend_class_entry **mock) { /* {{{ */
664✔
74
        zend_string *key = zend_string_tolower(clazz);
664✔
75
        zval *found = zend_hash_find(&UOPZ(mocks), key);
664✔
76

77
        zend_string_release(key);
664✔
78

79
        if (!found) {
664✔
80
                return FAILURE;
276✔
81
        }
82

83
        if (Z_TYPE_P(found) == IS_STRING) {
112✔
84
                *mock = zend_fetch_class_by_name(Z_STR_P(found), NULL, ZEND_FETCH_CLASS_EXCEPTION);
64✔
85
                return *mock ? SUCCESS : FAILURE;
64✔
86
        } else {
87
                *mock = Z_OBJCE_P(found);
48✔
88
                if (object) {
48✔
89
                        *object = Z_OBJ_P(found);
48✔
90
                }
91
                return SUCCESS;
48✔
92
        }
93
} /* }}} */
94

95
void uopz_set_property(zval *object, zend_string *member, zval *value) { /* {{{ */
64✔
96
        zend_class_entry *scope = uopz_get_scope(0);
64✔
97
        zend_class_entry *ce = Z_OBJCE_P(object);
64✔
98
        zend_property_info *info;
48✔
99

100
        do {
48✔
101
                uopz_set_scope(ce);
96✔
102

103
                info = zend_get_property_info(ce, member, 1);
96✔
104
        
105
                if (info && info != ZEND_WRONG_PROPERTY_INFO) {
96✔
106
                        break;
24✔
107
                }
108

109
                ce = ce->parent;
48✔
110
        } while (ce);
48✔
111

112
        if (info && info != ZEND_WRONG_PROPERTY_INFO) {
64✔
113
                uopz_set_scope(info->ce);
48✔
114
        } else {
115
                uopz_set_scope(Z_OBJCE_P(object));
16✔
116
        }
117

118
        Z_OBJ_HT_P(object)
64✔
119
                ->write_property(Z_OBJ_P(object), member, value, NULL);
64✔
120

121
        uopz_set_scope(scope);
64✔
122
} /* }}} */
64✔
123

124
void uopz_get_property(zval *object, zend_string *member, zval *value) { /* {{{ */
80✔
125
        zend_class_entry *scope = uopz_get_scope(0);
80✔
126
        zend_class_entry *ce = Z_OBJCE_P(object);
80✔
127
        zend_property_info *info;
64✔
128
        zval *prop, rv;
64✔
129

130
        do {
64✔
131
                uopz_set_scope(ce);
128✔
132

133
                info = zend_get_property_info(ce, member, 1);
128✔
134
        
135
                if (info && info != ZEND_WRONG_PROPERTY_INFO) {
128✔
136
                        break;
24✔
137
                }
138

139
                ce = ce->parent;
80✔
140
        } while (ce);
80✔
141

142
        if (info && info != ZEND_WRONG_PROPERTY_INFO) {
80✔
143
                uopz_set_scope(info->ce);
48✔
144
        } else {
145
                uopz_set_scope(Z_OBJCE_P(object));
32✔
146
        }
147

148
        prop = Z_OBJ_HT_P(object)->read_property(
80✔
149
                Z_OBJ_P(object), member, BP_VAR_R, NULL, &rv);
150

151
        uopz_set_scope(scope);
80✔
152

153
        ZVAL_COPY(value, prop);
80✔
154
} /* }}} */
80✔
155

156
void uopz_set_static_property(zend_class_entry *ce, zend_string *property, zval *value) { /* {{{ */
48✔
157
        zend_class_entry *scope = uopz_get_scope(0);
48✔
158
        zend_class_entry *seek = ce;
48✔
159
        zend_property_info *info;
32✔
160
        zval *prop;
32✔
161

162
        do {
32✔
163
                uopz_set_scope(seek);
64✔
164

165
                info = zend_get_property_info(seek, property, 1);
64✔
166
        
167
                if (info && info != ZEND_WRONG_PROPERTY_INFO) {
64✔
168
                        break;
16✔
169
                }
170

171
                seek = seek->parent;
32✔
172
        } while (seek);
32✔
173

174
        if (info && info != ZEND_WRONG_PROPERTY_INFO) {
48✔
175
                uopz_set_scope(info->ce);
32✔
176
        } else {
177
                uopz_set_scope(ce);
16✔
178
        }
179

180
        prop = zend_std_get_static_property(uopz_get_scope(0), property, 1);
48✔
181
        
182
        uopz_set_scope(scope);
48✔
183

184
        if (!prop) {
48✔
185
                uopz_exception(
16✔
186
                        "cannot set non-existent static property %s::%s", 
187
                        ZSTR_VAL(ce->name),
188
                        ZSTR_VAL(property));
189
                return;
16✔
190
        }
191

192
        zval_ptr_dtor(prop);
32✔
193
        ZVAL_COPY(prop, value);
32✔
194
} /* }}} */
195

196
void uopz_get_static_property(zend_class_entry *ce, zend_string *property, zval *value) { /* {{{ */
32✔
197
        zend_class_entry *scope = uopz_get_scope(0);
32✔
198
        zend_class_entry *seek = ce;
32✔
199
        zend_property_info *info;
24✔
200
        zval *prop;
24✔
201

202
        do {
24✔
203
                uopz_set_scope(seek);
48✔
204

205
                info = zend_get_property_info(seek, property, 1);
48✔
206
        
207
                if (info && info != ZEND_WRONG_PROPERTY_INFO) {
48✔
208
                        break;
16✔
209
                }
210

211
                seek = seek->parent;
16✔
212
        } while (seek);
16✔
213

214
        if (info && info != ZEND_WRONG_PROPERTY_INFO) {
32✔
215
                uopz_set_scope(info->ce);
32✔
216
        } else {
217
                uopz_set_scope(ce);
×
218
        }
219

220
        prop = zend_std_get_static_property(uopz_get_scope(0), property, 1);
32✔
221
        
222
        uopz_set_scope(scope);
32✔
223

224
        if (!prop) {
32✔
225
                return;
226
        }
227
        
228
        ZVAL_COPY(value, prop);
32✔
229
} /* }}} */
230

231
#endif        /* UOPZ_CLASS */
232

233
/*
234
 * Local variables:
235
 * tab-width: 4
236
 * c-basic-offset: 4
237
 * End:
238
 * vim600: noet sw=4 ts=4 fdm=marker
239
 * vim<600: noet sw=4 ts=4
240
 */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc