0

Isn't PHPUnit supposed to require the class itself using the naming conventiong "ClassTest"?

  • I have a php file "Router.php" with a class Router
  • My PHPUnit testing class is defined as following:

    class RouterTest extends PHPUnit_Framework_TestCase

However it raises a fatal error for file not found "Router.php". If I require it manually everything is ok.

What's wrong with it?

2
  • Are you using a framework? Your framework should automatically include Router.php, if you aren't then you have to include it Commented Jul 25, 2013 at 8:49
  • Which directory is RouterTest.php in, which is Router.php, and which directory do you run phpunit from? Commented Jul 25, 2013 at 23:53

1 Answer 1

1

There is nothing wrong with it. How would PHPUnit know where your classes are in relation from the tests?

For your tests, you need to either require the class under test yourself or create an autoloader that will require the class for you. PHPUnit has no idea where it should be getting the files from. It has an autoloader for its internal files but that is it.

Sign up to request clarification or add additional context in comments.

1 Comment

That was the answer I went to give yesterday; then I noticed the OP's error message is file not found, not class not found, which didn't seem to fit. Maybe that was just a typo.

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.