Files
myep-team/tests/Service/Statistics/StatisticsDimensionsTest.php
T

66 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service\Statistics;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\Disposition;
use App\Entity\Teamer;
use App\Service\Statistics\StatisticsDimensions;
use PHPUnit\Framework\TestCase;
/**
* The dimension columns are what every statistics screen groups by, so the SER-stripping
* hotel-code rule has to be applied here exactly as the recorder used to apply it inline.
*/
class StatisticsDimensionsTest extends TestCase
{
public function testFreezesTheNormalizedHotelCodeOfTheAssignment(): void
{
$assignment = (new Assignment())->setDestination((new Destination())->setHotelCode('SERZIL'));
$this->assertSame('ZIL', StatisticsDimensions::forAssignment($assignment)['hotel_code']);
}
public function testKeepsAnUnprefixedHotelCodeAsItIs(): void
{
$assignment = (new Assignment())->setDestination((new Destination())->setHotelCode('SBW'));
$this->assertSame('SBW', StatisticsDimensions::forAssignment($assignment)['hotel_code']);
}
public function testADispositionCarriesItsTeamerAndTheAssignmentDimensions(): void
{
$teamer = new Teamer();
$assignment = (new Assignment())->setDestination((new Destination())->setHotelCode('SERZIL'));
$disposition = new Disposition(new Application($assignment, $teamer));
$dimensions = StatisticsDimensions::forDisposition($disposition);
$this->assertArrayHasKey('disposition_id', $dimensions);
$this->assertSame($teamer->getId(), $dimensions['teamer_id']);
$this->assertSame('ZIL', $dimensions['hotel_code']);
}
/**
* A disposition can lose its assignment or teamer; the columns just go null, they do not
* blow up the flush that is trying to record the event.
*/
public function testDegradesToNullWithoutAnAssignmentOrTeamer(): void
{
$disposition = new Disposition(new Application(new Assignment(), new Teamer()));
$disposition->setAssignment(null);
$disposition->setTeamer(null);
$dimensions = StatisticsDimensions::forDisposition($disposition);
$this->assertNull($dimensions['assignment_id']);
$this->assertNull($dimensions['destination_id']);
$this->assertNull($dimensions['hotel_code']);
$this->assertNull($dimensions['teamer_id']);
}
}