toby/tests/Traits/InteractsWithYearPeriods.php
Adrian Hopek 5a51f24342 #23 - wip
2022-01-21 15:17:59 +01:00

38 lines
894 B
PHP

<?php
declare(strict_types=1);
namespace Tests\Traits;
use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
use Illuminate\Support\Carbon;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\YearPeriod;
trait InteractsWithYearPeriods
{
use InteractsWithSession;
public function createYearPeriod(int $year): YearPeriod
{
/** @var YearPeriod $yearPeriod */
$yearPeriod = YearPeriod::factory()->create(["year" => $year]);
return $yearPeriod;
}
public function createCurrentYearPeriod(): YearPeriod
{
return $this->createYearPeriod(Carbon::now()->year);
}
public function markYearPeriodAsSelected(YearPeriod $yearPeriod): void
{
$this->session([YearPeriodRetriever::SESSION_KEY => $yearPeriod->id]);
}
public function clearSelectedYearPeriod(): void
{
$this->session([]);
}
}