无法断言实际尺寸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)

但是,如果我测试了全班考试,则会收到此错误

  1. 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 (将#修改为@)