Seeds
This commit is contained in:
55
app/tests/extension/Seeds/Promotions.php
Normal file
55
app/tests/extension/Seeds/Promotions.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use DateInterval;
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Promotions extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$projects = $this->loadValues('proyecto', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
$count = $this->faker->numberBetween(1, 10);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$start = $this->faker->dateTimeBetween('-1 year');
|
||||
$end = $this->faker->dateTimeBetween($start, $start->add(new DateInterval('P1Y')));
|
||||
$data[] = [
|
||||
'description' => $this->faker->sentence,
|
||||
'type' => 1,
|
||||
'amount' => $this->faker->randomFloat(2, 0, 1),
|
||||
'start_date' => $start,
|
||||
'end_date' => $end,
|
||||
'valid_until' => $this->faker->dateTimeBetween($end, $end->add(new DateInterval('P1M'))),
|
||||
'state' => 1,
|
||||
];
|
||||
}
|
||||
$this->table('promotions')->insertValues($data)->save();
|
||||
|
||||
$promotions = $this->loadValues('promotions', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
foreach ($projects as $project) {
|
||||
$hasPromo = $this->faker->boolean(10);
|
||||
if (!$hasPromo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data []= [
|
||||
'promotion_id' => $this->faker->randomElement($promotions),
|
||||
'project_id' => $project,
|
||||
];
|
||||
}
|
||||
if (count($data) > 0) {
|
||||
$this->table('promotion_projects')->insertValues($data)->save();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user