Laravel5.8 使用 phpunit 测试报错
环境:
Mac 10.14.4 + php 7.3.4 + laravel 5.8 + PHPUnit 6.5.3
控制器代码:
namespace App\Http\Controllers\Admin;
class TestController extends Controller
{
public function index()
{
return ['success' => true];
}
}
测试代码:
namespace Tests\Feature;
use Tests\TestCase;
class UserTest extends TestCase
{
public function testLists()
{
$response = $this->json('GET', '/admin/test');
// dd($response);
$response->assertStatus(200);
}
}
Postman直接请求接口:
运行phpunit命令:
打印 $response
PHPUnit 6.5.3 by Sebastian Bergmann and contributors.
Illuminate\Foundation\Testing\TestResponse {#462
+baseResponse: Illuminate\Http\JsonResponse {#521
#data: "{"success":true}"
#callback: null
#encodingOptions: 0
+headers: Symfony\Component\HttpFoundation\ResponseHeaderBag {#520
#computedCacheControl: array:2 [
"no-cache" => true
"private" => true
]
#cookies: []
#headerNames: array:3 [
"cache-control" => "Cache-Control"
"date" => "Date"
"content-type" => "Content-Type"
]
#headers: array:3 [
"cache-control" => array:1 [
0 => "no-cache, private"
]
"date" => array:1 [
0 => "Fri, 26 Jul 2019 13:46:15 GMT"
]
"content-type" => array:1 [
0 => "application/json"
]
]
#cacheControl: []
}
#content: "{"success":true}"
#version: "1.1"
#statusCode: 200
#statusText: "OK"
#charset: null
+original: array:1 [
"success" => true
]
+exception: null
}
#streamedContent: null
}
第一次使用phpunit,看到这个问题完全没有思路,不知道应该从那里调试,希望能提供一个思路,我能继续研究下去! 非常感谢!
推荐文章: