auth()->user()->fresh()->notifications must be null rather than an empty Collection; how is notifications relationshop defined on the User class?
:assertCount() must be a countable or iterable - Laravel 7
Hey everyone,
Been trying to battle away with the Lets build a Forum with TDD, and I am about half way through, so far, its going OK, but been stuck for a while now on why I can't get my tests to pass.
Basically - all test are passing apart from this one:
public function test_a_notification_is_prepared_when_a_subscribed_thread_receives_a_new_reply_that_is_not_by_current_user()
{
$thread = create('App\Thread')->subscribe();
$this->assertCount(0, auth()->user()->notifications);
$thread->addReply([
'user_id' => auth()->id(),
'body' => 'Some reply here'
]);
$this->assertCount(0, auth()->user()->fresh()->notifications);
$thread->addReply([
'user_id' => create('App\User')->id,
'body' => 'Some reply here'
]);
$this->assertCount(1, auth()->user()->fresh()->notifications);
}
With the error in the test being
Argument #2 of PHPUnit\Framework\Assert::assertCount() must be a countable or iterable
I have commented out all 3 instances of this, and tried to debug it, but can't work it out. All other test are passing, I have also tried to look at the Github repo for the corresponding episodes and my code is almost identical - in fact I tried the code from the repo to double check I was being silly.
Has anyone come across this issue? The episodes are around 44-46 of the series "Lets build a forum with TDD"
I am building on Laravel 7 with PHP 7.4. The PHP unit version is 8.5.8.
I am not bothered at this stage if the test does not pass, I just want to change the error message!
Cheers
Ok can you dump(auth()->user()) and dd(auth()->user()->notifications to see what you are getting?
Please or to participate in this conversation.