feat: all-season assignments

This commit is contained in:
Björn Fromme authored and Björn Fromme committed 2026-09-26 12:13:16 +02:00
1 parent 675cec1b69
commit cf876ed224
119 files changed
+6194 -294

No files matched your search

@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Common;
use App\Model\TeamerFilterDto;
use App\Service\Common\TeamerFilterHandler;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
/**
* Two teamer lists share one filter form, so the only thing keeping them apart is the session
* bucket the settings are stored under. Without the split, filtering the Teamübersicht would
* silently narrow the Saisonteamer list as well - and the other way round.
*/
class TeamerFilterHandlerTest extends TestCase
{
public function testEachListKeepsItsOwnFilterSettings(): void
{
$handler = $this->createHandler();
$this->save($handler->setScope(null), 'Fromme');
$this->save($handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON), 'Musterfrau');
$this->assertSame('Fromme', $handler->setScope(null)->getFilterSettings()->getName());
$this->assertSame(
'Musterfrau',
$handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON)->getFilterSettings()->getName()
);
}
public function testResettingOneListLeavesTheOtherAlone(): void
{
$handler = $this->createHandler();
$this->save($handler->setScope(null), 'Fromme');
$this->save($handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON), 'Musterfrau');
$handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON)->resetFilterSettings();
$this->assertSame('Fromme', $handler->setScope(null)->getFilterSettings()->getName());
$this->assertNull(
$handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON)->getFilterSettings()->getName()
);
}
/**
* The bucket is what makes a list an all-season list, so every reader of the settings gets
* the scope without having to remember to apply it - the mailing above all.
*/
public function testTheScopeTravelsWithTheSettings(): void
{
$handler = $this->createHandler();
$this->assertFalse($handler->setScope(null)->getFilterSettings()->isAllSeason());
$this->assertTrue(
$handler->setScope(TeamerFilterHandler::SCOPE_ALL_SEASON)->getFilterSettings()->isAllSeason()
);
}
public function testAnUnknownScopeFallsBackToTheGeneralList(): void
{
$handler = $this->createHandler();
$this->save($handler->setScope(null), 'Fromme');
$this->assertSame('Fromme', $handler->setScope('nonsense')->getFilterSettings()->getName());
$this->assertFalse($handler->setScope('nonsense')->getFilterSettings()->isAllSeason());
}
private function save(TeamerFilterHandler $handler, string $name): void
{
$reflection = new \ReflectionMethod($handler, 'saveFilterSettings');
$reflection->invoke($handler, (new TeamerFilterDto())->setName($name));
}
private function createHandler(): TeamerFilterHandler
{
$request = new Request();
$request->setSession(new Session(new MockArraySessionStorage()));
$requestStack = new RequestStack();
$requestStack->push($request);
return new TeamerFilterHandler($requestStack, $this->createMock(EntityManagerInterface::class));
}
}