[GH-ISSUE #1048] Rethinking Hm_Functions #561

Open
opened 2026-02-25 21:35:21 +03:00 by kerem · 4 comments
Owner

Originally created by @TheDigitalOrchard on GitHub (May 25, 2024).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/1048

Originally assigned to: @josaphatim on GitHub.

🗣 Suggestion

I'll start off by saying that my Unit Testing experience is very limited. As the sole developer for my projects, I haven't had the need to do a lot of package-wide unit testing, although I'm sure I'd get a lot of value if I finally did incorprate this best practice.

In lib/framework.php, a class called Hm_Functions is defined with a lot of methods that merely wrap around built-in functions, such as function_exists() and class_exists(). Calling these results in two function calls, even though nothing of value is added by this.

The explanation for this class is:

/**
     * Used to override built in functions that break unit tests
     * @package framework
     * @subpackage setup
     */

Can someone enlighten me as to how unit tests are broken by built-in functions? What is an example?

How is calling Hm_Functions::function_exists() better than just calling the built-in function_exists()?

Let's start there. Help me understand this better. If there is a solid explanation for using this wrapping class, then I'll drop my suggestion for rethinking it.

(Yes, I'm a micro-optimization nut, so I'm always triggered by unnecessary function calls, pun intended)

Thanks.

Originally created by @TheDigitalOrchard on GitHub (May 25, 2024). Original GitHub issue: https://github.com/cypht-org/cypht/issues/1048 Originally assigned to: @josaphatim on GitHub. ## 🗣 Suggestion _I'll start off by saying that my Unit Testing experience is very limited. As the sole developer for my projects, I haven't had the need to do a lot of package-wide unit testing, although I'm sure I'd get a lot of value if I finally did incorprate this best practice._ In `lib/framework.php`, a class called `Hm_Functions` is defined with a lot of methods that merely wrap around built-in functions, such as `function_exists()` and `class_exists()`. Calling these results in two function calls, even though nothing of value is added by this. The explanation for this class is: ```php /** * Used to override built in functions that break unit tests * @package framework * @subpackage setup */ ``` Can someone enlighten me as to how unit tests are broken by built-in functions? What is an example? How is calling `Hm_Functions::function_exists()` better than just calling the built-in `function_exists()`? Let's start there. Help me understand this better. If there is a solid explanation for using this wrapping class, then I'll drop my suggestion for rethinking it. _(Yes, I'm a micro-optimization nut, so I'm always triggered by unnecessary function calls, pun intended)_ Thanks.
Author
Owner

@marclaporte commented on GitHub (May 26, 2024):

@josaphatim Please advise

<!-- gh-comment-id:2132239391 --> @marclaporte commented on GitHub (May 26, 2024): @josaphatim Please advise
Author
Owner

@josaphatim commented on GitHub (Jun 9, 2024):

@TheDigitalOrchard I tried to replace calls of Hm_Functions::function_exists and Hm_Functions::class_exists by native functions: there was a total of 3 tests failed. It can be more if I replaced all methods in Hm_Functions. I will investigate more but of course Hm_Functions prevents to break unit test

<!-- gh-comment-id:2156339358 --> @josaphatim commented on GitHub (Jun 9, 2024): @TheDigitalOrchard I tried to replace calls of Hm_Functions::function_exists and Hm_Functions::class_exists by native functions: there was a total of 3 tests failed. It can be more if I replaced all methods in Hm_Functions. I will investigate more but of course Hm_Functions prevents to break unit test
Author
Owner

@marclaporte commented on GitHub (Sep 28, 2024):

@josaphatim There has been lots of work in the last months. Any status changes here?

Thanks!

<!-- gh-comment-id:2380382450 --> @marclaporte commented on GitHub (Sep 28, 2024): @josaphatim There has been lots of work in the last months. Any status changes here? Thanks!
Author
Owner

@marclaporte commented on GitHub (Sep 1, 2025):

@josaphatim we need you :-)

<!-- gh-comment-id:3240658007 --> @marclaporte commented on GitHub (Sep 1, 2025): @josaphatim we need you :-)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#561
No description provided.