phpunit中的模拟http服务器

phpunit中的模拟http服务器,php,unit-testing,phpunit,fuelphp,Php,Unit Testing,Phpunit,Fuelphp,我为我的控制器写了一个测试,它需要$\u服务器[REQUEST\u URI],我如何模拟它并使它运行 我的控制器是 public function action_index() { $presenter = Presenter::forge('www/php'); $this->template->content = $presenter; } 我的测试是 public function test_action_index() { $response = Request

我为我的控制器写了一个测试,它需要$\u服务器[REQUEST\u URI],我如何模拟它并使它运行 我的控制器是

public function action_index()
{
  $presenter = Presenter::forge('www/php');
  $this->template->content = $presenter;
}
我的测试是

public function test_action_index()
{
  $response = Request::forge('www/php')
    ->set_method('GET')
    ->execute()
    ->response();
  $this->assertContains(' List', $response->body->__toString());
  Cli::write(__METHOD__ . "   √ \n", 'green');
}
  • 你可以自己设置这个全局,但它非常难看
  • 您可以通过SetEnv进行设置(请参阅此博客:)
  • 但是,最好使用$\u服务器['*'更改您的行
  • 为什么?

    单元测试的描述如下:

    对您的方法进行一次小型的孤立的测试


    您的代码将取决于全局!不例如,使用请求对象获取uri。

    我认为测试控制器不是PhpUnit的事。我最好使用一些E2E测试