Get the App
SLTechnology News&Howtos  ›  Development  › 

Configuration and usage of PHP Unit Test

Shulou Source: shulou.com Published: 2022-06-03 06:14:35 10月30日 Update

This article will explain in detail about the configuration and use of PHP unit testing, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article. Php is quite different from other languages. Unit testing needs to be installed and configured by itself, which is relatively troublesome. However, unit testing is very useful for improving the stability and robustness of the library. Here is how to configure PHP unit tests.

Note: php needs to be upgraded to version 7.1 or above

Configuration instructions 1. Global installation phpunit command script

$wget https://phar.phpunit.de/phpunit-7.0.phar$ chmod + x phpunit-7.0.phar$ sudo mv phpunit-7.0.phar / usr/local/bin/phpunit$ phpunit--versionPHPUnit x.y.z by Sebastian Bergmann and contributors.

two。 Global installation installation phpunit code

Composer global require phpunit/phpunit

3. Create phpunit.xml and put it in your project root. This file is a configuration file that phpunit will read by default:

Tests

4. Configure the phpstorm unit phpunit.phar path, Languages & Frameworks > PHP > PHPUinit

For example, my local path to phpunit is / usr/local/bin/phpunit

5. Configure unit test class hints, Languages & Frameworks > PHP > include path

For example, the local path of my phpunit package is / Users/chenqionghe/.composer/vendor/phpunit

6. The test class that writes 1.Class as Demo for unit tests is DemoTest2. The test class inherits from PHPUnit\ Framework\ TestCase3. Testing method

It must be a public permission, which usually starts with test, or it can be marked with @ test to identify it within the test method. Assertion methods such as assertEquals () are used to assert the match between actual and expected values.

Tags: Tests units configurations methods commands methods globals content files more paths projects usage introductory tutorials techniques tutorials articles knowledge articles operations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Shulou Information Apple Huawei