3

Installed PEAR and followed the directions on http://www.phpunit.de/manual/current/en/installation.html:

pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit.

Then, I created the test:

<?php
# error reporting
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

# include TestRunner
require_once 'PHPUnit/TextUI/TestRunner.php';

# our test class
class ExampleTest extends PHPUnit_Framework_TestCase
{
    public function testOne()
    {
        $this->assertTrue(FALSE);
    }
}

# run the test
$suite = new PHPUnit_Framework_TestSuite('ExampleTest');
PHPUnit_TextUI_TestRunner::run($suite);
?>

I included the following in php.ini file and restarted Apache:

include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear/PHPUnit"

I get Warning: require_once(PHPUnit/TextUI/TestRunner.php) [function.require-once]: failed to open stream: No such file or directory in ...

Why doesn't the include path work? Is it because there is a space in Program files?

Working in Windows XP and WAMP.

EDIT: I updated the path as suggested.

The output of echo ini_get('include_path'); before require_once call is:

.;C:\Program Files/wamp/bin/php/php5.3.8/pear

Also, removing the require_once command throws Fatal error: Class 'PHPUnit_Framework_TestCase' not found in...

B Seven
  • 44,484
  • 66
  • 240
  • 385
  • can you print the include path exactly before your require_once 'PHPUnit/TextUI/TestRunner.php' ? echo ini_get('include_path'); maybe something is overriding it – Laith Shadeed Nov 13 '11 at 16:27
  • on a sidenote there should be no need for manually including any files from PHPUnit in your testcases. When you run PHPUnit from the commandline it will register its own autoloader. You only need to make sure PEAR is on your include_path. – Gordon Nov 13 '11 at 16:29
  • Actually, I did consult some of those "How Do I" posts. They have many different instructions for installation, but did not solve the problem. – B Seven Nov 13 '11 at 16:40
  • @BSeven yeah, its actually not a phpunit issue at all. I modified the question to reflect this. deleting comment as well. You should also make sure the php you got on CLI is actually the one you configured with that php.ini by running `php --ini`. – Gordon Nov 13 '11 at 16:47
  • I only have one version of PHP installed. I think I am modifying the correct php.ini file because I can see the change in the path using `echo ini_get('include_path');`. – B Seven Nov 13 '11 at 16:51
  • @BSeven how are you executing the testcase? From CLI with phpunit? – Gordon Nov 13 '11 at 17:14
  • @BSeven That's the mistake. PHPUnit is a command line tool. See my 2nd comment again please. – Gordon Nov 14 '11 at 08:30
  • After following the provided solution I still had file not found errors, which I fixed by following http://stackoverflow.com/a/4641784/290182 and including the line `require 'PHPUnit/Autoload.php';` – beldaz Feb 07 '12 at 02:40

1 Answers1

2

By adding those three lines to the ini, the last one will override everything. Only use this one

include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8\pear"

Edit: adding @Gordon comment. We need to keep \pear. Because inner pear libraries are assuming that pear already in the include path.

http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.modifyingphpini

Laith Shadeed
  • 4,271
  • 2
  • 23
  • 27
  • Why that one? Why not `include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8`? – B Seven Nov 13 '11 at 16:35
  • 1
    @BSeven because http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.modifyingphpini ;) – Gordon Nov 13 '11 at 16:44