英文:
Php unit test problem with create customer
问题
我遇到了一些关于我的单元测试的问题。
如果测试是关于从我的数据库表中获取任何内容,那么我的单元测试就能够完美工作。
但是,如果我应该创建一个示例客户,我在如何做到这一点方面遇到了问题。
这是我的getCustomer测试的一个示例:
英文:
Im having some problems with my unittest.
My unittest works perfect if the test is about to get anything from my datbase table.
But if I should create example a customer, im having isuses with how I should do that.
Here is an example of my getCustomer test:
答案1
得分: 0
尝试类似以下方式:
$controller = new Veosoft_Controller();
$_REQUEST = [
'displayName' => 'meh',
'firstname' => 'Kristian',
'lastname' => 'Pedersen',
];
$controller->createCustomer();
// 然后以某种方式获取最后插入的ID?
$customer = $controller->getSpecificCustomer($customerId);
$this->assertEquals($customer->id, $customerId);
$this->assertEquals($customer->firstname, $firstName);
$this->assertEquals($customer->lastname, $lastName);
当然,最好的方法是模拟DB类本身?
英文:
Try something like this:
<?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);
Of course it would be better if you just mocked the DB class itself?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论