【问题标题】:Using Mango within a unit test in Kohana在 Kohana 的单元测试中使用 Mango
【发布时间】:2015-01-24 03:01:17
【问题描述】:

所以我将我们的应用程序切换为使用 Mango 而不是 Kohana 中的内置 ORM。我已经切换了所有必要的应用程序代码以按预期工作,但是当我们的 CI 服务器运行我们的单元测试时,我收到“找不到类 'Mango'”错误。

提供的测试被简化了,但我在 UnitTest 中使用的样式与我在常规 GET 请求中使用它们的方式完全相同。它在我执行 GET 时有效,但单元测试失败。现在希望不相关,我无法在本地重现此内容,但无法让单元测试在我们的 CI 服务器上运行。

我的猜测是我没有正确加载模块,但就像我说的,它在应用程序中正常工作,只有我的单元测试失败(出现致命错误)。

应用程序/类/模型/用户.php

class Model_User extends Mango {

    protected $_fields = array(
        'user_id'       => array('type' => 'string', 'required'=>TRUE),
        'first_name'    => array('type' => 'string', 'required'=>TRUE),
        'last_name'     => array('type' => 'string', 'required'=>TRUE),
    );
}

应用程序/测试/UserTest.php

Class UserTest extends Unittest_TestCase
{
    public function testUserCreation()
    {
        $user_data = array(
            "user_id"       => "1234asdf",
            "first_name"    => "Test",
            "last_name"     => "User",
        );

        $new_user = Mango::factory("User", $user_data);

        $this->assertEquals($user_data, $new_user->as_array());
    }
}

编辑:这是我引入的 Mango 模块的链接:https://github.com/Wouterrr/MangoDB

【问题讨论】:

    标签: php mongodb continuous-integration kohana


    【解决方案1】:

    如果有人通过谷歌偶然发现这个问题,我解决了这个问题。看起来我们的应用程序 nginx 配置比 CLI 更好地处理大写。将“Mango”更改为“mango”后,我看到错误消息更改为找不到它的父类(出于相同的大小写原因)。虽然我想我可以改变所有的大小写,但 Kohana 有一个处理大小写问题的函数,所以在 application/bootstrap.php 中,你只需要运行以下两个:

    spl_autoload_register(array('Kohana', 'auto_load'));
    spl_autoload_register(array('Kohana', 'auto_load_lowercase'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多