Zend FR

Consultez la FAQ sur le ZF avant de poster une question

Vous n'êtes pas identifié.

#1 01-02-2013 19:16:13

maryooman
Membre
Date d'inscription: 15-02-2010
Messages: 106

Tests avec Zend, erreurs au lancement

Bonjour,


J'ai besoins de vote aide pour lancer les tests pour Zend Framework, c'est assez désespérant autant de difficulté.

Mon but premier est de lancer les tests dans eclipse.
J'ai réussie, en installant le plugin MakeGood, en installant phpunit avec PEAR et toute les dépendances « sudo pear install --alldeps --force phpunit/phpunit », puis en écrivant les fichier suivant :

phpunit.xml

Code:

<phpunit bootstrap="./bootstrap.php">
    <testsuite name="Application Test Suite">
        <directory>./application</directory>
    </testsuite>
    <filter>
        <!-- If Zend Framework is inside your project's library, uncomment this filter -->
        <whitelist>
            <directory suffix=".php">../../library</directory>
            <directory suffix=".php">../../application/</directory>
        </whitelist> 
    </filter>
</phpunit>

bootstrap.php

Code:

<?php

error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);

// 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';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);

Cela fonctionnait, mais une assertion me provoque une erreur (assertRedirectTo()), cela est dû au faite que j'ai phpunit 3.7 alors que Zend recommande d'utiliser la version 3.4.

Alors je désinstalle phpunit puis le réinstalle : « sudo pear install --alldeps --force phpunit/phpunit-3.4.0 »

Mais plus rien ne fonctionne.

Code:

Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Preparer/PHPUnitPreparer.php on line 40

Call Stack:
    0.0005     254760   1. {main}() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/bin/testrunner.php:0
    0.0410    1659624   2. Symfony\Component\Console\Application->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/bin/testrunner.php:59
    0.0487    1969808   3. Symfony\Component\Console\Application->doRun() /usr/share/php/Symfony/Component/Console/Application.php:105
    0.0491    1971688   4. Symfony\Component\Console\Command\Command->run() /usr/share/php/Symfony/Component/Console/Application.php:192
    0.0495    1977568   5. Stagehand\TestRunner\CLI\TestRunnerApplication\Command\PluginCommand->execute() /usr/share/php/Symfony/Component/Console/Command/Command.php:238
    0.0821    3222472   6. Stagehand\TestRunner\CLI\TestRunner->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/CLI/TestRunnerApplication/Command/PluginCommand.php:145
    0.0838    3262360   7. Stagehand\TestRunner\Process\TestRun->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/CLI/TestRunner.php:69
    0.0843    3274624   8. Stagehand\ComponentFactory\ComponentAwareFactory->create() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Process/TestRun.php:100
    0.0843    3274856   9. Stagehand\ComponentFactory\ComponentFactory->create() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/ComponentFactory/ComponentAwareFactory.php:71
    0.0843    3274904  10. Symfony\Component\DependencyInjection\Container->get() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/ComponentFactory/ComponentFactory.php:76
    0.0844    3275296  11. Stagehand\TestRunner\DependencyInjection\CompiledContainer->getPhpunit_PreparerService() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/DependencyInjection/Container.php:258
    0.0844    3275800  12. Symfony\Component\ClassLoader\UniversalClassLoader->loadClass() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/DependencyInjection/Container.php:0
    0.0849    3292824  13. require('/opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Preparer/PHPUnitPreparer.php') /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/ClassLoader/UniversalClassLoader.php:249


Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/home/jean/project/library:/home/jean/project:/usr/share/php:/usr/share/php/PEAR:/opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php') in /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Preparer/PHPUnitPreparer.php on line 40

Call Stack:
    0.0005     254760   1. {main}() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/bin/testrunner.php:0
    0.0410    1659624   2. Symfony\Component\Console\Application->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/bin/testrunner.php:59
    0.0487    1969808   3. Symfony\Component\Console\Application->doRun() /usr/share/php/Symfony/Component/Console/Application.php:105
    0.0491    1971688   4. Symfony\Component\Console\Command\Command->run() /usr/share/php/Symfony/Component/Console/Application.php:192
    0.0495    1977568   5. Stagehand\TestRunner\CLI\TestRunnerApplication\Command\PluginCommand->execute() /usr/share/php/Symfony/Component/Console/Command/Command.php:238
    0.0821    3222472   6. Stagehand\TestRunner\CLI\TestRunner->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/CLI/TestRunnerApplication/Command/PluginCommand.php:145
    0.0838    3262360   7. Stagehand\TestRunner\Process\TestRun->run() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/CLI/TestRunner.php:69
    0.0843    3274624   8. Stagehand\ComponentFactory\ComponentAwareFactory->create() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Process/TestRun.php:100
    0.0843    3274856   9. Stagehand\ComponentFactory\ComponentFactory->create() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/ComponentFactory/ComponentAwareFactory.php:71
    0.0843    3274904  10. Symfony\Component\DependencyInjection\Container->get() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/ComponentFactory/ComponentFactory.php:76
    0.0844    3275296  11. Stagehand\TestRunner\DependencyInjection\CompiledContainer->getPhpunit_PreparerService() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/DependencyInjection/Container.php:258
    0.0844    3275800  12. Symfony\Component\ClassLoader\UniversalClassLoader->loadClass() /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/DependencyInjection/Container.php:0
    0.0849    3292824  13. require('/opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Stagehand/TestRunner/Preparer/PHPUnitPreparer.php') /opt/eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_2.2.0.v201212251558/resources/php/php/Symfony/Component/ClassLoader/UniversalClassLoader.php:249

Et la classe PHPUnitPreparer s'affiche dans eclipse sur la ligne 40 : require_once 'PHPUnit/Autoload.php';


Après quelques temps, j'ai abandonné au profit de la ligne de commande, mais j'ai encore des erreurs :

~$phpunit --configuration ../../phpunit.xml UserControllerTest.php

Code:

PHP Warning:  Module 'xdebug' already loaded in Unknown on line 0
PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'Argument #1 of PHPUnit_Util_Fileloader:load() is no existing file' in /usr/share/php/PHPUnit/Util/InvalidArgumentHelper.php:73
Stack trace:
#0 /usr/share/php/PHPUnit/Util/Fileloader.php(108): PHPUnit_Util_InvalidArgumentHelper::factory(1, 'existing file')
#1 /usr/share/php/PHPUnit/TextUI/Command.php(786): PHPUnit_Util_Fileloader::load('./bootstrap.php')
#2 /usr/share/php/PHPUnit/TextUI/Command.php(156): PHPUnit_TextUI_Command->handleArguments(Array)
#3 /usr/share/php/PHPUnit/TextUI/Command.php(147): PHPUnit_TextUI_Command->run(Array, true)
#4 /usr/bin/phpunit(52): PHPUnit_TextUI_Command::main()
#5 {main}
  thrown in /usr/share/php/PHPUnit/Util/InvalidArgumentHelper.php on line 73
zsh: exit 255   phpunit --configuration ../../phpunit.xml UserControllerTest.php

~$phpunit --bootstrap ../../bootstrap.php UserControllerTest.php
ce lance, par contre chaque assertion provoque une erreur, exemple :

Code:

PHPUnit 3.4.0 by Sebastian Bergmann.

..F

Time: 0 seconds

There was 1 failure:

1) UserControllerTest::testLoginActionSucces
Failed asserting last controller used <"error"> was "user"

/home/jean/project/library/Zend/Test/PHPUnit/ControllerTestCase.php:1000
/home/jean/project/tests/application/controllers/UserControllerTest.php:74

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
zsh: exit 1     phpunit --bootstrap ../../bootstrap.php UserControllerTest.php

C'est donc un blocage total, car j'ai passé beaucoup de temps à rechercher sur internet.
Je vous remercie par avance de votre aide.

Hors ligne

 

#2 05-02-2013 23:12:18

maryooman
Membre
Date d'inscription: 15-02-2010
Messages: 106

Re: Tests avec Zend, erreurs au lancement

Il n'existe nul part une documentation suffisamment fournie indiquant la marche à suivre pour lancer les test avec zend ?
ou bien il faut se payer un consultant ...

Hors ligne

 

#3 06-02-2013 11:16:01

maryooman
Membre
Date d'inscription: 15-02-2010
Messages: 106

Re: Tests avec Zend, erreurs au lancement

à priori un erreur dans le framework Zenb_Test

http://stackoverflow.com/questions/6030 … oller-used

je vais essayer de résoudre ce problème ...

Hors ligne

 

#4 06-02-2013 23:16:01

maryooman
Membre
Date d'inscription: 15-02-2010
Messages: 106

Re: Tests avec Zend, erreurs au lancement

j'ai trouvé un moyen de démarrer les tests, j'ai modifier le setUp() entre autre

Code:

    protected $application;
    
    public function setUp() {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp();
    }
    
    public function appBootstrap() {
        $this->application = new Zend_Application(
                APPLICATION_ENV,
                APPLICATION_PATH . '/configs/application.ini');
        $bootstrap = $this->application->getBootstrap()->bootstrap();
    
        $front = Zend_Controller_Front::getInstance();
        $front->setControllerDirectory(APPLICATION_PATH . '/controllers','default');
    
        return $bootstrap;
    }

cependant, lorsque j'utilise $this->assertQuery('');

j'ai le message suivant :

Zend_Dom_Exception: Cannot query; no document registered

et en mettant :
print_r($this->getResponse());

j'ai

Code:

Zend_Controller_Response_HttpTestCase Object
(
    [_body:protected] => Array
        (
            [default] => 
        )

    [_exceptions:protected] => Array
        (
        )

    [_headers:protected] => Array
        (
            [0] => Array
                (
                    [name] => Location
                    [value] => /
                    [replace] => 1
                )

        )

    [_headersRaw:protected] => Array
        (
        )

    [_httpResponseCode:protected] => 302
    [_isRedirect:protected] => 1
    [_renderExceptions:protected] => 
    [headersSentThrowsException] => 1
)

donc à priori il n'y pas de réponses HTML, la vue ne s'active pas en quelques sorte.

Avez vous une solution ?

Merci

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr

Graphisme réalisé par l'agence Rodolphe Eveilleau
Développement par Kitpages