首先需要确认你的php版本,以及该版本对应的phpunit的版本
主版本 | 初始版本 | PHP兼容性 | 支持 |
PHPUnit 8 | 2019年2月1日 | PHP 7.2, PHP 7.3, PHP 7.4 | 在2021年2月5日结束支持 |
PHPUnit 7 | 2018年2月2日 | PHP 7.1, PHP 7.2, PHP 7.3 | 在2020年2月7日结束支持 |
PHPUnit 6 | 2017年2月3日 | PHP 7.0, PHP 7.1, PHP 7.2 | 在2019年2月1日结束支持 |
PHPUnit 5 | 2015年10月2日 | PHP 5.6, PHP 7.0, PHP 7.1 | 在2018年2月2日结束支持 |
PHPUnit 4 | 2014年3月7日 | PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6 | 在2017年2月3日结束支持 |
安装phpUnit的phar档案包
安装完成后可以通过命令行phpunit 来操作phpunit相关命令测试
在网址https://phar.phpunit.de/ 查看你版本对应的phpunit的路径名称
比如我php版本是5.6, 我能使用的phpUnit版本是phpUnit5, 在上面的网址中我找到的最新的phpUnit5的版本是phpunit-5.7.9.phar 这个就是我本次要下载的phpUnit
wget https://phar.phpunit.de/phpunit-5.7.9.phar //下载phpUnit
chmod +x phpunit-5.7.9.phar //更改文件的可执行权限
sudo mv phpunit-5.7.9.phar /usr/local/bin/phpunit //增加命令行功能
测试phpUnit是否安装ok
phpunit --version (或者phpunit --help)
安装项目的phpunit依赖 使用composer
https://packagist.org/explore/ packagelist网站 输入phpunit 查询phpunit的所有composer库
使用composer引入phpunit并将phpunit放入项目的vendor中
通过上面的网址查看phpunit的库中都有什么版本 使用composer安装phpunit
composer require --dev phpunit/phpunit ^5
至此 phpunit安装完成