2012-02-09 12 views
1

「クラス 『GroupTest』が見つかりません」で失敗しますオートロードされているライブラリのリストに "simpletester"を追加してください。SimpleTesterは、私がここでの指示に従って、新しいCodeIgniterのアプリケーションにSimpleTesterをクリーンインストールやろうとしている

:私はそれがコメントであり、次のことを述べているreadmeファイルで参照参照

GroupTestためのコードをgrepを

Fatal error: Class 'GroupTest' not found in /path/to/app/application/libraries/simpletester.php on line 84

:できるだけ早く私がそうであるように任意のページを訪問することは、単純になり、ということGroupTestの名前がTestSuiteに変更されました(下記参照)。 これは、 という名前で1.1で完全に削除されました。

私はテストスイートでGroupTestを置き換えるためにライン84を変更しようとしたが、その後、私は次のエラーを取得する:

Fatal error: Call to undefined method TestSuite::addTestFile() in /home/path/to/app/application/libraries/simpletester.php on line 96

は、これは彼らの最後のバグですか?誰もこれを見たことがありますか?

答えて

1

私は同じ問題を抱えています。 GroupTestクラスは、SimpleTestのバージョン1.0.1のtest_case.phpにあります: http://sourceforge.net/projects/simpletest/files/simpletest/simpletest_1.0.1/

残念ながら、v1.0.1をライブラリフォルダに挿入しても、世界中の問題は解決されません。私はもはや "致命的なエラー:クラス 'GroupTest'が見つかりません..."エラーが発生しますが、私はセグメント違反を取得し、私のサイトはもはや動作しません。

私は簡単に問題を追跡しようとしましたが、役に立たなかったです。

注:私もCodeIgniter Wiki page containing the same questionで回答しました。

1

私は現在のプロジェクトで同じ問題を抱えていて、GroupTestが少し違った動作をするTestSuiteに置き換えられていることがわかりました。

これは私が使用するライブラリのコードです:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

$libraryDir = APPPATH . 'libraries/simpletest'; 

if(!is_dir($libraryDir)) 
    exit("Simpletest must be located in \"$libraryDir\""); 

require_once $libraryDir . '/unit_tester.php'; 
require_once $libraryDir . '/mock_objects.php'; 
require_once $libraryDir . '/collector.php'; 

class SimpleTester 
{ 
    /** 
    * What reporter should be used for display. 
    * Could be either HtmlReporter, SmallReporter, MinimalReporter or ShowPasses. 
    */ 
    public $Reporter = 'MinimalReporter'; 

    private $testDir; 
    private $testTitle; 
    private $fileExtension; 

    public function __construct($params = false) 
    { 
     $ci =& get_instance(); 

     $ci->config->load('simpletester'); 

     if($params == false) { 
      $params['runFromIPs'] = $ci->config->item('runFromIPs'); 
      $params['testDir'] = $ci->config->item('testDir'); 
      $params['fileExtension'] = $ci->config->item('fileExtension'); 
      $params['autorun'] = $ci->config->item('autorun'); 
      $params['reporter'] = $ci->config->item('reporter'); 
      $params['testTitle'] = $ci->config->item('testTitle'); 
     } 

     if(isset($params['runFromIPs']) && strpos($params['runFromIPs'], $ci->input->server('SERVER_ADDR') === FALSE)) 
     { 
      // Tests won't be run automatically from this IP. 
      $params['autorun'] = FALSE; 
     } 

     // Check if call was an AJAX call. No point in running test 
     // if not seen and may break the call. 
     $header = 'CONTENT_TYPE'; 
     if(!empty($_SERVER[$header])) { 
      // @todo Content types could be placed in config. 
      $ajaxContentTypes = array('application/x-www-form-urlencoded', 'multipart/form-data'); 
      foreach ($ajaxContentTypes as $ajaxContentType) { 
       if(false !== stripos($_SERVER[$header], $ajaxContentType)) 
       { 
        $params['autorun'] = FALSE; 
        break; 
       } 
      } 
     } 

     $this->testDir = $params['testDir']; 
     $this->testTitle = $params['testTitle']; 
     $this->fileExtension = $params['fileExtension']; 

     if(isset($params['reporter'])) 
      $this->Reporter = $params['reporter']; 

     if($params['autorun'] == TRUE) 
      echo $this->Run(); 
    } 

    /** 
    * Run the tests, returning the reporter output. 
    */ 
    public function Run() 
    { 
     // Save superglobals that might be tested. 
     if(isset($_SESSION)) $oldsession = $_SESSION; 
     $oldrequest = $_REQUEST; 
     $oldpost = $_POST; 
     $oldget = $_GET; 
     $oldfiles = $_FILES; 
     $oldcookie = $_COOKIE; 

     $test_suite = new TestSuite($this->testTitle); 

     // Add files in tests_dir 
     if(is_dir($this->testDir)) 
     { 
      if($dh = opendir($this->testDir)) 
      { 
       while(($file = readdir($dh)) !== FALSE) 
       { 
        // Test if file ends with php, then include it. 
        if(substr($file, -(strlen($this->fileExtension)+1)) == '.' . $this->fileExtension) 
        { 
         $test_suite->addFile($this->testDir . "/$file"); 
        } 
       } 
       closedir($dh); 
      } 
     } 

     // Start the tests 
     ob_start(); 
     $test_suite->run(new $this->Reporter); 
     $output_buffer = ob_get_clean(); 

     // Restore superglobals 
     if(isset($oldsession)) $_SESSION = $oldsession; 
     $_REQUEST = $oldrequest; 
     $_POST = $oldpost; 
     $_GET = $oldget; 
     $_FILES = $oldfiles; 
     $_COOKIE = $oldcookie; 

     return $output_buffer; 
    } 
} 

// Html output reporter classes ////////////////////////////////////// 

/** 
* Display passes 
*/ 
class ShowPasses extends HtmlReporter 
{ 
    function ShowPasses() 
    { 
     $this->HtmlReporter(); 
    } 

    function paintPass($message) 
    { 
     parent::paintPass($message); 
     print "<span class=\"pass\">Pass</span>: "; 
     $breadcrumb = $this->getTestList(); 
     array_shift($breadcrumb); 
     print implode("-&gt;", $breadcrumb); 
     print "-&gt;$message<br />\n"; 
    } 

    function _getCss() 
    { 
     return parent::_getCss() . ' .pass {color:green;}'; 
    } 
} 

/** 
* Displays a tiny div in upper right corner when ok 
*/ 
class SmallReporter extends HtmlReporter 
{ 
    var $test_name; 

    function ShowPasses() 
    { 
     $this->HtmlReporter(); 
    } 

    function paintHeader($test_name) 
    { 
     $this->test_name = $test_name; 
    } 

    function paintFooter($test_name) 
    { 
     if($this->getFailCount() + $this->getExceptionCount() == 0) 
     { 
      $text = $this->getPassCount() . " tests ok"; 
      print "<div style=\"background-color:#F5FFA8; text-align:center; right:10px; top:30px; border:2px solid green; z-index:10; position:absolute;\">$text</div>"; 
     } 
     else 
     { 
      parent::paintFooter($test_name); 
      print "</div>"; 
     } 
    } 

    function paintFail($message) 
    { 
     static $header = FALSE; 
     if(!$header) 
     { 
      $this->newPaintHeader(); 
      $header = TRUE; 
     } 
     parent::paintFail($message); 
    } 

    function newPaintHeader() 
    { 
     $this->sendNoCacheHeaders(); 
     print "<style type=\"text/css\">\n"; 
     print $this->_getCss() . "\n"; 
     print "</style>\n"; 
     print "<h1 style=\"background-color:red; color:white;\">$this->test_name</h1>\n"; 
     print "<div style=\"background-color:#FBFBF0;\">"; 
     flush(); 
    } 
} 

/** 
* Minimal only displays on error 
*/ 
class MinimalReporter extends SmallReporter 
{ 
    function paintFooter($test_name) 
    { 
     if($this->getFailCount() + $this->getExceptionCount() != 0) 
     { 
      parent::paintFooter($test_name); 
      print "</div>"; 
     } 
    } 
} 

は私もまだすべての異なるレポーターをテストしていない私のために正常に動作します。しかし、デフォルトのものは正常に動作します。

そして、これは私がそれを使用する方法です:

$this->load->library('simpletester'); 
echo $this->simpletester->Run(); 

そして、私の設定ファイルは次のとおりです。あなたの深い応答のための

$config['testDir'] = APPPATH . 'tests'; 
$config['runFromIPs'] = '127.0.0.1'; 
$config['reporter'] = 'HtmlReporter'; 
$config['autorun'] = false; 
$config['fileExtension'] = 'php'; 
$config['testTitle'] = 'My Unit Tests'; 
+0

ありがとう!私は家に帰ってここに戻ってくるときに試してみる。 – Mala

関連する問題