2011-04-25 4 views
6

J'ai un projet Zend Framework, et je veux utiliser des tests unitaires pour le tester.phpunit throws Exception non interceptée 'PHPUnit_Framework_Exception

Dans le dossier de test, j'ai le comme suit;

<phpunit bootstrap="./application/bootstrap.php" colors="true"> 
<testsuite name="Application Test Suite"> 
    <directory>./</directory> 
</testsuite> 

<filter> 
    <whitelist> 
     <directory suffix=".php">../application/</directory> 
     <exclude> 
      <directory suffix=".phtml">../application/</directory> 
      <file>../application/Bootstrap.php</file> 
      <file>../application/controllers/ErrorController.php</file> 
     </exclude> 
    </whitelist> 
</filter> 

<logging> 
    <log type="coverage-html" target="./log/reprot" charset="UTP-8" 
    yui="true" highlight = "true" lowUpoerBound="50" highLowerBound="80"/> 
    <log type="textdox" target="./log/testdox.html" /> 
</logging> 

Et je bootstrap.php dans/tests/dossier d'application comme suit:

<?php 
error_reporting(E_ALL | E_STRICT); 

// 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'; 

require_once 'controllers/ControllerTestCase.php'; 
Zend_Loader_Autoloader::getInstance(); 

quand je vais à la ligne de commande, exécutez la commande suivante

phpunit --configuration phpunit.xml 

il jette l'exception:

PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 
'Neither "Application Test Suite.php" nor "Application Test Suite.php" could be 
opened.' in D:\PHP\php5\PEAR\PHPUnit\Util\Skeleton\Test.php:102 
Stack trace: 
#0 D:\PHP\php5\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test- 
>__construct('Application Tes...', '') 
#1 D:\PHP\php5\PEAR\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run 
(Array, true) 
#2 D:\PHP\php5\phpunit(53): PHPUnit_TextUI_Command::main() 
#3 {main} 
    thrown in D:\PHP\php5\PEAR\PHPUnit\Util\Skeleton\Test.php on line 102

Comment pourrais-je le réparer?

Répondre

5

Youll remarque son jet de l'exception car il cherche un fichier nommé le même que le name que vous avez fourni pour votre suite de tests. Vous devez écrire en fait une suite de test, puis fournir le nom de cette suite de tests à votre config: http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

+0

-je ajouter le code suivant dans le dossier qui contient bootstrap.php addTestSuite ('MyApp'); // ... return $ suite; } } et c'est toujours la même erreur –

+0

Avez-vous changé le nom que vous avez fourni dans votre XML? Cela doit correspondre directement au nom de fichier de la classe de la suite de tests moins l'extension. Donc, si le code que vous venez de publier est dans MyApp.php, alors votre xml devrait ressembler à: '' par opposition à ' – prodigitalson

+0

oui, je déjà changé le nom dans le fichier XML, l'erreur est la même –

0

je remarquai que vous n'êtes pas en utilisant la <testsuites> qui contient plusieurs occurences de <testsuite>.

Voici mon phpunit.xml qui fonctionne très bien pour les projets Zend Framework:

<testsuites> 
    <testsuite name="UnitTests"> 
    <directory>./library</directory> 
    </testsuite> 
    <testsuite name="ApplicationTests"> 
    <directory>./application</directory> 
    </testsuite> 
</testsuites> 
+0

Merci Brown, je votre xml, mais l'erreur est la même. –

7

j'avais le même problème avec la même configuration. D'après ce que je comprends, les versions plus récentes de PHPUnit nécessitent au moins un test réel pour fonctionner correctement. Après avoir créé un test simple, cela a fonctionné.

myProject/tests/application/DemoTest.php

<?php 
class DemoTest extends ControllerTestCase 
{ 
    public function setUp() { 
     parent::setUp(); 
    } 

    public function testCanDoUnitTest() { 
     $this->assertTrue(true); 
    } 
} 
+0

Cela a résolu le problème pour moi, merci. –

Questions connexes