php - 创建客户的PHP单元测试问题
问题描述
我的单元测试有一些问题。如果测试即将从我的数据库表中获取任何内容,我的 unittest 就可以完美运行。但是,如果我应该创建一个客户的示例,我对我应该如何做到这一点有疑问。
这是我的 getCustomer 测试的示例:
解决方案
尝试这样的事情:
<?php
$controller = new Veosoft_Controller();
$_REQUEST = [
'displayName' => 'meh',
'firstname' => 'Kristian',
'lastname' => 'Pedersen',
];
$controller->createCustomer();
// then somehow get the last insert ID?
$customer = $controller->getSpecificCustomer($customerId);
$this->assertEquals($customer->id, $customerId);
$this->assertEquals($customer->firstname, $firstName);
$this->assertEquals($customer->lastname, $lastName);
当然,如果您只是嘲笑 DB 类本身会更好吗?
推荐阅读
- sql - Groovy + Oracle sql,如何同时创建表和传递变量
- javascript - 为 Here 地图标记添加进度条
- php - Yii2 高级 + docker-compose + nginx + certbot:子域中的错误 403
- python - 无法安装uwsgi。我有错误:命令出错,退出状态为 1:
- java - 为什么我的 MCreate Java Minecraft mod 无法编译?
- html - 无法设置标签图标
- c# - 使用 TextBoxFor 更改模型字段并将模型传递给控制器
- swift - AVFoundation 使用 Swift 切换按钮更改相机
- shell - 通过 .sh 文件传递 clrsh 命令时,文件行未完全解析
- javascript - 子文本不显示在 React Native 的文本组件中