1

I using NetBeans 7.3 with PHP Unit test.

Test file creation works. I can create test file by right-click: tools->create PHP unit test. New test is created in Test folder (filenameTest.php). When I run the test (Ctr+F6), in output window, I am getting error saying: that it can’t find the file I am trying to test. If I include_once the original file into test file everything works, and I can run the tests.

I would prefer not to add that include_once line manually into each testFile. Is there a way to have NetBeans to do that for me automatically? Or how do I configure bootstrap file and/or phpunit.xml file, so it works without including the original file into testfile?

Thanks in advance.

1 Answer 1

3

You can create a bootstrap.php file in your tests folder that registers an autoloader to load the class that you are testing. You would then have a phpunit.xml file with the following:

<phpunit bootstrap="bootstrap.php">
</phpunit>

Registering an autoloader would be the easiest solution as then you don't have to remember to include files or if you or someone else isn't using NetBeans there aren't any problems with creating new tests.

Inside the bootstrap.php would be:

function autoloader($className) {
    *** do logic to set path of file for the class ***
    $classPath = "/base/path/for/file/" . $className;
    require_once($classPath);
}

spl_autoload_register('autoloader');
Sign up to request clarification or add additional context in comments.

2 Comments

Schleis, thanks for quick response. Maybe stupid question, but what do I put in Bootstrap file? Do i need to add include_path to my project/site? Thank you.
I would create some sort of autoloader, the details will depend on the layout of your project and class naming. php.net/manual/en/function.spl-autoload-register.php

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.