Php unit test问题:创建客户

huangapple go评论58阅读模式
英文:

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?

huangapple
  • 本文由 发表于 2020年1月7日 00:31:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定