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

如果我能想出如何访问我的主题之一页面的正确方法........