2

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 Answer 1

5

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_');
Sign up to request clarification or add additional context in comments.

1 Comment

If the Zend Framework directory is not in your include path, put it at the beginning of the require_once above: require_once PATH_TO_ZEND . '/Zend/Loader/Autoloader.php';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.