系统: windows10php
WampServer: wampserver2.2e-php5.3.13-httpd2.2.22-mysql5.5.24-32b.exehtml
IDE: IntelliJ IDEA 2017.3.2mysql
PHP: 7.1.15web
Intellij IDEA 如何支持php请参考,IntellIJ IDEA 配置 Vue 支持。sql
1.下载PHPunit.phar:shell
Linux:bootstrap
➜ wget -O phpunit https://phar.phpunit.de/phpunit-7.phar ➜ chmod +x phpunit ➜ ./phpunit --version
Window:windows
下载phpunit-7.phar到你所在的php.exe目录下, 并新建外包覆批处理脚本 phpunit.cmd 文件,内容以下:yii2
@ECHO OFF php %~dp0phpunit-7.phar %*
对于 Cygwin 或 MingW32 (例如 TortoiseGit) shell 环境, 取而代之的是,把文件保存为 phpunit
(没有 .phar
扩展名),而后用 chmod 775 phpunit 将其设为可执行。参考:安装 PHPUnityii
设置环境变量:
执行: phpunit --version
PS: https://phpunit.de/getting-started/phpunit-7.html
1.以Yii 项目为例,在protected目录下建立一个测试目录tests。在tests目录下建立bootstrap.php文件。
<?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));
bootstrap文件是用来加载测试用例的运行时用的,各个项目有各个项目的加载配置,按具体项目而定。
2.编写测试用例
<?php use PHPUnit\Framework\TestCase; class MyTest extends TestCase{ public function testEmpty(){ $stack = []; $this->assertEmpty($stack); return $stack; } }
在测试用例中须要注意的是命名空间仍是须要指定的。参考:编写 PHPUnit 测试。
1. 勾选 Default bootstrap file ,并选择你上文新建的 bootstrap.php 文件。
2. 在你所在的 MyTest.php 文件 testEmpty 方法体中, 点击右键选择执行 。
若是你想手动执行:
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