php - Is it possible to mock "require" or "require_once" statement with Kahlan?
I have very old legacy code. Before starting refactoring I want to make some unit tests for the code. But the bad thing is that files relies on each other with "require_once" statements (hovewer, functions I want to test is isolated).
So I can't write normal tests if I will not be able to mock "require_once" statement.
I'm using Kahlan framework for testing. So is it possible to mock such statements? If yes, than how?
Answer
Solution:
It was not possible.
However, I have made a plugin to Kahlan that allows to "extract" functions from any file and skip all other code. It will not allow to exactly "mock" statements, but it will allow to test isolated functions. I made pull-request and if it will not be accepted, I will make a separate packagist composer packet and update this answer.
Changes can be found here:
https://github.com/lamp-of-god/kahlan/tree/isolator-plugin
Example of usage:
File:
Test for this file with plugin: