dongqucheng3851 2013-03-26 10:14
浏览 55

PHPunit在zendframework 2中

i'm trying to use phpunit with zendframework and i'm follwing the tutorial in

https://media.readthedocs.org/pdf/zf2/latest/zf2.pdfhere is my

bootstrap.php

<?php
chdir(dirname(__DIR__));
include __DIR__ . '/../init_autoloader.php';

here is my IndexControllerTest.php

<?php

namespace ApplicationTest\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;

class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig(
include '/C:/wamp/www/zf2/config/application.config.php'
);
    parent::setUp();
}

public function testIndexActionCanBeAccessed()
{
    $this->dispatch('/'); // this is line 20
    $this->assertResponseStatusCode(200);

    $this->assertModule('application');
    $this->assertControllerName('application_index');
    $this->assertControllerClass('IndexController');
    $this->assertMatchedRouteName('home');
}
}

and i'm getting the follwing errors

Warning: include(C:\wamp\www\zf2\module\Application\test/../init_autoloader.php)
: failed to open stream: No such file or directory in C:\wamp\www\zf2\module\App
lication\test\Bootstrap.php on line 4


Fatal error: Class 'Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase'
not found in C:\wamp\www\zf2\module\Application\test\ApplicationTest\Controller
\IndexControllerTest.php on line 8

i think that's a path probleme (auloading)but i don't know how to fix

any one can help me please ?

  • 写回答

2条回答 默认 最新

  • douji8033 2013-03-27 09:10
    关注
    Warning: include(C:\wamp\www\zf2\module\Application\test/../init_autoloader.php)
    : failed to open stream: No such file or directory in C:\wamp\www\zf2\module\App
    lication\test\Bootstrap.php on line 4
    

    This warning is telling you that it can't find the location of your init_autoloader.php file. Assuming that file is located in the root of your ZF2 project (so C:\wamp\www\zf2) as is convention, you need to change:

    include __DIR__ . '/../init_autoloader.php';
    

    to

    include __DIR__ . '/../../../init_autoloader.php';
    

    EDIT Continued...

    PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to 
    load ZF2. Run php composer.phar install or define a ZF2_PATH environment 
    variable.' in C:\wamp\www\zf2\init_autoloader.php:48
    

    Your init_autloader.php file is having trouble finding your ZF2 library autoloader. As you're using composer. Add

    "zendframework/zendframework": "2.1.*",
    

    to your "require" section in composer.json if its not already there. Run composer and update your vendor libraries with

    php composer.phar update
    

    Try run the application again and see if it works. It may do depending what is included in your init_autoload.php file. If you're still having problems add the following to init_autoloader.php

    if(file_exists('vendor/autoload.php'))
    {
        $loader = require 'vendor/autoload.php';
    }
    
    评论

报告相同问题?