【问题标题】:Autoloading phpunit test classes from another module in zf2从 zf2 中的另一个模块自动加载 phpunit 测试类
【发布时间】:2013-04-13 10:13:11
【问题描述】:

我正在尝试将另一个模块中的测试类重用到我当前的模块中。我的目录结构如下:

Home/
    Module.php
    config/
        module.config.php
    src/
        Home/
            <code files>
    test/
        phpunit.xml
        bootstrap.php
        HomeTest/
            <test code files>
Loader/
    Module.php
    config/
        module.config.php
    src/
        Loader/
            <code files>
    test/
        phpunit.xml
        bootstrap.php
        LoaderTest/
            <test code files>

我在 Loader/test/ 文件夹中运行 phpunit 测试类,需要重用 Home/test/Hometest/Model 中的类。

我尝试在我的引导文件中使用它:

AutoloaderFactory::factory(
   array(
     'Zend\Loader\StandardAutoloader' => array(
       'autoregister_zf' => true,
       'namespaces' => array(
         __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
        'HomeTest' => __DIR__ . '/Home/test/HomeTest',
       ),
     ),
   )
);

上述加载机制出现此错误:

Fatal error: Class 'HomeTest\Model\UserTableTest' not found

【问题讨论】:

    标签: zend-framework phpunit zend-framework2


    【解决方案1】:

    您需要从Loader/test 重新导航到Home/test,试试这个...

    AutoloaderFactory::factory(
        array(
            'Zend\Loader\StandardAutoloader' => array(
                'autoregister_zf' => true,
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
                    'HomeTest' => __DIR__ . '/../../Home/test/HomeTest',
                ),
            ),
        )
    );
    

    【讨论】:

      猜你喜欢
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 2013-01-13
      • 1970-01-01
      • 2015-09-05
      相关资源
      最近更新 更多