0
votes

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

1 Answers

0
votes

I think that you need provide full name of Request.

$request = Mockery::mock("Symfony\Component\HttpFoundation\Request");