phpunit骨架生成器找不到扩展类 [英] Phpunit skeleton generator cannot find extends class

查看:89
本文介绍了phpunit骨架生成器找不到扩展类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Zend Framework的应用程序,我试图使用phpunit生成测试用例的框架. phpunit似乎找不到我要为其生成的类的父类:

I have an application based on the Zend Framework that I am trying to use phpunit to generate skeletons for the test cases. Phpunit can't seem to find the parent classes of the classes I am trying to generate for:

phpunit --skeleton-test Default_Model_Person ../application/models/Person.php 
PHPUnit 3.5.11 by Sebastian Bergmann.

PHP Fatal error:  Class 'X1_Db_Table_Auditable' not found in /path/to/application/models/Person.php on line 3

Fatal error: Class 'X1_Db_Table_Auditable' not found in /path/to/application/models/Person.php on line 3

所以我有例如application/models/Person.php

So I have for example application/models/Person.php

 <?php

class Default_Model_Person extends X1_Db_Table_Auditable
{       

在library/X1/Db/Table/Auditable.php中是

In library/X1/Db/Table/Auditable.php is

<?php

class X1_Db_Table_Auditable extends X1_Db_Table
{

...

我还有其他手写的测试用例,证明phpunit可以在此应用程序上运行而不会出现问题.我也尝试过使用--bootstrap指定引导文件,并使用--configuration指定配置,以确保应该找到库的路径,但是我似乎无法使它正常工作(结果与以上).如何获得phpunit查找的库类以生成框架?

I have other test cases written by hand that phpunit can run on this application without a problem. I have also tried specifying the bootstrap file with --bootstrap and the config with --configuration to make sure that the path to the library should be found, but I can't seem to get this to work (the result is the same as above). How can I get this library class to be found by phpunit to generate the skeleton?

我对PHP,phpUnit和Zend相当陌生,所以请原谅我的初学者问题;) 预先感谢!

I am fairly new to PHP, phpUnit and Zend, so please forgive my beginner questions ;) Thanks in advance!

推荐答案

您需要设置一个自动加载器,以允许PHP在被引用时(通常在bootstrap.php中)导入X1和任何其他类.

You need to set up an autoloader to allow PHP to import the X1 and any other classes when referenced, typically in bootstrap.php.

require_once 'Zend/Loader/AutoLoader.php';
$autoloader = Zend_Loader_AutoLoader::getInstance();
$autoloader->registerNamespace('X1_');

这篇关于phpunit骨架生成器找不到扩展类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆