Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Dear stackoverflowers, We are developing a web application based on cakephp. CakePHP turns out to be a bit hard to use in a TDD manner and therefore we have are trying to develop the least amount of code possible on the framework it self by extracting all business logic out to classes that do not depend on cakephp. As such, we are able to test our libraries using phpunit with minimal problems. However, we do want to included the untested code in our coverage report more than anything to keep an eye on the amount of glue code between cake and our libraries that we can not test. The problem is then that when telling phpunit to account for these code it goes crazy parsing and executing cakephp's code and it breaks miserably. My question is: Why is phpunit executing this code at all? Is there something we are not understanding or doing wrong here? Here is the phpunit.xml file we are using:

<?xml version="1.0" encoding="utf-8" ?>

<phpunit backupGlobals="true"
         backupStaticAttributes="false"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false"
         testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader">
  <filter>
    <whitelist addUncoveredFilesFromWhitelist="true">
      <directory suffix=".php">app</directory>
      <exclude>
        <directory suffix=".php">tests</directory>
        <directory suffix=".php">app/webroot</directory>
        <directory suffix=".php">app/plugins</directory>
        <directory suffix=".php">app/vendors</directory>
        <directory suffix=".php">app/config</directory>
        <directory suffix=".php">app/tmp</directory>
        <directory suffix=".php">cake</directory>
        <directory suffix=".php">vendors</directory>
      </exclude>
    </whitelist>
  </filter>
</phpunit>

Thanks for any help.

share|improve this question

2 Answers 2

You need to add the cakephp files to the blacklist. You should be able to do this in your xml config file:

<filter>
  <blacklist>
    <directory suffix=".php">/path/to/files</directory>
    <file>/path/to/file</file>
    <exclude>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
    </exclude>
  </blacklist>
</filter>

There is further information here

share|improve this answer
1  
Thanks timmow. I did this and it ended up working fine. The most important detail though is the the path is relative to the tests directory and not to the root of the codebase from where the ant build is running. This is an undocumented detail that could have save me our!! –  edovale Jan 20 '11 at 4:31

Why is phpunit executing this code at all?

It does this because it needs to get information about the classes, methods and functions that are not covered, too. It includes the files it finds and uses Reflection to discover all information about the classes. That's easier than manually parsing and analyzing the parsed tokens of a PHP file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.