Figured out what's causing that issue its the mass assignment issue in my model
Favorite.php
protected $guarded = [];
This removed the error.
Following Jeffrey's Build a Forum tutorials results in failed test
PHPUnit 8.0.5 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 347 ms, Memory: 28.00 MB
There was 1 failure:
1) Tests\Feature\FavoritesTest::an_authenticated_user_can_favorite_any_reply
Failed asserting that actual size 0 matches expected size 1.
The test is as follows
/** @test */
public function an_authenticated_user_can_favorite_any_reply()
{
$this->signIn();
$reply = create('App\Reply');
$this->post('replies/' . $reply->id . '/favorites');
$this->assertCount(1, $reply->favorites);
}
web.php is as follows
Route::post('replies/{reply}/favorites', 'FavoritesController@store');
And in the controller is the store method as below
FavoritesController.php
public function store(Reply $reply)
{
Favorite::create([
'user_id' => auth()->user()->id,
'favorited_id' => $reply->id,
'favorited' => get_class($reply)
]);
}
When I dd the Favorite::all() in the test after the post I get a blank array. What could I possibly be doing wrong ?
Please or to participate in this conversation.