Version Details
PHP: 5.3
PHPUnit
ThinkPHP 3.1.3
IDE: PHPStorm 10 (recommended)
Configuring PHPUnit in PHPStorm
See the blog post:
http://blog.coinidea.com/web开发/php-1088.html
ThinkPHP Deployment
Official code download:
http://www.thinkphp.cn/down.html
Site initialization:
http://www.thinkphp.cn/info/60.html
Test Cases
In this example, the index.php in the root directory is configured as follows:
| |
After the first visit, the following directory structure is generated:

Create a new folder named “Testcase” in the example site.
Testing the Model
Create HelloModel.class.php:
| |
Create a Test.php file in the Test folder as the PHPUnit test file. Note that you need to require ThinkPHP to initialize the framework environment. Also, in Think.class.php, modify the
start() function by changing App::run() to !APP_PHPUNIT && App::run();
This distinguishes between site runtime and test case execution.

| |
Add a test case in TestSayHello:
| |
Testing the Action
Modify IndexAction.class.php as follows:
| |
Browser access to Index:

Add a test case in TestSayHello:
| |
Results
Running Test.php produces the following result:

Tests passed. At this point, unit testing has been successfully added to ThinkPHP.
poisonbian 2016/05/10 14:57
I tried following this guide and found that the model couldn’t be used, and custom functions in the Common directory were not loaded. After some investigation, I think adding the APP_PHPUNIT check in Think.class.php is not ideal. It would be better to add it in App.class.php instead: !APP_PHPUNIT && App::exec();