1

I know this probably gets asked a lot, but I have not used PHP in a really long time and I find myself once again wrestling with its path behavior and includes.

I have installed PHPUnit via Pear as is recommended, I have the Pear directory added to my php.ini file so that I can include PHPUnit.php globally. However, PHPUnit.php needs to include several files within it's own directory, and when I reference PHPUnit.php within my test directory:

require_once 'PHPUnit.php';

it attempts to include those files either relative to the test directory, or to the Pear directory specified in php.ini.

Fatal error: require_once() [function.require]: Failed opening required 'PHPUnit/TestCase.php'
(include_path='.:/home/data/pear/php') in /[snip]/domains/test.domainname.com/html/project/tests/PHPUnit.php on line 47

I remember dealing with these issues back in the day with PHP but I feel like I shouldn;t have to modify the path to the PHPUnit include files to make this work...

3
  • 1
    Dont know, if this matters, but PHPUnit_TestCase is for PHPUnit 1.x (or something, at least < 3.x). You should use PHPUnit_Framework_TestCase. Commented Mar 10, 2011 at 23:28
  • and you shouldn't "require 'PHPUnit.php' anyways. that will be done for you. Just to make sure: You did 'pear install phpunit/PHPUnit' (versions 3.5.x) and not just 'pear install phpunit' because thats a really old version :) Commented Mar 11, 2011 at 8:28
  • You know, I just realized I've been looking at documentation on the Pear site that is woefully out of date, not wonder this is giving me trouble, there seems to have been a lot of progress on this since I last used it! Commented Mar 11, 2011 at 16:49

1 Answer 1

1

PHPUnit uses the typical class name to path conversion autoloader that replaces the underscores in a class name with directory separators.

So in your code you've referenced PHPUnit_TestCase which has automatically tried to include the TestCase.php file in the PHPUnit directory, however that file/class doesn't exist.

As KingCrunch said in the comment, the class to use is PHPUnit_Framework_TestCase

If you look in your PHPUnit directory, there is a Framework directory that contains TestCase.php

See Writing Tests for PHPUnit

<?php
class StackTest extends PHPUnit_Framework_TestCase
{
Sign up to request clarification or add additional context in comments.

1 Comment

Jacob, you're absolutely right. I've installed the latest version but have been trying to use it like the old version. Thanks for the good Marking this as the answer since it provides a good, succinct run-down on how the current version is used. Thanks!

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.