Laravel 10月CMS PHPUnit路线测试

Laravel 10月CMS PHPUnit路线测试,laravel,phpunit,laravel-routing,octobercms,octobercms-plugins,Laravel,Phpunit,Laravel Routing,Octobercms,Octobercms Plugins,我试图使用PHPUnit为一个10月份CMS插件的自定义路由编写一些测试,但是在正确运行测试时遇到了一些错误 当单独运行时,每个测试都通过,但当作为一个组运行时,第一个测试将通过,其余测试将失败,并出现500个错误。失败测试的错误消息为: in Resolver.php line 44 at HandleExceptions->handleError('8', 'Undefined index: myThemeName', '/Users/me/src/myProject/vendor/o

我试图使用PHPUnit为一个10月份CMS插件的自定义路由编写一些测试,但是在正确运行测试时遇到了一些错误

当单独运行时,每个测试都通过,但当作为一个组运行时,第一个测试将通过,其余测试将失败,并出现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...
}

我不知道为什么,但是如果您在
phpunit
调用中添加标志
--进程隔离
,我认为可能是缓存问题

我不知道为什么,但是如果您在
phpunit
调用中添加标志
--进程隔离
,则该功能有效,我认为可能是缓存问题

我们最终使用curl发出实际请求并从中获取响应代码

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('/'));
}

现在所有的测试都通过了,而不需要使用独立的进程。

我们最终使用curl来发出实际的请求并从中获取响应代码

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('/'));
}

现在所有的测试都通过了,而没有使用单独的过程。

不幸的是,没有解决方案,只是角度不同而已。我认为这与10月份的“测试”配置(config/testing/cms.php)有关。 这将在目录“tests/fixture/themes/pages/”中查找文件。在那里找到的index.htm文件的url参数设置为“/”。 这就是为什么phpunit会找到它,而不是其他URL。 我看到了一些解决这个问题的建议,但没有一个对我有效:

  • 在运行测试之前使用“Config::set('cms.activeTheme','myTheme');”
  • 在config/testing/cms.php中将“pluginspath local”从“base_path('tests/fixture/plugins')”更改为“base_path('plugins')”
  • 在config/testing/cms.php中将“themesPathLocal”从“基本路径('tests/fixture/themes')”更改为“基本路径('themes')”

  • 如果我能想出如何以正确的方式访问我的主题页面,生活会轻松得多。

    不幸的是,没有解决方案,只是从不同的角度。我认为这与10月份的“测试”配置(config/testing/cms.php)有关。 这将在目录“tests/fixture/themes/pages/”中查找文件。在那里找到的index.htm文件的url参数设置为“/”。 这就是为什么phpunit会找到它,而不是其他URL。 我看到了一些解决这个问题的建议,但没有一个对我有效:

  • 在运行测试之前使用“Config::set('cms.activeTheme','myTheme');”
  • 在config/testing/cms.php中将“pluginspath local”从“base_path('tests/fixture/plugins')”更改为“base_path('plugins')”
  • 在config/testing/cms.php中将“themesPathLocal”从“基本路径('tests/fixture/themes')”更改为“基本路径('themes')”

  • 如果我能想出如何以正确的方式访问我的主题页面,生活会轻松得多……。

    这确实会让测试通过,但似乎更像是一种解决方法,而不是实际解决问题。:)祝你好运,我已经花了一年时间试图发现发生了什么,但是……这确实让测试通过了,但似乎更像是一种解决方法,而不是实际解决问题。:)祝你好运,我已经尝试了一年来发现发生了什么,但是…你能分享一下你的
    使用
    声明吗?我似乎无法获得
    use-illumb\Foundation\Testing\TestCase工作,我看到
    使用\PHPUnit\u Framework\u TestCase其他地方-哪种是首选/有效的
    使用
    风格?请分享您的
    使用
    语句好吗?我似乎无法获得
    use-illumb\Foundation\Testing\TestCase工作,我看到
    使用\PHPUnit\u Framework\u TestCase其他地方-哪个是首选/有效的
    使用
    样式?