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.4PHP version: php5.3. 1. install Pear

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:

 

  1. Wget http://pear.php.net/go-pear.phar
  2. /Usr/local/php5.3/bin/php go-pear.phar
 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"

 

 

 
  1. Pear channel-discover pear.phpunit.de
  2. Pear channel-discover components. ez. no
  3. Pear channel-discover pear.symfony-project.com
  4. Pear upgrade-all
  5. Pear install phpunit/PHPUnit
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

 

 

  • Class hello_test extends PHPUnit_Framework_TestCase
  • {
  • Public function test_equal ()
  • {
  • $ Stack = array ();
  • $ This-> assertEquals (0,123); // judge whether 0 and 123 are equal
  • }
  • }
  • ?>
  •  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:

     

     

     
    1. Pear update-channels
    2. Pear upgrade-all
    pear update-channels pear upgrade-all 
     

     

    After installation:

     

     

    Pear install-alldeps phpunit/PHPUnit
    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. 1 pear channel-discover pear.symfony.com
    2. 2 pear install pear.symfony.com/Yaml
    1 pear channel-discover pear.symfony.com2 pear install pear.symfony.com/Yaml 


     

    Then execute again

     

     

    Pear install-alldeps phpunit/PHPUnit
    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.