Foros del Web » Programando para Internet » PHP » Zend »

PHPUnit - Class 'xxx' not found

Estas en el tema de PHPUnit - Class 'xxx' not found en el foro de Zend en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 12/03/2011, 10:39
Avatar de 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.
  #2 (permalink)  
Antiguo 13/03/2011, 07:24
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHPUnit - Class 'xxx' not found

Que tal jerkan,

seguramente lo que esta fallando es el autoload, agrega al final de /tests/application/bootstrap.php

Código PHP:
Ver original
  1. ...
  2. /**
  3.  * Register autoloader
  4.  */
  5. require_once 'Zend/Loader/Autoloader.php';
  6. Zend_Loader_Autoloader::getInstance();
  7.  
  8. /** Zend_Application */
  9. require_once 'Zend/Application.php';
  10.  
  11. // Create application, bootstrap and run
  12. require_once './application/controllers/ControllerTestCase.php';

PD: ver el verde en la consola y el 100% en code coverage da confianza en la aplicación

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)
  #3 (permalink)  
Antiguo 13/03/2011, 10:42
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: PHPUnit - Class 'xxx' not found

Me olía que era cosa del autoload.

Muchas gracias!
  #4 (permalink)  
Antiguo 14/03/2011, 10:11
pur
 
Fecha de Ingreso: agosto-2007
Mensajes: 98
Antigüedad: 16 años, 8 meses
Puntos: 4
Respuesta: PHPUnit - Class 'xxx' not found

Hola, si trabajas con Netbeans, podés configurarlo para trabajar con phpunit, y te hace todo automaticamente.

Etiquetas: autoloader, frameworks-y-php-orientado-a-objetos, phpunit
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:41.