dougu6815 2014-11-29 14:33
浏览 5
已采纳

测试和模拟。 谁在说话?

This is my test

 use Lean\Core;
 use Symfony\Component\HttpFoundation\Request;

class TestCore extends PHPUnit_Framework_TestCase{
    public function tearDown() {
        Mockery::close();
    }
    public function test_handle_returns_a_response(){
        $request = Mockery::mock("Request");
        $request->shouldReceive("create")->once()->andReturn(new Request);
        $core = new Core();
        $response = $core->handle($request->create("d"));
        $output = $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response',$response);
    }
} 

And this is the handle function of my Core Class

 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        switch($request->getPathInfo()) {
            case "/":
                return new Response("Welcome to the main page");
                break;
            case "/d":
                return new Response("d");
                break;
            default:
                return new Response("This route doesn't exist");
        }

I feel like I'm doing something very stupid. I use PHP 5.6 and Mockery + PHPUNIT. This works but when I try to return the mock object, the handle function says it needs an instance of Request

UPDATE

Just to Clarify, this works. But I'm basically being counter intuitive. I want to be a ble to pass the mock itself

  • 写回答

1条回答 默认 最新

  • doudou6719 2014-11-29 14:46
    关注

    I think that you need provide full name of Request.

    $request = Mockery::mock("Symfony\Component\HttpFoundation\Request");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导