0

我試圖寫一個使用PHPUnit的十月CMS插件的定製路由一些測試,但遇到了一些錯誤,讓測試才能正確運行。月CMS PHPUnit的路線測試

每個測試單獨運行時通過,但是當作爲一組運行時,所述第一測試將通過其餘的失敗,500的錯誤。爲測試失敗的錯誤信息是:

in Resolver.php line 44 
at HandleExceptions->handleError('8', 'Undefined index: myThemeName', 
'/Users/me/src/myProject/vendor/october/rain/src/Halcyon/Datasource/ 
Resolver.php', '44', array('name' => 'myThemeName')) in Resolver.php line 
44 

測試用例看起來是這樣的:

class RoutesTest extends PluginTestCase 
{ 
    protected $baseUrl = "/"; 

    public function setUp() { 
    parent::setUp(); 
    DB::beginTransaction(); 
} 

    public function tearDown() 
    { 
    DB::rollBack(); 
    parent::tearDown(); 
    } 

    public function testRootPath() 
    { 
    $response = $this->call('GET', '/'); 
    $this->assertEquals(200, $response->status()); 
    } 

    public function testIntroPath() 
    { 
    $response = $this->call('GET', '/intro'); 
    $this->assertEquals(200, $response->status()); 
    } 

    etc... 
} 
+0

你能分享你所擁有的'use'陳述,好嗎?我似乎無法得到'使用照亮\基金會\測試\測試用例;'工作,我已經看到了'使用\化PHPUnit_Framework_TestCase;'別的地方 - 這是首選/有效'use'風格? – icedwater

回答

0

我們結束了使用捲曲,使實際的請求,並從獲得響應代碼。

protected function getResponseCode($url) { 
    $ch = curl_init($this->baseUrl.$url); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_NOBODY, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT,10); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_exec($ch); 
    return curl_getinfo($ch, CURLINFO_HTTP_CODE); 
} 

public function testRootPath() 
{ 
    $this->assertEquals(200, $this->getResponseCode('/')); 
} 

現在所有的測試都通過了,沒有使用獨立的進程。

0

我不知道爲什麼,但如果你對你的phpunit通話添加標誌--process-isolation工作,我想,也許是一個緩存問題

+0

這確實讓測試通過,但看起來更像是一種解決方法,而不是解決問題。 – mindlis

+0

:)祝你好運,我已經一年試圖發現正在發生的事情,但... – OsDev

0

遺憾的是沒有解決辦法,只是角度不同。我認爲它與10月份的「測試」配置(config/testing/cms.php)有關。 這將查找目錄「tests/fixtures/themes/pages /」中的文件。它在其中找到的index.htm文件的url參數設置爲「/」。 這就是爲什麼phpunit會找到它,但不是其他的url。 我看到serveral的建議解決這個問題,但他們沒有工作對我來說:

  1. 使用「配置::設置(‘cms.activeTheme’,‘mytheme的’);」在運行測試之前。
  2. 改變從 「pluginsPathLocal」 「BASE_PATH( '試驗/裝置/插件')」 到 「BASE_PATH( '插件')」 在配置/測試/ cms.php
  3. 改變從「BASE_PATH的 「themesPathLocal」( 'tests/fixtures/themes')「to」base_path('themes')「在配置/測試/ cms.php

如果我能想出如何訪問我的主題之一頁面的正確方法........