【问题标题】:2 Unit test controllers to verify that action created new record2 单元测试控制器以验证操作是否创建了新记录
【发布时间】:2012-06-08 16:28:40
【问题描述】:

当我对成员控制器的注册操作进行单元测试时,如何断言在我的成员的测试数据库中创建了一条新记录?

我正在尝试使用 getLastInsertID,但我不知道如何加载 Member 模型来进行调用。

我已经对我的会员模型进行了包含注册和激活的测试,但是在我执行激活过程时出现了错误。我想在控制器中使用测试来验证是否可以注册新成员,然后使用两个测试激活。

更新 我将App::uses('Member', 'Model'); 添加到我的控制器测试中,并且还

  public function setUp() {
    parent::setUp();
    $this->Member = ClassRegistry::init('Member');
  }

在函数 testRegister 我有:

   $data = array(
      'Member' => array(
        'first_name' => 'Foo',
        'last_name' => 'Bar',
        'email' => 'foobar@example.org',
        'password' => 'password',
        'password_confirmation' => 'password',
        'security_question' => 0, // Your father's middle name?
        'security_answer' => 'Randolf the great',
      ),
    );
    $result = $this->testAction(
      '/Members/register',
      array('data' => $data, 'method' => 'post')
    );
    debug($result);

    $this->assertTrue($this->Member->validationErrors);
    $this->assertTrue($this->Member->getLastInsertId());

断言显示“无法断言 array() 为真”和“无法断言 null 为真”。

【问题讨论】:

    标签: php unit-testing cakephp


    【解决方案1】:

    我能够在$this->vars 中找到足够的信息来找到我的模型的记录。现在一切都在测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      相关资源
      最近更新 更多