如何解决无法断言实际尺寸2与预期尺寸1相匹配
我有用于图书管理测试的功能测试
class BookManagemantTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function a_book_can_added_to_the_library()
{
//$this->withoutExceptionHandling();
$response = $this->post('/book',[
'title' => 'Book title','author' => 'faraz',]);
$response->assertOk();
$this->assertCount(1,Book::all());
return Book::all();
}
/** @test */
public function a_book_can_be_updated()
{
$book = $this->a_book_can_added_to_the_library()->first();
$response = $this->patch('/book/' . $book->id,[
'title' => 'new title','author' => 'new author',]);
$response->assertOk();
$this->assertEquals('new title',Book::first()->title);
$this->assertEquals('new author',Book::first()->author);
}
}
如果我测试仅测试a_book_can_be_updated()方法..我将通过测试。 (PHP供应商/ phpunit / phpunit / phpunit --filter a_book_can_be_updated)
但是,如果我测试了全班考试,则会收到此错误。
我认为
- Tests \ Feature \ BookManagemantTest :: a_book_can_be_updated 无法断言实际尺寸2与预期尺寸1相符。
控制器工作很好:
<?php
namespace App\Http\Controllers;
use App\Book;
use Illuminate\Http\Request;
class BookController extends Controller
{
public function store(Request $request)
{
Book::create($this->validate_request($request));
}
public function update(Request $request,Book $book)
{
$book->update($this->validate_request($request));
}
public function validate_request(Request $request)
{
return $request->validate([
'title' => 'required','author' => 'required',]);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。