* - directory refactor * - readme.md update * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
		
			
				
	
	
		
			83 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace Tests\Unit;
 | 
						|
 | 
						|
use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
 | 
						|
use Illuminate\Foundation\Testing\RefreshDatabase;
 | 
						|
use Illuminate\Support\Carbon;
 | 
						|
use Tests\TestCase;
 | 
						|
use Tests\Traits\InteractsWithYearPeriods;
 | 
						|
use Toby\Eloquent\Helpers\YearPeriodRetriever;
 | 
						|
use Toby\Eloquent\Models\YearPeriod;
 | 
						|
 | 
						|
class YearPeriodRetrieverTest extends TestCase
 | 
						|
{
 | 
						|
    use RefreshDatabase;
 | 
						|
    use InteractsWithSession;
 | 
						|
    use InteractsWithYearPeriods;
 | 
						|
 | 
						|
    public Carbon $current;
 | 
						|
    public YearPeriod $previousYearPeriod;
 | 
						|
    public YearPeriod $currentYearPeriod;
 | 
						|
    public YearPeriod $nextYearPeriod;
 | 
						|
    public YearPeriodRetriever $yearPeriodRetriever;
 | 
						|
 | 
						|
    protected function setUp(): void
 | 
						|
    {
 | 
						|
        parent::setUp();
 | 
						|
 | 
						|
        $this->current = Carbon::now();
 | 
						|
        Carbon::setTestNow($this->current);
 | 
						|
 | 
						|
        $this->yearPeriodRetriever = $this->app->make(YearPeriodRetriever::class);
 | 
						|
 | 
						|
        $this->previousYearPeriod = $this->createYearPeriod($this->current->year - 1);
 | 
						|
        $this->currentYearPeriod = $this->createCurrentYearPeriod();
 | 
						|
        $this->nextYearPeriod = $this->createYearPeriod($this->current->year + 1);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testRetrievesCorrectCurrentYearPeriod(): void
 | 
						|
    {
 | 
						|
        $this->assertSame($this->currentYearPeriod->id, $this->yearPeriodRetriever->current()->id);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testRetrievesCurrentYearPeriodWhenNoneIsSelected(): void
 | 
						|
    {
 | 
						|
        $this->clearSelectedYearPeriod();
 | 
						|
 | 
						|
        $this->assertSame($this->currentYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testRetrievesCorrectYearPeriodWhenSelected(): void
 | 
						|
    {
 | 
						|
        $this->markYearPeriodAsSelected($this->nextYearPeriod);
 | 
						|
 | 
						|
        $this->assertSame($this->nextYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testLinks(): void
 | 
						|
    {
 | 
						|
        $expected = [
 | 
						|
            "current" => $this->current->year,
 | 
						|
            "navigation" => [
 | 
						|
                [
 | 
						|
                    "year" => $this->previousYearPeriod->year,
 | 
						|
                    "link" => route("year-periods.select", $this->previousYearPeriod),
 | 
						|
                ],
 | 
						|
                [
 | 
						|
                    "year" => $this->currentYearPeriod->year,
 | 
						|
                    "link" => route("year-periods.select", $this->currentYearPeriod),
 | 
						|
                ],
 | 
						|
                [
 | 
						|
                    "year" => $this->nextYearPeriod->year,
 | 
						|
                    "link" => route("year-periods.select", $this->nextYearPeriod),
 | 
						|
                ],
 | 
						|
            ],
 | 
						|
        ];
 | 
						|
 | 
						|
        $this->assertSame($expected, $this->yearPeriodRetriever->links());
 | 
						|
    }
 | 
						|
}
 |