【问题标题】:Error running testAction on CakePHP 2.4.6 error Undefined index: REMOTE_ADDR在 CakePHP 2.4.6 上运行 testAction 时出错 错误未定义索引:REMOTE_ADDR
【发布时间】:2017-07-31 23:26:29
【问题描述】:

我正在尝试为 CakePHP 2.4.6 控制器编写测试。我正在关注文档,该文档建议我可以使用 testAction 对产品输出进行测试。

<?php
App::uses('UsersController', 'Controller');      

class UsersControllerTest extends ControllerTestCase {
    public $fixtures = array(
      'app.user',
    );

    public function testIndex() {
      $result = $this->testAction('/users/view/10');
      debug($result);
    }
  }

当我运行此测试时,我收到以下错误消息:

UsersControllerTest::testIndex
Undefined index: REMOTE_ADDR

请您建议我可以做些什么来初始化控制器并访问其单元测试方法。

【问题讨论】:

  • 你会发布 UsersController 的索引方法吗?可能有问题!

标签: unit-testing cakephp cakephp-2.0


【解决方案1】:

发现问题,它在自定义授权组件中,由于某种原因未包含在堆栈跟踪中。它试图使用 $_SERVER['REMOTE_ADDR'],在调用 testAction 时不能设置。

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 2017-07-16
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多