php zend-framework doctrine phpunit zend-test

Configurar PHPUnit con Zend Test



zend-framework doctrine (1)

Estoy intentando comenzar a utilizar PHPUnit con Zend Test para mi aplicación Zend Framework. Puedo ejecutar el comando PHPUnit desde la línea de comando phpunit --configuration phpunit.xml . Intenté seguir este tutorial que se basa en la publicación del blog de Matthew Weier O''Phinney. Me aparece un error cuando PHPUnit intenta escribir el archivo de registro. Aquí está mi phpunit.xml

<phpunit bootstrap="./Bootstrap.php" colors="true"> <testsuite name="Zend Framework Tests"> <directory>./</directory> </testsuite> <!-- Optional filtering and logging settings --> <filter> <whitelist> <directory suffix=".php">../library/</directory> <directory suffix=".php">../application/</directory> <exclude> <directory suffix=".phtml">../application/</directory> </exclude> </whitelist> </filter> <logging> <log type="coverage-html" target="./log/report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/> <log type="testdox-html" target="./log/testdox.html"/> </logging> </phpunit>

Mi bootstrap de prueba:

<?php //Set app paths and environment define(''BASE_PATH'', realpath(dirname(__FILE__) . ''/../'')); define(''APPLICATION_PATH'', BASE_PATH . ''/application''); define(''TEST_PATH'', BASE_PATH . ''/tests''); define(''APPLICATION_ENV'', ''testing''); //Set include path set_include_path(''.'' . PATH_SEPARATOR . BASE_PATH . ''/library'' . PATH_SEPARATOR . get_include_path()); //Set the default timezone date_default_timezone_set(''America/Chicago''); ?>

Y mi ControllerTestCase que me gustaría que extiendan mis controladores de prueba:

<?php require_once ''Zend/Application.php''; require_once ''Zend/Test/PHPUnit/ControllerTestCase.php''; abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { public $_application; public function setUp() { //Override the parent to solve an issue with not finding the correct module $this->bootstrap = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . ''/configs/application.ini'' ); parent::setUp(); } } ?>

El error que recibo cuando PHPUnit intenta escribir el archivo de registro es: Fatal error: Class ''Symfony/Component/Console/Command/Command'' not found in C:/repositories/myfirstzend.com/includes/library/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php on line 38

¿Alguna pista sobre lo que estoy haciendo mal? Estoy en PHP 5.4, Windows 7, XAMPP 8.0, Pear está actualizado y tengo la última PHPUnit.

Actualizar si cambio mi Bootstrap.php al siguiente del blog de Matthew Weier O''Phinney:

<?php /* * Start output buffering */ ob_start(); /* * Set error reporting to the level to which code must comply. */ error_reporting( E_ALL | E_STRICT ); /* * Set default timezone */ date_default_timezone_set(''GMT''); /* * Testing environment */ define(''APPLICATION_ENV'', ''testing''); /* * Determine the root, library, tests, and models directories */ $root = realpath(dirname(__FILE__) . ''/../''); $library = $root . ''/library''; $tests = $root . ''/tests''; $models = $root . ''/application/models''; $controllers = $root . ''/application/controllers''; /* * Prepend the library/, tests/, and models/ directories to the * include_path. This allows the tests to run out of the box. */ $path = array( $models, $library, $tests, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $path)); /** * Register autoloader */ require_once ''Zend/Loader.php''; Zend_Loader::registerAutoload(); /** * Store application root in registry */ Zend_Registry::set(''testRoot'', $root); Zend_Registry::set(''testBootstrap'', $root . ''/application/bootstrap.php''); /* * Unset global variables that are no longer needed. */ unset($root, $library, $models, $controllers, $tests, $path);

Continúo recibiendo el error sobre Symfony de Doctrine. Me aseguré de haber instalado pear.symfony.com/Yaml también. Así que todavía está roto.

Si elimino la referencia de Doctrine de mi app.ini para la aplicación que estoy probando (lo que significa que no se carga), sigo recibiendo el error. Casi parece que los cargadores de cada una de las tres partes (PHPUnit, ZF, Doctrine) luchan entre sí. ¿Hay alguna forma de evitar esto?

Segunda actualización: he degradado PHPUnit a 3.4.15 y sigo teniendo este problema. Mi siguiente paso es pasar de PHP 5.4 a 5.3.x.

Tercera actualización: ahora estoy en PHP 5.3.10 y veo el mismo error.

Si hay más información que necesita, hágamelo saber.


Me falta la carga de la aplicación en tu bootstrap.

require_once ''Zend/Loader/Autoloader.php''; Zend_Loader_Autoloader::getInstance();

Para darle una idea de lo que tengo en mis pruebas / bootstrap.php (esto es generado automáticamente por la herramienta zend desde el lanzamiento-1.11.4)

<?php // Define path to application directory defined(''APPLICATION_PATH'') || define(''APPLICATION_PATH'', realpath(dirname(__FILE__) . ''/../application'')); // Define application environment defined(''APPLICATION_ENV'') || define(''APPLICATION_ENV'', (getenv(''APPLICATION_ENV'') ? getenv(''APPLICATION_ENV'') : ''testing'')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . ''/../library''), get_include_path(), ))); require_once ''Zend/Loader/Autoloader.php''; Zend_Loader_Autoloader::getInstance();

Como mencioné en el manual de Zend Framework, lo mejor es usar PHPUnit 3.4.15 aunque podría ejecutar mis pruebas usando PHPUnit 3.6.12 ya que estoy aislando mis pruebas para enfocarme en mi lógica comercial y no en la lógica de Zend Framework.

También modifiqué mi phpunit.xml en lo siguiente:

<phpunit bootstrap="./bootstrap.php" colors="true"> <testsuite name="Application Test Suite"> <directory>./application</directory> </testsuite> <testsuite name="Library Test Suite"> <directory>./library</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">../../library</directory> <directory suffix=".php">../../application</directory> <exclude> <directory suffix=".php">../../library/Zend</directory> </exclude> </whitelist> </filter> </phpunit>

Espero que esto solucione muchos de los problemas que enfrentas ahora.

Atentamente,

Michelangelo