1
votes

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...

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. - KingCrunch
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 :) - edorian
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! - Graham Conzett

1 Answers

1
votes

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
{