Files
myep-team/tests/Service/Assignment/StaffingFixturesTrait.php
T

94 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service\Assignment;
use App\Entity\Destination;
use App\Entity\StaffingRule;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
/**
* Rows for running the staffing matrix against db_test. The job profiles and fees are written
* with the ids config/services.yaml configures, because StaffingResolver looks them up by id.
*/
trait StaffingFixturesTrait
{
private function resetStaffingTables(Connection $connection): void
{
$connection->executeStatement('DELETE FROM assignment_fee');
$connection->executeStatement('DELETE FROM assignment');
$connection->executeStatement('DELETE FROM destination');
$connection->executeStatement('DELETE FROM staffing_rule');
$connection->executeStatement('DELETE FROM job_profile_training WHERE job_profile_id IN (3, 5, 14, 20, 21)');
$connection->executeStatement('DELETE FROM job_profile WHERE id IN (3, 5, 14, 20, 21)');
$connection->executeStatement('DELETE FROM fee WHERE id IN (3, 4)');
foreach ([
5 => 'Reiseleitung',
3 => 'Kursleitung Ski Anfänger:innen',
14 => 'Kursleitung Ski Fortgeschrittene',
20 => 'Reise- und Kursleitung Ski Anfänger:innen',
21 => 'Reise- und Kursleitung Ski Fortgeschrittene',
] as $id => $name) {
$connection->insert('job_profile', [
'id' => $id,
'uuid' => sprintf('00000000-0000-4000-8000-%012d', $id),
'name' => $name,
'required_licenses' => '[]',
'created_at' => '2026-01-01 00:00:00',
]);
}
foreach ([3 => 'Skigebietsguiding (pro Einheit)', 4 => 'Ski-/Snowboardkurs (pro Stunde)'] as $id => $name) {
$connection->insert('fee', [
'id' => $id,
'value' => 10000,
'name' => $name,
'name_internal' => $name,
'created_at' => '2026-01-01 00:00:00',
]);
}
}
private function staffingRule(EntityManagerInterface $entityManager, string $productCode, bool $enabled = true): StaffingRule
{
$rule = (new StaffingRule())
->setProductCode($productCode)
->setGuides(2)
->setSkiBeginner(true)
->setGuiding(true)
->setBusEscort(true)
->setEnabled($enabled)
;
$entityManager->persist($rule);
return $rule;
}
private function staffingDestination(EntityManagerInterface $entityManager, string $code, string $productCode): Destination
{
$destination = (new Destination())
->setCode($code)
->setProductCode($productCode)
->setDateFrom(new \DateTimeImmutable('+1 month'))
->setDateTo(new \DateTimeImmutable('+1 month +5 days'))
->setProduct('Davos Klosters - Schwendi')
->setHotel('Schwendi')
->setHotelCode('DKI')
->setHotelBusProId(1)
->setPickups([
['busProId' => 7, 'city' => 'Kassel', 'street' => null, 'time' => '00:30', 'datetime' => null],
['busProId' => 5, 'city' => 'Göttingen', 'street' => null, 'time' => '22:00', 'datetime' => '2026-11-15T22:00:00+01:00'],
])
->setImportedAt(new \DateTimeImmutable('today 03:20'))
;
$entityManager->persist($destination);
return $destination;
}
}