Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/03/2011, 10:39
Avatar de jerkan
jerkan
 
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Pregunta PHPUnit - Class 'xxx' not found

Hola,

estoy intentando ejecutar test unitarios con PHPUnit pero siempre me da el mismo error.
Estoy trabajando con MacOsX 10.6.6, PHP 5.3.2, PHPUnit 3.5.13 y Apache 2.0.63.

Siguiendo las instrucciones de http://www.zendcasts.com/unit-testin...punit/2009/06/ adapté mi código de la siguiente manera.

/tests/phpunit.xml
Código XML:
Ver original
  1. <phpunit bootstrap="./application/bootstrap.php" colors="true" processIsolation="true">
  2.     <testsuite name="MyApp">
  3.         <directory>./</directory>
  4.     </testsuite>
  5.    
  6.     <filter>
  7.         <whitelist>
  8.             <directory suffix=".php">../application/</directory>
  9.             <exclude>
  10.                 <directory suffix=".phtml">../application/</directory>
  11.                 <file>../application/Bootstrap.php</file>
  12.                 <file>../application/controllers/ErrorController.php</file>
  13.             </exclude>
  14.         </whitelist>
  15.     </filter>
  16.    
  17.     <logging>
  18.         <log type="coverage-html" target="./log/report" charset="UTF-8"
  19.        yui="true" highlight="true" lowUpperBound="50" highUpperBound="80" />
  20.         <log type="testdox-html" target="./log/testdox.html" />
  21.     </logging>
  22.    
  23. </phpunit>
/tests/application/bootstrap.php
Código PHP:
Ver original
  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3.  
  4. // Define path to application directory
  5. defined('APPLICATION_PATH')
  6.     || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
  7.  
  8. // Define application environment
  9. defined('APPLICATION_ENV')
  10.     || define('APPLICATION_ENV',
  11.         (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
  12.    
  13. // Ensure library/ is on include_path
  14. set_include_path(implode(PATH_SEPARATOR, array(
  15.     realpath(APPLICATION_PATH . '/../library'),
  16. )));
  17.  
  18. /** Zend_Application */
  19. require_once 'Zend/Application.php';
  20.  
  21. // Create application, bootstrap and run
  22. require_once './application/controllers/ControllerTestCase.php';
/tests/Application/Controllers/ControllerTestCase.php
Código PHP:
Ver original
  1. require_once 'Zend/Application.php';
  2. require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
  3.  
  4. abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
  5. {
  6.     /**
  7.      * @var Zend_Application
  8.      */
  9.     public $application;
  10.    
  11.     public function setUp()
  12.     {
  13.         $this->bootstrap = array($this, 'appBootstrap');
  14.         parent::setUp();
  15.         print_r(PHP_EOL . 'include_path: ' . get_include_path() . PHP_EOL);
  16.     }
  17.    
  18.     public function appBootstrap()
  19.     {
  20.         $this->application = new Zend_Application(APPLICATION_ENV,
  21.                                                   APPLICATION_PATH . '/configs/application.ini');
  22.         $this->application->bootstrap();
  23.     }
  24. }
El error que me da es el siguiente:
Código:
PHP Fatal error:  Class 'Zend_Controller_Action' not found 
in /Users/xxx/Documents/websites/quickstart/application/controllers/AccountController.php on line 4
Como no encuentra las clases de la librería Zend, pienso que es debido al include_path de PHP. Sin embargo, he comprobado que apunta a donde debe:
Código:
/Users/xxx/Documents/websites/quickstart/application/../library:
/Users/xxx/Documents/websites/quickstart/library:
/Users/xxx/Documents/websites/quickstart/library:
.:
/usr/lib/php:/Applications/MAMP/bin/php5.3/lib/php
La librería Zend se encuentra en
Código:
/Users/xxx/Documents/websites/quickstart/library
y es un link simbólico.

¿A alguien se le ocurre qué puede estar pasando?

Gracias de antemano.