* #23 - wip * #23 - wip * #23 - wip * #23 - wip * #23 - fix * #23 - ecs fix * #23 - fix * #23 - fix * #23 - cr fix
This commit is contained in:
49
tests/Traits/InteractsWithYearPeriods.php
Normal file
49
tests/Traits/InteractsWithYearPeriods.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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([]);
|
||||
}
|
||||
|
||||
public function cleanYearPeriods(): void
|
||||
{
|
||||
$this->clearSelectedYearPeriod();
|
||||
|
||||
YearPeriod::query()->delete();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user