PHPUnit introduction and possible warnings/errors


1. Beginner guidebook

I am using Ubuntu 12.04, so below may only available for 12.04 and can have issues when using different unix system.
2.  Installation
Cmd below will install the latest PHPUnit. And you need install "pear" first.
>sudo pear install --alldeps --force phpunit/phpunit
3. Modify the php.ini
First, find the php path:
>pear config-show | grep php_dir                                 
PEAR directory                 php_dir          /usr/share/php
Then find  the php.ini file
>locate php.ini   
And change the include_path in php.ini to the value of php_dir:
include_path = ".:/usr/share/php"                               

4. The output of the PHPUnit result
>phpunit path/to/file/ClassNameTest.php
PHPUnit 3.7.27 by Sebastian Bergmann.

Time: 6.76 seconds, Memory: 4.75Mb

OK (1 test, 1 assertion)

The new PHPUnit version will also calculate the memory used to run your script. That is really nice and can help you to know the memory consumption of your script.

5. Issues
If your setting is not correct, or after a certain time, PHPUnit is updated, you may have encounter some problems as below:

(1)
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 64
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/usr/bin/pear') in /usr/share/php/PHPUnit/Autoload.php on line 64

This is because your include_path is not correct, or lack of  File_Iterator.
You can install the latest PHPUNit by:
>sudo pear install --alldeps --force phpunit/phpunit
Or you can only install File_Iterator:
sudo pear install phpunit/File_Iterator 


(2)
phpunit PHP Warning: require_once(PHPUnit/Framework/MockObject/Autoload.php): failed to open stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 48 PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Framework/MockObject/Autoload.php' (include_path='.:/usr/share/php/:/usr/local/share/php/library') in /usr/share/php/PHPUnit/Autoload.php on line 48
You can install the latest PHPUNit by:
>sudo pear install --alldeps --force phpunit/phpunit
or you can only update the lib that seems to be the issue:
>sudo pear install --force phpunit/PHPUnit_MockObject

Comments

Popular posts from this blog

install postgreSQL in ubuntu 16.04

timestamp with 16, 13 and 10 digits to Qlik date

install ipython in Cloudera VM using pip