Install PHPUnit in Centos5.4

Source: Internet
Author: User

PHPUnit is used by PHP programmers to write unit test code, just as JUnit is used in Java. As the superiors asked employees to write unit test code when writing code, I collected relevant information online and sorted out a set of PHPUnit installation methods that suit the virtual machine environment.

Requirements:

System: Centos5.4

PHPVersion: Php5.3.

 

1. Install Pear

 

First, install the latest pear. The installation command is as follows:

 wget http://pear.php.net/go-pear.phar /usr/local/php5.3/bin/php go-pear.phar

Pear is successfully installed! If the preceding command fails to be executed:

 

1. Use find/-name php to find the location of the php executable file;

2. Try to add sudo to the command or use su root to switch to the root user.

 

Ii. Install phpunit

 

The following uses pear to install phpunit. The following installation process may prompt that the pear is not found because the pear is not added to the environment variable. My solution is:

 

1. Use find/-name pear to locate the pear location.

2. Enter this statement export PATH = "$ PATH:/usr/local/php5.3/bin/pear"

 

pear channel-discover pear.phpunit.depear channel-discover components.ez.nopear channel-discover pear.symfony-project.compear upgrade-allpear install phpunit/PHPUnit  

The dependency package may appear during the installation process. Follow the prompts to install the package.

 

For example, yum install php-dom-y.

 

Congratulations! If everything goes well, you have successfully installed PHPUnit.

 

3. Use PHPUnit

 

Example: hello. php

 

<? Phpclass hello_test extends PHPUnit_Framework_TestCase {public function test_equal () {$ stack = array (); $ this-> assertEquals (0,123); // judge whether 0 and 123 are equal}?>

Phpunit hello. php: If OK is displayed, it indicates the operation is successful. Otherwise ......

 

However, phpunit is not found in the error message. If it is not a path problem, find the following solution:


pear update-channels pear upgrade-all 
 

After installation:

 

pear install –alldeps phpunit/PHPUnit 

 

An error is returned:

 

Unknownremote channel: pear.symfony.com

 

Phpunit/PHPUnit requires package "channel: // pear.symfony.com/Yaml" (version> = 2.1.0)

 

Google to find a useful solution:

 

1 pear channel-discover pear.symfony.com2 pear install pear.symfony.com/Yaml 


Then execute again

 

pear install –alldeps phpunit/PHPUnit 

 

This is successful.

 

Iv. Summary

 

Here I will share with you the process from failure to success when I install PHPUnit on my own virtual machine. Failure is mainly because the executable file cannot be found or some dependent libraries are missing. Failure may also result in high or low compatibility between the tool and the system version.

 

In the above example, assertEquals with equal asserted values are used. Of course, PHPUnit also comes with many other asserted methods, such as assertEmpty assertTrue ......

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.