You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
<?php
|
|
|
|
namespace Tests\Generators;
|
|
|
|
use Tests\TestCase;
|
|
|
|
class ModelFactoryGeneratorTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function it_creates_correct_model_factory_content()
|
|
{
|
|
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
|
|
|
|
$modelFactoryPath = database_path('factories/'.$this->model_name.'Factory.php');
|
|
$this->assertFileExists($modelFactoryPath);
|
|
$modelFactoryContent = "<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\User;
|
|
use {$this->full_model_name};
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class {$this->model_name}Factory extends Factory
|
|
{
|
|
protected \$model = {$this->model_name}::class;
|
|
|
|
public function definition()
|
|
{
|
|
return [
|
|
'name' => \$this->faker->word,
|
|
'description' => \$this->faker->sentence,
|
|
'creator_id' => function () {
|
|
return User::factory()->create()->id;
|
|
},
|
|
];
|
|
}
|
|
}
|
|
";
|
|
$this->assertEquals($modelFactoryContent, file_get_contents($modelFactoryPath));
|
|
}
|
|
}
|