Laravel 8 testing do not pass data through call

Viewed 22

in my code i want save a category in db and check whether it has been saved or not but the code seems to not work. my data $category1 does not get passed through the call function. if I use create instead of make in factory then the entire command becomes redundant. I want test basically create operation working or not.

Test:

/**
  * @test
  */
  public function save_method_saves_a_category()
  {
      $category1 = Category::factory()->make([
          'id' => '1',
      ]);
      $this->call('POST','/submitcategory',[$category1]);

      $this->assertDatabaseHas('categories', [
          'id' => '1',
          'name' => $category1->name
      ]);
  }

Route:

Route::post('/submitcategory', [CategoryController::class,'save']);

Controller:

public function save(Request $r){
      $cat = new Category;
      $cat->name=$r->name;
      $cat->parent_id=$r->parent_id;
      $cat->description=$r->description;
      $cat->slug=$r->slug;
      $cat->save();
      return redirect('/admin/categories');
    }
0 Answers
Related