How to install PHPUnit in the CentOS environment

Source: Internet
Author: User
Tags pear
This article mainly introduces the method of installing PHPUnit in the CentOS environment, analyzes the steps, related problems and solutions of installing phpunit in the CentOS environment with the example form, and the friends can refer to the following

This paper describes the method of installing PHPUnit in the CentOS environment. Share to everyone for your reference, as follows:

PHPUnit to PHP, as JUnit is to Java, is a tool that PHP programmers use to write unit test code. Because the superior requires the staff to write code, also write unit test code, so I collected the relevant information on the Internet, and collated a set of virtual machine in line with their own environment PHPUnit installation method.

Requirements:

System: centos5.4
PHP Version: php5.3.

First, install the Pear

The first thing to install is the latest pear. The installation commands are as follows:

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

Pear installation is successful! If the above command execution is unsuccessful:

1. Find PHP executable file location with Find/-name PHP;
2. You can try to add sudo at the beginning of the command, or switch to the root user with Su root.

Second, installation PHPUnit

Use pear to install phpunit below. The following installation process may prompt you not to find pear, because pear is not added to the environment variable. My workaround is to:

1, use find / -name pear to find the location of pear

2. Enter this statementexport 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

Dependent packages may appear during installation and follow the prompts to install them.

such as: yum install php-dom -y etc.

Congratulations! If all goes well, prove that you have successfully installed PHPUnit.

Third, the use of PHPUnit

Example: hello.php

<?phpclass Hello_test extends Phpunit_framework_testcase{publicfunction test_equal ()  {$stack = array (); $this- >assertequals (0,123);  Determine if 0 and 123 are equal  }}?>

PHPUnit hello.php See OK, say success, otherwise ...

But my side error did not find PHPUnit, when the discovery is not a path problem, find the following workaround

Pear Update-channelspear Upgrade-all

After the installation is finished:

Pear install–alldeps Phpunit/phpunit

The result is an error:

Unknownremote channel:pear.symfony.com
Phpunit/phpunit requires package "Channel://pear.symfony.com/yaml" (Version >= 2.1.0)

Google, find a useful solution:

Pear channel-discover pear.symfony.compear Install Pear.symfony.com/yaml

And then execute it again.

Pear install–alldeps Phpunit/phpunit

This is a success.

Iv. Summary

Here I share with you the process from failure to success when I install PHPUnit on my own virtual machine. The failure is mainly due to the lack of executable files, or a few dependent libraries, or the failure of the tool to the version of the system has a high and low mutual incompatibility.

The previously shared example uses assertequals with an equal assertion value, although PHPUnit also has many other assertion 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.