Skip to content

Commit 877b4f0

Browse files
tests: ensure Models only use internal callables that exist #664
1 parent b2fa8ad commit 877b4f0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APICoreModelTestCase.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,4 +1248,23 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
12481248
$dhcp_server->staticmap->value = [];
12491249
$dhcp_server->update(apply: true);
12501250
}
1251+
1252+
/**
1253+
* Checks that all Model classes with an internal_callable assigned have an existing callable assigned.
1254+
*/
1255+
public function test_model_internal_callables_exist(): void {
1256+
# Loop through all Model classes
1257+
foreach (Model::get_all_model_classes() as $model_class) {
1258+
# Create a new instance of the Model class
1259+
$model_obj = new $model_class(skip_init: true);
1260+
1261+
# Skip models that don't have an internal callable assigned
1262+
if (!$model_obj->internal_callable) {
1263+
continue;
1264+
}
1265+
1266+
# Ensure the internal callable exists
1267+
$this->assert_is_true(method_exists($model_obj, $model_obj->internal_callable));
1268+
}
1269+
}
12511270
}

0 commit comments

Comments
 (0)