0

I'm trying some supposedly nice features of PHPUnit, but I cannot generate a freakin' code coverage report. What I get is:

rolf@dev ~/projects/current/tests $ scripts/phpunit --configuration $PROJECTS/current/tests/conf/inc/tests.xml
[...]
Generating code coverage report, this may take a moment.
[...]
Fatal error: require_once(): Failed opening required 'lib/DataSource.php' (include_path=':::') in path/to/lib/WS/DataParser.php on line 10

However, in this very class, a specific include path is defined, and the require_once works like a charm when the application is launched.

Could it be that PHPUnit cannot solve include paths ?

Thanks in advance and long live stackoverflöw!

Rolf
4
  • When you 'launch' your application, is it via a browser or the CLI? If the browser, are you setting include paths in the .htaccess file or possibly the PHP.INI file that is not being used by PHPUnit? Commented Jun 28, 2010 at 10:36
  • hi, I usually run the application via a browser, except for unit tests... Commented Jun 29, 2010 at 8:04
  • btw, launch an application isn't correct ? Commented Jun 29, 2010 at 8:06
  • it is very likely that you have a different php_include_path in phpunit, or the base directory is different Commented Jul 2, 2010 at 17:49

2 Answers 2

1

If you're using the latest PHPUNIT (3.5+) it might be because Sebastion has started using an autoloader himself within the program.

You've got to add the line

 spl_autoload_register('__autoload');

after your __autoload() function gets created / included / required

so for example, the file that has my autoloader is called functions. in my bootstrap I do the following:

require_once(ROOT_PATH.'/lib/utils/functions.php');
spl_autoload_register('__autoload');
Sign up to request clarification or add additional context in comments.

Comments

0

Are you changing your include_path in any of your tests/code? Because it looks really odd (:::)

2 Comments

well, I've got an __autoload function just for unit tests that changes the include_path, but the class that cannot be parsed also defines an include path, so I don't understand...
Your include_path of (include_path=':::') doesn't contain any actual path information, only path separators. That means the code may only look in the current directory for includes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.