PHPUnit 5.3.10, PHP_CodeCoverage 1.1.2

We use different extensions than just the typical .php for different functions to protect against the web server being able to run some code that is not intended as a web service or page.

  • .class are PHP class definitions.
  • .fn is used when not expecting interaction or a web service, but a simple function
  • .php - Normal web services and pages
  • .test are the test cases

I am writing test cases for a number of classes in a subdirectory. I have one load file that loops through all the classes (using glob) and then requires them. When I run the automated testing with code coverage, the LoadClasses.fn file is present in the Code Coverage report at 0%. When I add the testing file (LoadClasses.fn.test), the tests do execute and pass, but the file is not showing in my Code Coverage report anymore. The file is not even listed at 0%, 100% or anything.

Please note, this code has to work with PHP 5.2.x, so we use UI_ in the class name to give the equivalence of namespaces.

Source File: LoadClasses.fn

    <?php
    /**
     * $Archive: /UserInterface/lib/UTIL/LoadClasses.fn $
     */
    foreach (glob(dirname(__FILE__) . '/../APP_CLASS/' . '*.class') as $FileName)
    {
        require_once($FileName);
    }
    ?>

Test File: LoadClasses.fn.test

    <?php
    /**
     * $Archive: /UserInterface/lib/UTIL/LoadClasses.fn.test $
     */
    require_once(substr(__FILE__, 0, -5));  // strip '.test' extension to call code to execute
    class TEST_LIB_UTIL_LoadClasses extends PHPUnit_Framework_TestCase
    {
        protected function setUp()  {       }

        public function testAllClassesLoadedByFileName()
        {
            foreach (glob(dirname(__FILE__) . '/../APP_CLASS/' . '*.class') as $FileName)
            {
                $ClassName = 'UI_';
                $ClassName .= basename($FileName, '.class');  // Remove .class from end
                $this->assertTrue(class_exists($ClassName), 'Class: ' . $ClassName);
            }
        }
    }
    ?>

If I change the

$ClassName = 'UI_'; 

to be

$ClassName = 'BAD_' 

in the file, and then run the tests, I get the error on the first pass that the class does not exist.

If I remove the LoadClasses.fn.test file and run the test suite again, the LoadClasses.fn returns to my code coverage report.

The classes are fairly straight forward, so not sure what is going wrong here.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

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

Browse other questions tagged or ask your own question.