PHPUnit Integrated thinkphp Library

Source: Internet
Author: User
Tags netbeans
Project Address: Https://github.com/web3d/TPUnit

Tpunit

thinkphp phpunit Framework integration, based on TP3.2, recommended PHP 5.4 or more environment.

Unit testing should be a way to improve the quality of PHP coding, but there should not be many PHP teams using unit tests to improve the development process, not to mention TDD development methods.

It is undeniable that the thinkphp framework in the domestic PHP circle "to High" status, so only this integration attempt, but also in the team to carry out relevant practices.

1. Initial Configuration

To reduce the cost of learning, it is recommended to use an IDE like NetBeans to set PHPUnit's basic environment.

The NetBeans interface gives you a direct view of some of the core concepts of the PHPUnit use process.

    • NetBeans-based PHPUnit environment configuration
    • git clone git@github.com:web3d/TPUnit.gitTo Thinkphp's Vendor directory

2. Start

Copy the bootstrap.php file from the demo directory in the Tpunit to your tests directory.

In the previous step of the configuration process, there is a "use boot" place remember to check and specify the directory of the bootstrap.php file.

Due to the thinkphp in the framework of the pit father's. class.php suffix, the class file to be tested cannot be directly specified in NB to automatically generate a test method skeleton.

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

3. Supported Features

3.1 Basic UnitTest

The most classic examples are:

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

3.2 DB UnitTest

See the Project Demo catalogue/demo/application/common/model/urlmodeltest.php file.

Dbunit is mainly composed of four assertions, which currently support TP support for these four assertions:

    • Assert the number of data rows in the table
    • Assert the state of a table
    • Making assertions about the results of a query
    • Assert the state of multiple tables

For details, please see https://github.com/web3d/TPUnit/blob/master/demo/Application/Common/Model/UrlModelTest.php

where {{%url}} is the table name prefix substitution scheme introduced from the YII2 framework, {{and}} is the table name qualifier and% is the table name prefix placeholder.

The above describes the PHPUnit integrated thinkphp Library, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.