This article mainly introduces about thinkphp3.2.3 how to use Think-phpunit to carry on unit test introduction, have certain reference value, now share to everybody, need friend can refer to
Problem description
thinkphp3.2.3 officially does not provide the tools for unit testing. As the project grows, the unit tests have to be put on the agenda to ensure the robustness of the code. In practice, https://github.com/snowair/think-phpunit
it is a good choice, but there are const
undefined errors during use. The specific error message is:syntax error, unexpected 'const' (T_CONST),
Problem analysis
const
Keyword hints syntax error, stating that the current PHPUNIT
does not support this syntax, review Official document Discovery, const
for php5.3
new referenced functionality. So the root cause should be PHPUNIT
the version is too low to cause.
description of the official address of the Const definition constant: Http://php.net/manual/zh/lang
...
We looked at vender\snowair/composer.json
the following code found:
"Require": { "php": ">=5.4", "Phpunit/phpunit": "^4.7" }
That is, phpunit
the request version is >=4.7 && <5.0
. The cause of the problem is confirmed. phpunit
keyword error caused by a low version.
Workaround:
Refer to php composer
the VCS
version control section to modify phpunit
the version number.
fork
The original project to its own warehouse. For example fork
, after my project address is: https://github.com/callme119/think-phpunit
.
https://github.com/callme119/think-phpunit
Composer.json file in PHPUnit, change the version of^5.0
Modify the VCS section of the project reference. Add repositories
properties.
For example, my project reference, modified to:
{ "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/
...
Summarize
If you just want to use it properly snowair/think-phpunit
, see https://github.com/callme119/think-phpunit
install it.
If you are a version of another project, see this article, after using GitHub to fix it, and in your project composer.json
, add repositories
properties to indicate a specific warehouse.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!