Search code examples
configurationphpunitphpstorm

configuring issue with phpunit in phpstorm 3.0.3. can't find required files


Whenever I run my unit tests in PHPStorm, i have to outcomment my require_once statements from my class files.

If I for instance have a class

require_once 'model/Foo.php'

class Bar extends Foo {

    function baz($a, $b) {
        ...
    }
}

I'll have to make a unit test class that looks like this (note the extra require_once)

require_once 'c:\path\to\project\src\model\Foo.php
require_once 'c:\path\to\project\src\Bar.php

class BarTest extends PHPUnit_Framework_TestCase {

    /**
     * @covers Bar::baz
     */
    function testBaz(){
        ...
    }
}

then when I'm done testing, I can go through all my files and uncomment the require_once statements and then I can work on or upload to the server.

I organize my classes like this

projectRoot
+-src
| +-index.php and my classes+their folders
|
+-test
  +-my unit test classes

Is this a configuration issue in PHPUnit or PHPStorm? and where do I fix it? I have googled for a few days and played with the phpunit configuration settings in phpstorm, but with little luck.


Solution

  • This is most likely caused by a working directory change.

    You should change your require_once from

    require_once 'model/Foo.php';
    

    To something that uses an absolute path, like:

    require_once(realpath(dirname(__FILE__) . "/model/Foo.php"));