How to: Setting, Using and Running Test with PHPUnit

[Warning: require_once(PHPUnit2/Framework/TestCase.php): failed to open stream: No such file or directory in… ]

How I got it?

I wanted to check my phpunit installed and try it for my testing. I took a sample code as below:

<?php
require_once ‘PHPUnit2/Framework/TestCase.php’;
class ArrayTest extends PHPUnit_Framework_TestCase {

}

?>

Then I opened up a terminal and keyed in the below command:

saffrongeek@saffrongeek-laptop:~/Projects/sao2crmdr$ phpunit phpunitdemo

I got the error Warning: require_once(PHPUnit2/Framework/TestCase.php): failed to open stream: No such file or directory in /home/saffrongeek/Projects/sao2crmdr/phpunitdemo.php on line 2

HOW TO RESOLVE THIS:

Step #1: Open a file broser and go and verify where PEAR and phpunit files exist. In mine both where at the following folder paths respectively: /usr/share/php/

Step #2: Open the php.ini and modify the include_path as below:

saffrongeek@saffrongeek-laptop:~/Projects/sao2crmdr$ sudo gedit /etc/php5/apache2filter/php.ini

Remove semicolon in front and add the pear and phpunit paths to look as include_path = “.:/usr/share/php:/usr/share/php/PEAR:/usr/share/php/PHPUnit”

Step #3: Restart Apache server as below:

saffrongeek@saffrongeek-laptop:~/Projects/sao2crmdr$ sudo /etc/init.d/apache2 restart

Step #4: Correct the file included and class from PHPUnit2 to PHPUnit.

Now try again in terminal and I got it working.

saffrongeek@saffrongeek-laptop:~/Projects/sao2crmdr$ phpunit phpunitdemo
PHPUnit 3.3.17 by Sebastian Bergmann.

..

Time: 0 seconds

OK (2 tests, 2 assertions)

Let me know whether it works for you and your comments.


Advertisements

2 Responses to “How to: Setting, Using and Running Test with PHPUnit”

  1. Thank you for your work!!!! It’s just what I need!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: