PHP: include files only when running phing?
I have the following folder structure:
/main /loader.php /build.xml /components /package1 /class1.php /package2 /class2.php /tests /package1 /class1.test.php /package2 /class2.test.php
When I start the web application, I first load loader.php
and enable other components by calling Loader::load( 'package_name' )
. Then all the necessary files are included. The good thing is that I don't need to include loader.php
in the class files because I can rely on the working instance Loader
.
The Unit Test classes simulate this behavior by including any required classes explicitly. This way there is no problem with phing and PHPUnit.
But now I want to generate a coverage report using phing and Xdebug. The problem here is that phing seems to load every single PHP file to create the coverage database. Unfortunately it stops because it cannot find the class Loader
that is being used in the PHP files.
I could easily add a statement include
to each class file, but I'm wondering if there is a way to include the files only if the code coverage analysis checks the file?
Another idea: I could also set up the coverage analysis to scan the single test directory and therefore find all the required components. Then I will need to filter out the classes that match the pattern, eg /Test$/i
. Is it possible?
a source to share
I was looking for an age for something similar.
In the end I ended up with the changes below. Basically you are telling the php cli to add a php file containing the loading logic.
In the php.ini of my cli, I have set the following:
auto_prepend_file = autoload.php
I made sure the file was included in my include path (/ usr / share / php in my case) and put the following lines in it (I'm using Zend Framework which is also in my include path):
require_once "Zend / Loader / Autoloader.php"; $ autoloader = Zend_Loader_Autoloader :: getInstance (); $ Autoloader-> registerNamespace ('Model _');
Now, what you can do is define your __autoload function and define what should be automatically loaded, but you get the idea.
It's an ugly hack, but everything was done for me.
WKO Jeroen