本文实例讲述了PHP单元测试配置与使用方法。分享给大家供大家参考,具体如下:
php与其他语言不太一样,单元测试需要自己安装和配置,相对麻烦一点,不过单元测试对于提高库的稳定性和健壮性还是非常给力的,下面教大家怎么配置PHP单元测试
注意:php需升级到7.1版本以上
$ 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 --version PHPUnit x.y.z by Sebastian Bergmann and contributors.
composer global require phpunit/phpunit
<phpunit bootstrap="vendor/autoload.php"> <testsuites> <testsuite name="service"> <directory>tests</directory> </testsuite> </testsuites> </phpunit>
如我的phpunit本地的路径为/usr/local/bin/phpunit
如我的phpunit包本地的路径为/Users/chenqionghe/.composer/vendor/phpunit
<?php use Eoffcn\Utils\Arrays; use PHPUnit\Framework\TestCase; /** * Array测试用例 * Class ArraysTest */ class ArraysTest extends TestCase { public function testGet() { $array = [ 1 => [ 'b' => [ 'c' => 'cqh' ] ], 2 => [ 'b' => [ 'c' => 'cqh' ] ] ]; $this->assertEquals('cqh', Arrays::get($array, '1.b.c')); } }
Phpstorm方式,当前测试类右键Run即可
命令行的方式,进行项目目录执行
phpunit tests/ArraysTest.php
phpstorm方式
命令行方式,命令行下进入当前项目执行
phpunit
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP错误与异常处理方法总结》、《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》及《php优秀开发框架总结》
希望本文所述对大家PHP程序设计有所帮助。
本文实例讲述了PHP设计模式:原型模式Prototype。分享给大家供大家参考,具体如...
在上篇文章给大家介绍了 javascript正则表达式和字符串RegExp and String(一)...
一、问题描述 如何在内核中操作某个文件? 问题 二、操作函数 1. 分析 在用户态,...
以下都是小旭大一下学期在家上网课的时候一份份手写搞成图片粘进word里面的现在...
% '********************************************************** '*智能脏话过...
在jsp页面实现显示当前的日期时间,我们可以用一下两种方式实现: 1. 通过在jsp...
TabLayoutMediator的坑 问题描述 问题分析 ViewPager2翻页的监听 TabLayout选择T...
挑战: 将字符串中的字符 、、、 (双引号), 以及 (单引号)转换为它们对应的 ...
文章目录 1. 集合成员资格 2. 集合的比较 3. 空关系测试exist、not exist 4. 重...
1.JSP代码: 复制代码 代码如下: %-- Document : Application Created on : 2009...