First, instead of using __construct(), use setup() and teardown()
Those are documented here:
http://www.phpunit.de/manual/current/en/fixtures.html#fixtures.more-setup-than-teardown
Next, if you find the PHP state is not getting reset for certain values,
in your teardown, you can always do something like this:
ini_restore('include_path');
That should reset the value to its original value.
Hope that helps!
-ralph
fab2008 wrote:
Hi all,
I've a problem using these two components together when i run my tests. I
have my tests organized with a hierarchy similar to the Zend Framework one,
so in every directory I have a file named AllTests.php which can be used to
run all the tests in that directory recursively.
When I run a consistent number of test I have an exception regarding some
classes not found; I debugged the code and I found that is a problem related
to include_path. This is an example of what's happening:
class TestCase extends PHPUnit_Framework_TestCase {
/**
* @var Zend_Application_Bootstrap_Bootstrap
*/
protected $_bootstrap;
public function __construct($name = NULL, array $data = array(),
$dataName
= '') {
parent::__construct($name, $data, $dataName);
$application = new Zend_Application(APPLICATION_ENV,
APPLICATION_CONFIG);
$application->bootstrap('db');
$this->_bootstrap = $application->getBootstrap();
Zend_Debug::dump(get_include_path());
}
public function testA() {
Zend_Debug::dump(get_include_path());
}
public function testB() {
Zend_Debug::dump(get_include_path());
}
public function testC() {
Zend_Debug::dump(get_include_path());
}
}
and this is the output:
string(120) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
string(203) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
string(286) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
PHPUnit 3.3.15 by Sebastian Bergmann.
string(286) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
.
string(286) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
.
string(286) "/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:/Users/fabionapoleoni/Documents/workspaces/php/ZenitSpot
Trunk/application/var/lib:.:/Applications/MAMP/bin/php5/lib/php"
.
Time: 0 seconds
OK (3 tests, 0 assertions)
As you can see at every constructor call (all of them made in the
inizialization phase) the include_path growth by a voice, as specified by
application.ini
includePaths.library = APPLICATION_PATH "/var/lib"
This problem doesn't affect earlier tests, but when I run a large number of
tests the include_path became of over 1000 characters and at a certain point
php doesn't find classes anymore.
What can I do to fix this behaviour? I tried by saving original include_path
in constructor and restoring it both in the teardown method and in the
__destruct method, but with no success :-(
Any hint?