首页 > 解决方案 > 创建客户的PHP单元测试问题

问题描述

我的单元测试有一些问题。如果测试即将从我的数据库表中获取任何内容,我的 unittest 就可以完美运行。但是,如果我应该创建一个客户的示例,我对我应该如何做到这一点有疑问。

这是我的 getCustomer 测试的示例:

标签: phpunit-testingphpunit

解决方案


尝试这样的事情:

<?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 类本身会更好吗?


推荐阅读