2013-02-08 19 views
13

Tôi đang làm theo hướng dẫn Zend Framework 2 chính thức cho phiên bản 2.1. Trong Unit Testing phần, nơi tôi đang phải chạy phpunit trong mô-đun/Ứng dụng/thử nghiệm Tôi chạy vào vấn đề sau đây:Hướng dẫn Zend Framework 2: Mô-đun (Ứng dụng) không thể được khởi tạo

[email protected]:~/Desktop/zf2-tutorial/module/Application/test$ phpunit 
PHPUnit 3.7.13 by Sebastian Bergmann. 

Configuration read from /home/user/Desktop/zf2-tutorial/module/Application/test/phpunit.xml.dist 

E 

Time: 0 seconds, Memory: 4.00Mb 

There was 1 error: 

1) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed 
Zend\ModuleManager\Exception\RuntimeException: Module (Application) could not be initialized. 

/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:140 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:81 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:460 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:204 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:100 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:239 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:146 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:173 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:193 
/home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:236 
/home/user/Desktop/zf2-tutorial/module/Application/test/ApplicationTest/Controller/IndexControllerTest.php:20 

FAILURES! 
Tests: 1, Assertions: 0, Errors: 1. 

tôi sao chép nội dung của IndexControllerTest.php từ hướng dẫn.

<?php 

namespace ApplicationTest\Controller; 

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; 

class IndexControllerTest extends AbstractHttpControllerTestCase 
{ 
    public function setUp() 
    { 
     $this->setApplicationConfig(
      include '/home/user/Desktop/zf2-tutorial/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'); 
    } 
} 

Tôi không biết tại sao ứng dụng sẽ không khởi chạy và tôi sẽ đánh giá cao bất kỳ con trỏ nào.

+0

Sự cố của tôi là các quyền mà tôi có trong thư mục và tệp mô-đun của mình. (Tôi đang sử dụng máy tính Ubuntu) – leticia

Trả lời

-1

Kiểm tra tệp application.config trong thư mục Cấu hình gốc, nơi chúng tôi phải xác định ứng dụng trong 'mô-đun'.

Mẫu mã:

'modules' => array(
     'Application', 
     'FrontEnd', 
      ), 
+2

Tôi e rằng không phải vậy. Trong config/application.config.php của tôi có ''modules' => array ( 'Application', 'Album', ), ' –

31

Đây là một vấn đề tự động load mà có thể liên quan với các tùy chọn module_paths trong config/application.config.php (trong hướng dẫn, đó là một trong những bạn có trong /path/to/application/config/test/application.config.php).

Đó application.config.php lẽ trông giống như sau:

return array(
    'modules' => array(
     'Application', 
     'Album', 
    ), 

    'module_listener_options' => array(
     'module_paths' => array(
      './module', 
      './vendor', 
     ), 
    ), 
); 

Để khắc phục vấn đề của bạn, thay đổi giá trị ./module vào một đường dẫn tuyệt đối, ví dụ __DIR__ . '/../module, giả sử application.config.php là trong config/ trong thư mục gốc của ứng dụng của bạn.

Để làm rõ: sự cố xảy ra vì ./module là đường dẫn tương ứng với cwd của bạn. cwd của bạn khi chạy phpunit nằm trong thư mục kiểm tra, nơi không có (rõ ràng) bất kỳ thư mục module nào.

+0

Cảm ơn bạn đã phản hồi @Ocramius Tôi đã thử cách này nhưng tôi nhận được 'PHP Lỗi nghiêm trọng: Gọi đến phương thức không xác định ApplicationTest \ Controller \ IndexControllerTest :: assertModule() trong /var/www/test/zf2-tutorial/module/Application/test/ApplicationTest/Controller/IndexControllerTest.php trên dòng 22' không chắc chắn nếu nó giải quyết một vấn đề và gây ra một vấn đề khác. –

+0

Vâng, vấn đề dường như được giải quyết ở đó ('IndexControllerTest :: assertModule' không tồn tại là một vấn đề khác). Chúng ta có thể trò chuyện về điều đó. – Ocramius

+0

Dường như nó phải là 'assertModuleName' cho mọi tham chiếu everyones trông khá nhiều vẫn cần cập nhật trong hướng dẫn sử dụng này. –

Các vấn đề liên quan