Phpunit skeleton generator cannot find extends class

梦想与她 提交于 2019-12-07 21:41:53

问题


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

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

 <?php

class Default_Model_Person extends X1_Db_Table_Auditable
{       

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

<?php

class X1_Db_Table_Auditable extends X1_Db_Table
{

...

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?

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


回答1:


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_');


来源:https://stackoverflow.com/questions/5099179/phpunit-skeleton-generator-cannot-find-extends-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!