PHPUnit integrates ThinkPHP Library

Source: Internet
Author: User
: This article describes how to integrate ThinkPHP library with PHPUnit. For more information about PHP tutorials, see. Project address: https://github.com/web3d/TPUnit

TPUnit

ThinkPHP PHPUnit framework integration. based on TP3.2, we recommend that you use a PHP 5.4 or later environment.

Unit testing should be the solution to improve PHP coding quality, but few PHP teams should use unit testing to improve the development process, not to mention TDD development methods.

It is undeniable that the ThinkPHP framework has a "highest" position in the domestic PHP circle. Therefore, this integration attempt was made and related practices were also carried out in the team.

1. initial configuration

To reduce learning costs, it is recommended that you use an IDE like Netbeans to set the basic PHPUnit environment.

Through the Netbeans operation interface, you can directly understand some core concepts of the PHPUnit usage process.

  • PHPUnit environment configuration based on Netbeans
  • git clone git@github.com:web3d/TPUnit.gitTo the ThinkPHP Vendor Directory

2. start

Copy the bootstrap. php file under the demo directory in TPUnit to your tests directory.

During the configuration process in the previous step, remember to check and specify the Directory of the bootstrap. php file in the "use guide" area.

Due to the suffix of. class. php in the ThinkPHP framework, the class file to be tested cannot be directly specified in NB to automatically generate the testing method skeleton.

You can temporarily rename the file to remove. class and then use NB to quickly generate the test code skeleton.

3. Supported features

3.1 Basic UnitTest

Classic example:

See the above reference configuration document: Netbeans-based PHPUnit environment configuration

3.2 DB UnitTest

See the demo directory/demo/Application/Common/Model/UrlModelTest. php in this project.

DBUnit consists of four assertions. Currently, TP supports these four assertions:

  • Assert the number of data rows in the table
  • Assert the table status
  • Assert the query result
  • Assert the status of multiple tables

See https://github.com/web3d/TPUnit/blob/master/demo/Application/Common/Model/UrlModelTest.php for details

Here, {% url} is the table name prefix replacement solution introduced from the Yii2 framework. {and} are the table name delimiters, and % is the table name prefix placeholder.

The above introduces the PHPUnit integration ThinkPHP library, including the content, hope to be helpful to friends who are interested in PHP tutorials.

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.