1

I have the following example test code (PHP4) I need to run with phpunit:

<?php

require_once 'PHPUnit/Framework.php';

class RemoteConnectTest extends PHPUnit_Framework_TestCase
{
  public function setUp(){ }
  public function tearDown(){ }
  public function testConnectionIsValid()
  {
    $this->assertTrue(true);
  }
}
?>

which does not run with phpunit:

PHP Fatal error:  require_once(): Failed opening required 'PHPUnit/Framework.php' ...

How do I need to setup my environment to make this work (Linux, Ubuntu 12.04)? Do I need to set a search path? Change php.ini? I AM NOT ABLE TO CHANGE THE TEST CODE ITSELF.

9
  • Does the required file stay in the right relative path? Commented Apr 17, 2013 at 9:49
  • I need the given code example to work without change. I can change paths, phpunit, use options, anything, but the test code has to stay unchanged. Where all the required files are is of no importance. Commented Apr 17, 2013 at 9:51
  • Your code will not work, if your required files are in different than the mentioned path, isn't it obvious? Commented Apr 17, 2013 at 9:52
  • So how to fix the problem then? I do not know where PHPUnit/Framework.php is at all... Commented Apr 17, 2013 at 9:53
  • Don't you have root access? Commented Apr 17, 2013 at 9:57

2 Answers 2

1

The answer is an incompatibility between the used versions. Newer versions of phpunit do have a different internal setup (see example for 3.7 here) which are different from older phpunit versions.

One need to 'downgrade' phpunit, as example as follows:

sudo pear uninstall phpunit/PHPUnit
sudo pear install phpunit/PHPUnit-3.2.8

to install version 3.2.8, for example. It can be verified the existance of the file Framework.php:

> ls /usr/share/php/PHPUnit
Extensions  Framework  Framework.php  Runner  TextUI  Util

The example code should work now when called as

phpunit SimpleTest.php

(assuming identical name of class and file [excluding the php of course]).

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

Comments

0

Since you can run phpunit from command line, you most likely have the source code installed with PEAR already (or composer, which is less likely). But path to framework is not in global include paths (or in system variable PATH).

The path to PHPUnit is usually inside PEAR. And PEAR is usually near php installation. You can always use global filesearch in terminal with

find / -name 'Framework.php' 2>/dev/null

You either need to either

  • edit php.ini and add path to PHPUnit in include_path directive
  • require_once absolute path
  • use autoloading (but thats only from PHP 5.3)

1 Comment

There is no Framework.php file at all. It is completely missing!!

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.