Analysis of the official Automation test method of PHP (I.)

Source: Internet
Author: User
Tags ini php language variables php script regular expression

Introduction: This article will be from a tester's perspective on the official PHP automated testing methods, automated test framework structure, as well as specific implementation of the analysis and research. Give the reader a practical example of how PHP implements an effective automated test to ensure that its code is of high quality. By reading this article, the reader can learn how to automate the automated test method and implementation of PHP, and apply this automated test method to its own development process to improve the quality of code functionality.

A brief introduction to the official automated test method of PHP

The following is an example of an analysis of the LINUX system platform based on the latest official version of PHP 5.2.8 's source code. First look at the PHP Automated test script PHPT script.

Automated test Script PHPT sample

PHP's test script is a ". Phpt" suffix, containing test,file,expect and other paragraphs of the file, referred to as PHPT. In each paragraph, Test,file,expect is the basic paragraph, and each test script must include at least three paragraphs. Where the test section can be used to fill in the name of the testing case; The FILE segment is a test case implemented by a PHP script; The EXPECT segment is the expected value of the test case. In the running of a test case, PHP uses the tested PHP executable object to run the test cases in the FILE section, using the actual results to compare the expected values listed in the EXPECT section of the test case, and if the actual and expected values are the same, the test passes, and if it is inconsistent, the test fails.

Table 1 lists the commonly used paragraph names and their corresponding fill descriptions.

Table 1. Paragraph descriptions in the PHP test script

Paragraph name Fill content Note
TEST Test Case Name Required paragraph
ARGS Input parameters for the FILE segment Optional paragraph
SKIPIF Skip the condition of this test Optional paragraph
POST POST variables for incoming test scripts Select the paragraph to fill. If you use POST segments, it is recommended that you use SKIPIF segments, such as:

--skipif--

<?php if (php_sapi_name () = = ' cli ') echo ' skip ';?>

Get Get variables for incoming test scripts Select the paragraph to fill. If you use POST segments, it is recommended that you use SKIPIF segments, such as:

--skipif--

<?php if (php_sapi_name () = = ' cli ') echo ' skip ';?>

Ini INI settings applied to the test script Select the paragraph to fill. such as Foo=bar. The value can be obtained by function Ini_get (string name_entry).
FILE Test Script Statement Required paragraphs. Script statements that are written in the PHP language. The results of its execution will be compared with the expected value of the expect* segment.
EXPECT Expected value of the test script Required paragraph
Expectf The expected value of the test script, using the format of the function sscanf () to express the expected value Variants of the EXPECT segment
Expectregex The expected value of the test script, the expected value can be expressed in the regular expression Variants of the EXPECT segment

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.