###测试文件例-数组篇
~~~
<?php declare(strict_types = 1);
namespace msqphp\test\base\arr;
// 继承测试类
class ArrTest extends \msqphp\test\Test
{
public function testStart() : void
{
// 由于对应的测试类为Arr基类,全部为静态函数,所以在此处赋类值
$this->class('\msqphp\base\arr\Arr');
// 测试当前对象
$this->testThis($this);
}
// 测试所有数组排序函数
public function testSort() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// args,此处为待排序数组
$args = [1,2,465,47,136,49,136,49,13,496,31,74,64,46];
// result,此处为结果,即排序后的数组
$result = [1,2,13,31,46,47,49,49,64,74,136,136,465,496];
// 因为参数与结果,所以统一赋值.
$this->args($args)->result($result);
// 分辨测试各个函数
$this->method('bubbleSort')->test();
$this->method('insertSort')->test();
$this->method('quickSort')->test();
$this->method('selectSort')->test();
}
public function testSetAndGet() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// args,此处为数据数组
$args = [
'liming'=>['name'=>'liming','age'=>12],
'wangwu'=>['name'=>'wangwu','age'=>27],
'zhanghai'=>['name'=>'zhanghai','age'=>50],
'changni'=>['name'=>'changni','age'=>34],
];
// 由于该函数为值引用传递,有些bug,所以人工测试
\msqphp\base\arr\Arr::set($args, 'changni.age', 57);
// 结果不为57,报错
if ($args['changni']['age'] !== 57 || \msqphp\base\arr\Arr::get($args, 'changni.age') !== 57) {
echo '该函数由于值为应用传递,所以采用非正常测试,此时测试失败';
throw new \msqphp\test\TestException('测试失败');
}
echo '该函数由于值为应用传递,所以采用非正常测试,此时测试成功';
}
public function testRandom() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// 数组范围,1-19的单数
$args = [1,3,5,7,9,11,13,15,17,19];
// 方法,参数,结果以函数形式判断true通过,false则失败报错
$this->method('random')->args($args)->result(function (int $value) use ($args) : bool {
return in_array($value, $args);
})->test();
// 测试当数组中取多个值,
$num = random_int(1, 7);
$this->method('random')->args($args, $num)->result(function (array $value) use ($args, $num) : bool {
$bool = true;
$bool = count($value) === $num && $bool;
foreach ($value as $number) {
$bool = $bool && in_array($number, $args);
}
return $bool;
})->test();
}
}
~~~
- 序言
- 框架
- 框架获取
- 框架安装
- 应用结构
- 框架结构
- 应用目录结构
- 框架流程
- 命名规范
- 核心思想
- 扩展
- 类组装
- 框架基类
- Arr
- Arr扩展函数
- Date基类
- Dir
- Dir基类扩展函数
- Dom基类
- File基类
- Str基类
- Str随机字符
- Str操作函数
- Str随机创建
- Html基类
- Header基类
- Filter基类
- 框架核心
- 路由
- 路由信息
- 路由安装样本
- 路由逻辑原理
- 路由方法匹配
- 路由分组
- 路由构建
- 路由限制
- 路由规则
- 路由多语,多主题
- 路由常量
- 路由扩展
- 路由例
- 路由真静态使用
- 智能加载
- Response基类
- 定时任务
- 框架主类
- 控制器
- model
- model样本
- model使用
- view
- view路径
- view方法
- view配置
- view使用
- view真静态
- view例
- view多主题
- 模版引擎
- 模版引擎之单句解析
- 模版引擎之foreach解析
- cache
- cache注意事项
- cache配置
- cache方法
- cache使用
- cache扩展
- cache处理类File配置
- cache处理类Apc,Apcu配置
- cache处理类memcache,memcached配置
- cookie
- session
- 框架扩展
- Upload类
- 测试
- 测试流程
- 测试文件编写
- 测试文件例-数组篇
- 测试类函数
- 测试类使用
- 测试注意事项
- 常用功能
- 读码须知
- 个人技巧或习惯
- 万能get,call,callStatic
- &&和||
- 变量值交换
- trait拼接
- 多语支持