【发布时间】:2015-01-27 23:35:02
【问题描述】:
这是我的测试
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);
}
}
这是我的核心类的句柄函数
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");
}
我觉得我在做一些非常愚蠢的事情。 我使用 PHP 5.6 和 Mockery + PHPUNIT。 这可行,但是当我尝试返回模拟对象时,句柄函数说它需要一个 Request 实例
更新
只是为了澄清,这是有效的。 但我基本上是反直觉的。我希望能够通过模拟本身
【问题讨论】:
标签: php testing phpunit mockery