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

Antonella's avatar

TDD: Error: Class 'http\Client\Curl\User' not found

I'm doing the exercise from lesson 05 :A Project Requires An Owner minute 09:47

I wrote this unit test for User:

namespace Tests\Unit;

use http\Client\Curl\User;
use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;

class UserTest extends TestCase
{
    use RefreshDatabase;

    public function test_a_user_has_projects()
    {
        $user = User::factory()->create();

        $this->assertInstanceOf(Collection::class,$user->projects);
    }
}

but i get this error which is not present in the course:

  1. Tests\Unit\UserTest::test_a_user_has_projects Error: Class 'http\Client\Curl\User' not found

i can't solve it

0 likes
4 replies
Sergiu17's avatar

use http\Client\Curl\User; namespace is incorrect

should be, App\Models\User

Antonella's avatar

i changed as follows:

namespace Tests\Unit;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;

use Tests\TestCase;

class UserTest extends TestCase
{
    use RefreshDatabase;

    public function test_a_user_has_projects()
    {
        $user = User::factory()->create();

        $this->assertInstanceOf(Collection::class,$user->projects);
    }
}

but I get the following error always not present in the course:

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

Tray2's avatar

Add the Collection class the use statements.

2 likes
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

add this use Illuminate\Support\Collection; at the top

Please or to participate in this conversation.