Home >Backend Development >PHP Tutorial >Introduction to how to use think-phpunit for unit testing in thinkphp3.2.3
This article mainly introduces how to use think-phpunit for unit testing in thinkphp3.2.3. It has a certain reference value. Now I share it with you. Friends in need can refer to the
thinkphp3.2.3 officially does not provide unit testing tools. As the project grows, unit testing has to be put on the agenda to ensure the robustness of the code. After practice, https://github.com/snowair/think-phpunit
is a good choice, but const
undefined errors occurred during use. The specific error message is: syntax error, unexpected 'const' (T_CONST),
const
Keyword prompt syntax error, description The current PHPUNIT
does not support this syntax. After consulting the official documentation, we found that const
is a newly referenced function of php5.3
. So the root cause should be that the PHPUNIT
version is too low.
The official address description of const defined constants: http://php.net/manual/zh/lang...
Let’s checkvender\snowair/composer.json
The following code was found:
"require": { "php":">=5.4", "phpunit/phpunit": "^4.7" }
which requires the phpunit
version to be >=4.7 && <5.0
. The cause of the problem is now confirmed. Keyword error caused by phpunit
version being too low.
Refer to the VCS
version control section of php composer
and modify the version number of phpunit
.
fork
The original project to your own warehouse. For example, the project address after my fork
is: https://github.com/callme119/think-phpunit
.
The composer.json file in https://github.com/callme119/think-phpunit
, modify the version of phpunit to ^5.0
Modify The VCS part referenced by the project. Add repositories
attribute.
For example, my project reference, after modification, is:
{ "name": "topthink/thinkphp", "description": "the ThinkPHP Framework", "type": "framework", "keywords": ["framework","thinkphp","ORM"], "homepage": "http://thinkphp.cn/", "license": "Apache2", "authors": [ { "name": "liu21st", "email": "liu21st@gmail.com" } ], "require": { "php": ">=5.3.0" }, "autoload": { "classmap": ["Application","ThinkPHP/Library"] }, "autoload-dev": { "psr-0": { "": "test" } }, "repositories": [ { "type": "vcs", "url": "https://github.com/callme119/think-phpunit" } ], "require-dev": { "snowair/think-phpunit": "dev-master" }, "minimum-stability": "dev" }composer VCS official address: https://docs.phpcomposer.com/...Summary
If you just want to use
snowair/think-phpunit
normally, then please refer tohttps://github.com/callme119 /think-phpunit
just install it.If you have version problems in other projects, please refer to this article, use github to fix it, and add it to
composer.json
of your own project.repositories
Attribute to specify a specific repository.The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to traverse folders through php to obtain the image directory name and file name
The above is the detailed content of Introduction to how to use think-phpunit for unit testing in thinkphp3.2.3. For more information, please follow other related articles on the PHP Chinese website!