我想用基本身份验证测试一个小API。
路线看起来像这样:
Route::group(array('prefix' => 'api/v1', 'before' => 'auth.basic'), function()
{
Route::get('/', function()
{
return 'Hello';
});
});
测试看起来像那样:
class APITest extends TestCase {
public function testHTTPAuthFailed()
{
$response = $this->call('GET', 'api/v1');
fwrite(STDERR, print_r($response->getContent(), TRUE));
}
}
当我用phpunit运行测试时,我可以看到" Hello"在控制台。它不是我排除的,我以为我会看到"身份验证失败"。但是,如果我尝试使用cURL(在终端上)调用我的API,我可以看到身份验证失败(所以它没问题,它是我的例外情况):
$ curl -i host/api/v1
HTTP/1.1 401 Unauthorized
那么为什么phpunit在laravel(4.2)中跳过(?)基本身份验证。如何测试无效凭证?