【发布时间】:2017-02-15 11:07:49
【问题描述】:
我是 Laravel 的新手,我对如何在 5.3 中测试我的 api 有点困惑。我阅读了文档并看到了这种示例,但我不知道我是否正确应用了这些示例。无论如何,我总是得到一个 ErrorException
我在 UserTest.php 中有这个
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UserTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testLoginSuccess()
{
$this->post('http://127.0.0.1/identificare_api/public/api/user/login', ['email' => 'identificare@gmail.com', 'password' => 'identificare']);
}
}
我也试过这个,还是不行。
$this->json('POST', 'user/login', ['email' => 'identificare@gmail.com', 'password' => 'identificare']);
这是我的路线
Route::post('user/login', 'UserController@login');
这样做是否正确?如果不是,测试我的 api 的正确方法是什么?
【问题讨论】:
-
我猜你的错误处理程序有错误! 'e' 可能是 try-catch 块中缺少的参数?我不知道 app/Exceptions 路径是什么——这在 Laravel 中并不常见,所以如果这是您的自定义类路径,我建议您查看错误所在的第 47 行。 $e 是否像 catch($e Exception) 一样被声明? ...然后就可以调试异常了。
标签: php unit-testing laravel-5.3