Files
myep-team/tests/Repository/HouseManagerReminderQueryTest.php
T

109 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Repository;
use App\Entity\Destination;
use App\Entity\Teamer;
use App\Entity\User;
use App\Repository\DestinationRepository;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Who the nightly house manager reminder writes to and what it reminds them of, against db_test
* with real rows.
*
* Every test runs inside a transaction that is rolled back, so db_test - shared between
* branches - keeps nothing.
*/
class HouseManagerReminderQueryTest extends KernelTestCase
{
use QuestionnaireFixturesTrait;
private EntityManagerInterface $entityManager;
private Teamer $teamer;
protected function setUp(): void
{
self::bootKernel();
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->entityManager->getConnection()->beginTransaction();
$this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d');
$this->entityManager->persist($this->teamer);
}
protected function tearDown(): void
{
$this->entityManager->getConnection()->rollBack();
parent::tearDown();
}
/**
* A house manager who worked on the travel themselves does not rate their own placement, so
* it must not keep the travel pending for them - only someone else's unrated one does.
*/
public function testTheHouseManagersOwnPlacementDoesNotKeepATravelPending(): void
{
$houseManager = $this->houseManager('[email protected]');
$ownOnly = $this->escort(teamer: $houseManager->getTeamer(), hotel: 'Nur selbst')->getAssignment()->getDestination();
$withOther = $this->escort(hotel: 'Mit anderen')->getAssignment()->getDestination();
$this->entityManager->flush();
$pending = array_column($this->destinationRepository()->findPendingForHouseManager(
$houseManager,
new \DateTimeImmutable('2099-01-01'), // questionnaire not live: only ratings count
new \DateTimeImmutable('today')
), 0);
$this->assertContains($withOther, $pending);
$this->assertNotContains($ownOnly, $pending);
}
public function testBlockedAndDeletedHouseManagersAreNotReminded(): void
{
$active = $this->houseManager('[email protected]');
$blocked = $this->houseManager('[email protected]')->setDisabledAt(new \DateTimeImmutable());
$deleted = $this->houseManager('[email protected]')->setDeletedAt(new \DateTimeImmutable());
$this->entityManager->flush();
/** @var UserRepository $repository */
$repository = $this->entityManager->getRepository(User::class);
$reminded = $repository->findHouseManagersToRemind();
$this->assertContains($active, $reminded);
$this->assertNotContains($blocked, $reminded);
$this->assertNotContains($deleted, $reminded);
}
private function houseManager(string $email): User
{
$teamer = (new Teamer())->setFirstName('Hanna')->setLastName('Haus')->setGender('d');
$user = (new User())
->setFirstName('Hanna')
->setLastName('Haus')
->setEmail(uniqid('', true).'.'.$email)
->setRoles(['ROLE_HOUSE_MANAGER'])
->setHotelCodes(['DKI'])
->setBusProAddressId(1)
->setBusProPersonId(1)
->setTeamer($teamer)
;
$teamer->setUser($user);
$this->entityManager->persist($teamer);
$this->entityManager->persist($user);
return $user;
}
private function destinationRepository(): DestinationRepository
{
return $this->entityManager->getRepository(Destination::class);
}
}