Because running tests should be easy with Codeception. Any test.
I’ve developed function-mocker to be able to use it in PHPUnit tests and this means that using it inside PHPUnit tests in a Codeception suite comes natural; but some issues might arise if function-mocker is loaded too late into the tests.
Precisely what happens is that patchwork will need to be loaded before any file defining classes and functions or it will fail; that’s because its magic is based on intercepting any file loading operation and modify the code that’s loaded in the memory and executed.
The Codeception library will load a main
_bootstrap.php file first and a suite specific
_bootstrap.php file second.
I always include Composer autoloader in the bootstrap file to make my testing life easier and that will take care of autoloading the
FunctionMocker class as well.
// file codeception/_bootstrap.php <?php /** * @file Global bootstrap for all codeception tests */ use tad\FunctionMocker\FunctionMocker; $composer_autoload_file = dirname( __FILE__ ) . '/../whatever/vendor/autoload.php'; require_once $composer_autoload_file; FunctionMocker::setUp();
and that will make it.
Patchwork will cache any loaded file on the first run but function-mocker will not replace any function unless explicitly told to do so.