I installed PHPUnit
with:
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
Trying to run a simple test, but getting:
Fatal error: require_once(): Failed opening required 'PHPUnit_Extensions_Story_TestCase.php'
How do I install PHPUnit_Extensions_Story_TestCase
?
The test is simply:
class TestFunctions extends PHPUnit_Framework_TestCase {
public function test_str() {
$this->assertEquals('foo', 'bar');
}
}
Unfortunately none of the suggested fixes worked for me. The typical response is to install the phpunit/PHPUnit_Story module. While that will put you in the right direction, it did not solve my problem.
I registered an autoload function in my boostrap.php file. This most likely replaced the autoload function, registered by PHPUnit, used to autoload PHPUnit's classes. I commented my autoload function implementation and the issue went away.
EDIT
In response to @user3265472; It's been a while since I've worked on this, but I want to say that the "fix" was to set the include paths at the beginning of the bootstrap.php file and then manually loading the classes as you would normally:
/**
* Configure include paths used by the unit tests.
*
* @return void
*/
function configure_include_paths()
{
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . "/mylib");
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . "/mylib2");
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)) . "/lib");
}
configure_include_paths();
This allowed me to do something like the following at the beginning of every file:
require_once("MyClass.php");
instead of having to determine where the class was in relation to the current class file.
I also want to say that no matter what I did I couldn't get class auto-loading to work as I would have liked. I hope this helps.
You need to install phpunit/PHPUnit_Story package:
sudo pear channel-discover pear.phpunit.de
sudo pear install phpunit/PHPUnit_Story
Or manually from github repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With