簡體   English   中英

Kohana 3和SimpleTest使用autorun.php

[英]Kohana 3 and SimpleTest using autorun.php

如何將Simpletest與Kohana 3集成在一起? 我已經簽出了這個答案,但是我想使用SimpleTest的autorun.php功能。

經過幾個小時的檢查,我發現了如何做

  1. 創建index.php的新副本,並將其命名為test_index.php
  2. 禁用test_index.php中的error_reporting行
  3. 創建bootstrap.php的新副本,並將其命名為test_bootstrap.php
  4. 在底部注釋掉請求
  5. 確保test_index.php包含test_boostrap.php而不是bootstrap.php
  6. 向目錄結構添加simpletests
  7. 編寫測試用例-像往常一樣包括“ test_index.php”和“ autorun.php”(來自simpletests)並編寫代碼測試用例。

我的例子:

<?php
include_once ("../../test_index.php");
include_once ("../simpletest/autorun.php");

class kohana_init_test extends UnitTestCase
{
    function testTrue()
    {
        $this->assertTrue(true);
    }

    function testWelcome()
    {
        $response = Request::factory('main/index')->execute()->response;

        $this->assertEqual($response->content, 'testing');

    }
}

?>

一些注意事項:$ response變量取決於您使用的是View還是純文本輸出。 如果使用模板控制器或視圖,則$ response是用於呈現內容的視圖。 視圖中的變量可用,如上所示(變量內容在視圖內部定義)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM