1. Environment
System: windows10
WampServer: wampserver2.2e-php5.3.13-httpd2.2.22-mysql5.5.24-32b.exe
PHP: 7.1.15
How Intellij IDEA supports php, please refer to Intellij IDEA configure Vue support .
Second, PHPunit configuration
1. Download PHPunit.phar:
Linux:
➜ wget -O phpunit https://phar.phpunit.de/phpunit-7.phar ➜ chmod +x phpunit ➜ ./phpunit --version
Window:
Download phpunit-7.phar to your php.exe directory, and create a new overwrite batch script phpunit.cmd file with the following contents:
@ECHO OFF php % ~ dp0phpunit- 7 .phar% *
For Cygwin or MingW32 (eg TortoiseGit) shell environments, instead, save the file as phpunit
(without .phar
extension) and make it executable with chmod 775 phpunit. Reference: Install PHPUnit
Set environment variables:
Execute: phpunit --version
PS: https://phpunit.de/getting-started/phpunit-7.html
3. New test project
1. Take the Yii project as an example, create a test directory tests in the protected directory. Create the bootstrap.php file in the tests directory.
<?php define('YII_ENV', 'test'); defined('YII_DEBUG') or define('YII_DEBUG', true); require_once(__DIR__ . '/../../../yiisoft/yii2/Yii.php'); $config = require '../config/web.php'; (new Application($config));
The bootstrap file is used to load the runtime of the test case. Each project has the loading configuration of each project, which depends on the specific project.
2. Write test cases
<?php use PHPUnit\Framework\TestCase; class MyTest extends TestCase{ public function testEmpty(){ $stack = []; $this->assertEmpty($stack); return $stack; } }
In the test case, it is necessary to pay attention to whether the namespace still needs to be specified. Reference: Writing PHPUnit tests .
3. Configure PHPunit
1. Check Default bootstrap file and select the bootstrap.php file you created above.
2. In the testEmpty method body of your MyTest.php file, right-click and select Execute.
If you want to do it manually:
D:\IdeaProjects>phpunit --bootstrap D:\IdeaProjects\test\protected\tests\bootstrap.php MyTest D:\IdeaProjects\test\protected\tests\examples\MyTest.php PHPUnit 7.1.5 by Sebastian Bergmann and contributors. . 1 / 1 (100%) Time: 367 ms, Memory: 10.00MB OK (1 test, 1 assertion)
PS:
http://www.yii-china.com/post/detail/460.html
http://tangl163.iteye.com/blog/2288538
https://phpunit.readthedocs.io/zh_CN/latest/installation.html
https://phpunit.readthedocs.io/zh_CN/latest/index.html
https://phpunit.de/getting-started/phpunit-7.html