Graham Conzett
Graham Conzett

Reputation: 8454

PHPUnit Setup and PHP directory issues

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

Upvotes: 1

Views: 599

Answers (1)

Jacob
Jacob

Reputation: 8334

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
{

Upvotes: 1

Related Questions