Introduction to essential PHP continuous integration tools for PHP Development (Part 1)

Source: Internet
Author: User
Tags php continuous integration continuous integration tools

In this article, we will introduceContinuous IntegrationInPHPIn development, how can we use some open-source continuous integration management tools of PHP to manage projects.

Concept of continuous integration

The concept of continuous integration was proposed in modern software engineering and was first introduced in Agile development methodology. Master Martin Fowler defined continuous integration as follows: continuous integration is a software development practice, that is to say, developers often integrate their work. Generally, each member is integrated at least once a day, which means that multiple integrations may occur every day. Each integration is verified through automated build (including compilation, release, and automated testing) to detect integration errors as soon as possible. Many teams find that this process can greatly reduce integration problems and allow the team to develop cohesive software more quickly.

The following describes the continuous integration tool in PHP:

PHPUNIT

First of all, PHPUNIT is a tool for unit testing in PHP, the Project address in: http://www.phpunit.it. It

You can automatically run the unit test code you wrote and show whether the code passes. The installation procedure is as follows. you can install PEAR in PHP:

 
 
  1. sudo apt-get install php5-curl php-pear php5-dev  
  2. sudo pear upgrade pear  
  3. sudo pear channel-discover pear.phpunit.de  
  4. sudo pear channel-discover components.ez.no  
  5. sudo pear channel-discover pear.symfony-project.com  
  6. sudo pear install phpunit/PHPUnit 

Then, you can execute phpunit in the following format in the command line:

Php file name for Phpunit unit test. php

In addition, you can run the following command to generate a unit test coverage report:

Phpunit -- coverage-html ../CodeCoverage

This will generate the unit test coverage report in the specified directory. In this example, the unit test coverage report will be generated in the CodeCoverage directory, for example:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP development essential PHP continuous integration tool introduction (on) "href ="/picshow/index595837.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095310781.jpg "/>
▲Click to view the big picture

If you click on each PHP file, you can also see the unit test coverage of each file, such:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP development essential PHP continuous integration tool introduction (on) "href ="/picshow/index595838.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095310397.jpg "/>
▲Click to view the big picture

From this, we can see the unit test coverage of the called method in each PHP file, and the specific code lines that have been overwritten by the unit test, which ones have not been overwritten (Green indicates that they have been overwritten, orange indicates that they have not been overwritten), such:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP development essential PHP continuous integration tool introduction (on) "href ="/picshow/index595839.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095310154.jpg "/>
▲Click to view the big picture

PHP CodeSniffer

PHP CodeSniffer is a PHP code style detector. It checks the code style of the application based on the preset PHP encoding style and rules, and has built-in ZEND and PEAR encoding style rules, of course, developers can also customize them. The Project address is http://pear.php.net/package/php_codesniffer/redirected. the installation steps are as follows:

 
 
  1. sudo pear install PHP_CodeSniffer  
  2. phpcs --standard=Zend c:phpcode 

The recommended Zend code style standard is specified after phpcs-standard, and the last parameter is the directory of the PHP file to be checked. After running, check one of the following:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP CodeSniffer "href ="/picshow/index595841.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095310674.jpg "/>
▲Click to view the large image

PHP Depend

PHP Depend (http://pdepend.org/) is a tool for static code analysis in PHP. It can be used to check the code size and complexity in your PHP project. The installation method is as follows:

 
 
  1. sudo pear channel-discover pear.pdepend.org  
  2. sudo pear install pdepend/PHP_Depend-beta 

An example is as follows:

Pdepend -- jdepend-xml = ../jdepend. xml -- jdepend-chart = ../dependencies. svg -- overview-pyramid = ../overview-pyramid.svg

An XML file and two SVG graphics files are generated above. The XML file illustrates the dependency call (reference) of various PHP files in the project and the code lines of each method, function, and Class. An example is as follows:

 
 
  1. <?xml version=”1.0” encoding=”UTF-8”?>  
  2. <metrics noc=”3” nof=”0” noi=”0” nom=”6”>  
  3. <package name=”+global” noc=”17” nof=”0” noi=”0” nom=”237”>  
  4. <class name=”data_container”nom=”55”>  
  5. <file name=”/home/case-study/libs/data/container.php”/>  
  6. </class>  
  7. <class name=”data_download” nom=”10”>  
  8. <file name=”/home/case-study/libs/data/download.php”/>  
  9. </class> 

The noc indicates the row book of the class code. nof indicates the number of lines of the function code, noi indicates the number of lines of the interface code, and nom indicates the number of lines of the method code.

Next, let's take a look at the generated SVG image, as shown below:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP CodeSniffer "href ="/picshow/index595842.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095310442.jpg "/>

This figure shows the dependency measurement in the project. The basic theory is derived from the measurement of module dependency and stability in software described in Robert C. Martin's thesis (http://www.objectmentor.com/resources/articles/oodmetrc.pdf. The following concepts are mentioned:

Afferent Couplings (Ca)

Depends on the number of other packages of the analyzed package, used to measure the responsibility of pacakge.

Simply put, there are several other packages or modules that call the analyzed packages or modules.

Efferent Couplings (Ce)

The number of other packages that the class of the analyzed package depends on, which is used to measure the independence of the package.

That is, the number of other packages it calls.

Abstractness ()

The ratio of the abstract class and interface in the analyzed package to the number of all classes in the package. The value range is 0-1. If the value is 0, it indicates that the package does not contain any abstract classes. Some classes only implement logical methods. If the value is 1, only the abstract classes or interfaces are included in the package.

Instability (I)

I = Ce/(Ce + Ca), used to measure the instability of the package. The value range is 0 to 1. I = 0 indicates the most stable, I = 1 indicates the most unstable.

Distance (D)

Used to measure the balance between the stability and abstraction of a package. As you can see, the ideal situation is that A + I is closer to 1, which can achieve the optimal balance between abstraction and stability.

In addition, we will introduce the meaning of another graph generated in php depend, as shown in the following figure:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'style = "cursor: hand "border =" 1 "alt =" PHP CodeSniffer "href ="/picshow/index595844.shtml "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095311587.jpg "/>

In this figure, the top ANDC represents the average number of classes inherited from other classes, that is, the number of classes in the project inherits from other classes; and AHH represents the number of layers inherited from other classes. CILS is the total number of times the method is called, and FANOUT is the number of types referenced by the class. CYCLO is the complexity of the circle (for the analysis of the complexity of the circle, please refer to (http://en.wikipedia.org/wiki/Cyclomatic_complexity ). LOC indicates the number of lines of code, NOM indicates the number of methods in the project, NOC indicates the number of classes in the project, and NOP indicates the number of packages in the project.

Based on the division rules marked in, you can calculate the relevant data. For more details, see the php depend Manual (http://pdepend.org/documentation/handbook/reports/overview-pyramid.html.


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.