2011-07-21 12 views
0

私はコントローラをテストしようとしています。 私は、このガイドに従っ:私は私のテスト機能では、この呼び出しを使用していたまでphpunitでテストする

http://www.zendcasts.com/unit-testing-a ... S/2010/11/

すべてがOKだった: ます$ this->ディスパッチ( '/') ; 問題はブートストラップと問題ですが、これを解決する方法はわかりません。 私がテストに関与し、私のファイルを貼り付けます。

のapplication.ini = http://pastie.org/2248669

phpunit.xml =

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

<filter> 
    <!-- If Zend Framework is inside your project's library, uncomment this filter --> 
    <whitelist> 
    <directory suffix=".php">../application</directory> 
    <directory suffix=".php">../library/Kolcms</directory> 
    <exclude> 
     <directory suffix=".php">../library/Zend</directory> 
     <directory suffix=".php">../library/Kolcms/Model/DB</directory> 
     <directory suffix=".phtml">../library/</directory> 
     <directory suffix=".phtml">../application/</directory> 
     <file suffix=".php">../application/Bootstrap.php</file> 
    </exclude> 
    </whitelist> 

</filter> 

<logging> 
    <log type="coverage-html" target="./log/report" charset="UTF-8" 
    yui="true" highlight = "true" lowUpperBound="50" highLowerBound="80" /> 
</logging> 

bootstrap.phpの=

<?php 

    // Define path to application directory 
defined('APPLICATION_PATH') 
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application')); 

// Define application environment 
define('APPLICATION_ENV', 'testing'); 

// Ensure library/ is on include_path 
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'), 
    realpath(APPLICATION_PATH . '/../../../Zend'), 
    get_include_path() 
))); 


/** Zend_Application */ 
require_once 'Zend/Application.php'; 
require_once 'ControllerTestCase.php'; 
// Create application, bootstrap, and run 
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini' 
); 
$application->bootstrap(); 
clearstatcache(); 

ControllerTestCaseを.php =

<?php 
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php'; 

class ControllerTestCase 
extends Zend_Test_PHPUnit_ControllerTestCase 
{ 

/** 
* 
* @var Zend_Application 
*/ 

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

$this->application->bootstrap(); 

} 

public function tearDown() 
{ 
    $this->resetRequest(); 
    $this->resetResponse(); 

    parent::tearDown(); 
} 

} 

indexControllerTest.php =

<?php 
include_once APPLICATION_PATH . '/modules/core/controllers/IndexController.php'; 
class Core_IndexControllerTest extends ControllerTestCase 
{ 
     public function testDefaultShouldInvokeAction() 
     { 
      $this->dispatch('/core/index/index'); 
      $this->assertController('index'); 
      $this->assertAction('index'); 
      $this->assertModule('core'); 
     } 
} 

そして、ここに私のPHPUnitの出力です:

$ phpunit 
PHPUnit 3.5.5 by Sebastian Bergmann. 

PHP Fatal error: Call to a member function hasResource() on a non-object in 
/home/aykut/dev/kolonicms/application/modules/core/controllers/ErrorController.php on 
line 49 

Fatal error: Call to a member function hasResource() on a non-object in 
/home/aykut/dev/kolonicms/application/modules/core/controllers/ErrorController.php 
on line 49 

誰かが私を助けてくださいことができます。 ありがとう

答えて

1

私の推測では、URL /core/index/indexのルートがないため、ZFがエラーコントローラにリダイレクトしています。次にErrorController.phpには、オブジェクトを保持していない変数、またはnullの変数に対してhasResource()メソッドを呼び出すバグがあります。エラーコントローラーを最初に修正すると、問題の診断がより簡単になります。

これはコントローラとビュー用に別々の抽象的なテストケースクラスを構築した理由です。私はZendのControllerTestCaseがコントローラに加えてルート、ディスパッチャ、およびビューをテストするのは気に入らない。

0

dispatch()メソッドのコードを見ることができれば簡単ですが、例外を飲み込んでsetUp()(おそらくブートストラップ)のどこかでトリガされたエラーが考えられます。 。それはtearDownresetRequest()で使用される属性(多分$this->applicationまたはPHPエラーが生じ設定で初期化されていない$this->bootstrapを呼び出そうとしましたことを後

私はそのANを知っている。この種やエラーが発生する可能性があります時に説明answerを掲載しました古い投稿ですが、他の人を助けることができる場合は

関連する問題