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.git
To 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.