Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Danieloplata's avatar

ParseError: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';'

Currently following this lesson (I'm using Laravel 5.7)

https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/4?autoplay=true

I'm getting the following error in my test:

1) Tests\Unit\ThreadTest::a_thread_is_owned_by_a_user
ParseError: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';'

Here is the code from my test:

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ThreadTest extends TestCase
{

    use RefreshDatabase;

    protected $thread;

    public function setUp()
    {
        parent::setUp();
        $this->thread = factory('App\Thread')->create();
    }

    /** @test */
    public function a_thread_is_owned_by_a_user()
    {
        $this->assertInstanceOf('App\User', $this->thread->user);
    }

    /** @test */
    public function a_thread_has_replies()
    {
        $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $this->thread->replies);
    }

    /** @test */
    public function a_thread_can_add_a_reply()
    {
        $this->thread->addReply([
            'body' => 'Foobar',
            'user_id' => 1
        ]);

        $this->assertCount(1, $this->thread->replies);
    }

}

I'm guessing based on the error that I've made a stupid mistake somewhere in here, but I can't seem to spot it

0 likes
3 replies
goatshark's avatar
Level 14

@Danieloplata Probably just a missing ;, but in your User::class or Thread::class. Your test looks good.

1 like
Danieloplata's avatar

@goatshark Thanks Goatshark, I thought the error must exist in the test page.

I've found the error in my Thread::class. Was missing a semi colon where I had deviated slightly from the lesson (I feel safer using $fillable rather than $guarded = [])

protected $fillable = [
    'user_id',
    'title',
    'body'
]

Please or to participate in this conversation.