0

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

我正在尝试使用 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 为真”。

4

1 回答 1

0

I was able to find enough information in $this->vars to find the record with my Model. Everything tests out now.

于 2012-06-08T18:54:15.103 回答