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");
    
    点赞 评论

相关推荐 更多相似问题