thinkphp3.2.3 How to use Think-phpunit to introduce unit tests

Source: Internet
Author: User
Tags autoload
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

constKeyword 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. phpunitkeyword error caused by a low version.

Workaround:

Refer to php composer the VCS version control section to modify phpunit the version number.

    1. forkThe original project to its own warehouse. For example fork , after my project address is: https://github.com/callme119/think-phpunit .

    2. https://github.com/callme119/think-phpunitComposer.json file in PHPUnit, change the version of^5.0

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

    1. If you just want to use it properly snowair/think-phpunit , see https://github.com/callme119/think-phpunit install it.

    2. 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!

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.