Summer Sale! All accounts are 50% off this week.

david001's avatar

BadMethodCallException: Method Illuminate\Http\Response::assertEquals does not exist.

I am new to unit testing. I am trying to match the updated record but everytime i run i get following error BadMethodCallException: Method Illuminate\Http\Response::assertEquals does not exist.

and this is my test


      /** @test */
        public function a_book_can_be_updated()
        {
       
            $this->post('/books',[
                'title'=>'cool title',
                'author'=>'victor'
            ]);

            $book = Book::first();
           
            $reponse = $this->patch('/books/'.$book->id,[
                'title'=> 'a new title',
                'author'=>'new author'
            ]);
           
            $reponse->assertEquals('a new title',Book::first()->title);
            $reponse->assertEquals('new author',Book::first()->author);
        }

update method


 public function update(Book $book)
    {
        $data = request()->validate([
            'title'=>'required',
            'author'=>'required'
        ]);
0 likes
2 replies
Zubs's avatar

The error is coming from the fact that the $response object doesn't have an assertEquals method. To achieve the intended result, use the assertEquals that comes with PHPUnit like this:

$this->assertEquals('a new title', Book::first()->title);
2 likes

Please or to participate in this conversation.