PHPUnit

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

PHPUnit

Post by kpraman »

Hello,

I downloaded PHPUnit PHPUnit-3.0.0beta1. Extracted to a folder and tried to test a sample test. But i am getting errors like....Warning: require_once(PHPUnit/Framework.php). i have even checked the path. Every thing seems to be correct. Can anyone guide me to get it installed?

Regards,

kpraman
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

I believe you have three options:

1) installing with PEAR (see http://www.phpunit.de/pocket_guide/3.0/ ... ation.html)

2) downloading it yourself. This way is just fine, but you must add the parent path of PHPUnit directory to include_path of php (either by editing php.ini or at runtime with set_include_path(), see PHP manual for details).

For example, if you install PHPUnit in /var/php/libs/PHPUnit, the path /var/php/libs must be added to include_path.

3) Another option is to checkout the project from the svn repository, but again you must add that path.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

Thanks for the reply. Its working now.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

if i give,

require_once '../library/PHPUnit.php';

it is working. but, if i give require_once '../library/PHPUnit2.php'; same error occurs. PHPUnit2.php is in same library folder
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Get the file path to PHPUnit on your system. Then add it to your test file's include path.

Code: Select all

set_include_path(
    get_include_path() . PATH_SEPARATOR . "my/path/from/test/to/PHPUnit"
);
If you want a single PHPUnit directory for all your PHP projects, set up PEAR and update it to the alpha. PEAR should already come prepackaged with PHPUnit 2.

AFAIK you start by including the relevant framework component. i.e. once it's installed to PEAR (and PEAR is on the include path) or once you set up the include path as above...

Code: Select all

require_once 'PHPUnit/Framework/TestCase.php';
Then write your test case for the test... See the PHPUnit docs - it's the external homepage link from the PEAR page for PHPUnit2
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

PHPUnit2

Post by kpraman »

I am currently using PHPUnit-1.3.2.

PHPUnit is located in,

server/project/classes/library/PHPUnit


in the testcase files, i am using the following code...

Code: Select all

<?php 
set_include_path("library/"); 

require_once 'members.php'; 
require_once 'PHPUnit/Framework/TestCase.php'; 
require_once 'PHPUnit.php'; 

class MembersTest extends PHPUnit_TestCase { 
....... 
...... 

?>
This is working.

if i want to use PHPUnit-2.3.6 What are the changes i have to make?. I am getting errors.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Check the internal 2.3.x references. If they are including from a PHPUnit2 directory then PHPUnit2 is what you need to use in your test files. I tried setting up 2.x.x via PEAR a while back and it was throwing include errors. I predominantly use SimpleTest (I also help do general maintenance for it) so I'm not entirely up to speed on the current setup.
R@mzes
Forum Newbie
Posts: 3
Joined: Fri Jan 05, 2007 3:48 am

Post by R@mzes »

Hi, I think that article will be usefull
Post Reply