Laravel 5 phpunit getContent返回空
我正在学习Laravel 5.4,对Laravel和PHPUnit来说仍然是新的。在遵循在线基础教程之后,一切都很好 运行phpunit时,此测试功能正常工作Laravel 5 phpunit getContent返回空,laravel-5,phpunit,Laravel 5,Phpunit,我正在学习Laravel 5.4,对Laravel和PHPUnit来说仍然是新的。在遵循在线基础教程之后,一切都很好 运行phpunit时,此测试功能正常工作 public function testBasicExample() { $response = $this->call( 'GET' , '/welcome'); $this->assertTrue(strpos($response->getContent(), 'Laravel') !== fals
public function testBasicExample()
{
$response = $this->call( 'GET' , '/welcome');
$this->assertTrue(strpos($response->getContent(), 'Laravel') !== false);
}
当我尝试测试Api时,问题出现了
我采取的步骤
在调用api之前,请尝试使用工厂创建一些数据: e、 g: 然后
如果您在phpunit.xml上设置“:memory:”作为您的数据库,您将不再看到本地数据库中的任何数据,这就是为什么您应该改用factory的原因。我遇到了类似的问题,即curl调用在内容中返回正确的JSON响应,但是API调用在public$original中显示类对象信息,但是public$内容是{}。你找到解决办法了吗?
public function index()
{
$users = DB::table('users')->get()->toJson();
echo $users;
}
public function test_index_method_returns_all_books()
{
$response = $this->call( 'GET' , '/api/books/');
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getContent(),true);
$this->assertJson($data);
}
factory(\App\Books::class, 20)->create();
$response = $this->call( 'GET' , '/api/books/');