Level 104
Make sure your Unit Test extends the Tests\TestCase class; not the PHPUnit `TestCase class
2 likes
Summer Sale! All accounts are 50% off this week.
My factory code
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Project>
*/
class ProjectFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => $this->faker->sentence,
'description' => $this->faker->sentence,
];
}
}
my migration
$table->string('title');
$table->string('description');
wanted to run this test it shows me this error
public function test_it_has_a_path()
{
$project = Project::factory()->create();
$this->assertEquals('/projects/' . $project->id, $project->path());
}
@Shivamyadav this should work - note the space is removed and ensure there are double quotes (") used:
public function path()
{
return "/projects/{$this->id}";
}
Please or to participate in this conversation.