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

Bacchus's avatar

Assert::assertInstanceOf() must be a class or interface name

Hello everyone,

I'm trying to follow along with "Build a Laravel App with TDD" on Laravel 6.x.

I've already figured out that I need to change the TestCast back to 'Tests\TestCase' for many things in the tutorial to work, but this particular issue has me stuck.

    /** @test */
    public function a_task_belongs_to_a_project()
    {
        $task = factory(Task::class)->create();

        $this->assertInstanceOf(Project::class, $task->project);
    }

When I run this, my output is:

There was 1 error:

1) Tests\Unit\TaskTest::a_task_belongs_to_a_project
PHPUnit\Framework\InvalidArgumentException: Argument #1 of PHPUnit\Framework\Assert::assertInstanceOf() must be a class or interface name

What could be happening here?

0 likes
6 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Did you import project at the top?

use App\Project;
1 like
Sinnbeck's avatar

If that does not work, try this

$this->assertInstanceOf('\App\Project', $task->project);
3 likes
Bacchus's avatar

That's a little embarrassing. The use statement was the problem. Thanks for your help.

dhikrullah's avatar

Yes, that worked for me too, just import or use the Class name. cheers

Please or to participate in this conversation.