Tôi có một ứng dụng có cấu trúc thư mục mặc định, cho một ứng dụng không có mô-đun tùy chỉnh (xem hình cấu trúc ở cuối).Nhận ngoại lệ "Không có mô-đun mặc định được xác định cho ứng dụng này" trong khi chạy kiểm tra đơn vị điều khiển trong khung công tác zend
Tôi đã viết tệp ControllerTestCase.php theo hướng dẫn trong nhiều hướng dẫn và tôi cũng đã tạo tệp bootstrap thích hợp (một lần nữa, xem các số liệu ở cuối).
Tôi đã viết một số thử nghiệm mô hình chạy tốt, nhưng khi tôi bắt đầu viết tệp kiểm tra chỉ mục, chỉ với một thử nghiệm trong đó, chỉ có một dòng trong đó ("$ this-> dispatch ('/ '); "), Tôi nhận được ngoại lệ sau khi chạy phpunit (nhưng điều hướng với trình duyệt đến cùng một vị trí - tất cả đều tốt và hoạt động):
1) IndexControllerTest::test_indexAction_noParams
Zend_Controller_Exception: No default module defined for this application
Tại sao lại như vậy? Tôi đã làm gì sai ?
Phụ lục:
Cấu trúc thư mục:
-proj/
-application/
-controllers/
-IndexController.php
-ErrorController.php
-config/
-layouts/
-models/
-views/
-helpers/
-scripts/
-error/
-error.phtml
-index/
-index.phtml
-Bootstrap.php
-library/
-tests/
-application/
-controllers/
-IndexControllerTest.php
-models/
-bootstrap.php
-ControllerTestCase.php
-library/
-phpunit.xml
-public/
-index.php
(. Về cơ bản tôi có một số file ở những thư mục mô hình, nhưng đó là không liên quan đến câu hỏi này)
tập tin application.ini :
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "My"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
phpSettings.date.timezone = "America/Los_Angeles"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
kiểm tra/ứng dụng/file bootstrap.php: file
<?php
error_reporting(E_ALL);
// 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'), // this project' library
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'ControllerTestCase.php';
ControllerTestCase.php:
<?php
require_once ('Zend/Test/PHPUnit/ControllerTestCase.php');
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase {
/**
*
* @var Zend_Application
*/
protected $application;
protected function setUp(){
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}
public function appBootstrap(){
$this->application = new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini');
}
}
Thực ra, tôi đang sử dụng zend framework 1.10.2, vì vậy lỗi này bạn' đang nói về là không có ở tất cả, tuy nhiên - bạn đã dẫn tôi đến giải pháp, và đó là tôi đã bỏ lỡ $ this -> _ application-> bootstrap() gọi trong phương thức appBootstrap. Vui lòng chỉnh sửa câu trả lời của bạn để xóa tham chiếu đến lỗi, vì không phải như vậy. Cảm ơn – Doron
tôi đang ở mức 1,10,6 ngay bây giờ nhưng tôi dường như vẫn gặp phải lỗi đó ... dunno nếu tôi đã làm điều gì đó sai tho. nếu tôi xóa bản sửa lỗi đó, nó không thành công –
@jiewmeng Hãy xem thiết lập được mô tả bởi Matthew: [Thử nghiệm các ứng dụng khung công tác Zend] (http://www.slideshare.net/weierophinney/testing-zend-framework-applications) – takeshin