-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from spatie/feature/88-opening-hours-across-m…
…idnight Feature/88 opening hours across midnight
- Loading branch information
Showing
4 changed files
with
155 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
preset: laravel | ||
|
||
disabled: | ||
- short_list_syntax | ||
|
||
enabled: | ||
- long_list_syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Spatie\OpeningHours\Test; | ||
|
||
use DateTime; | ||
use DateTimeImmutable; | ||
use PHPUnit\Framework\TestCase; | ||
use Spatie\OpeningHours\TimeRange; | ||
use Spatie\OpeningHours\OpeningHours; | ||
|
||
class OpeningHoursOverflowTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_fills_opening_hours_with_overflow() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'overflow' => true, | ||
'monday' => ['09:00-02:00'], | ||
], null); | ||
|
||
$this->assertInstanceOf(TimeRange::class, $openingHours->forDay('monday')[0]); | ||
$this->assertEquals((string) $openingHours->forDay('monday')[0], '09:00-02:00'); | ||
} | ||
|
||
/** @test */ | ||
public function check_open_with_overflow() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'overflow' => true, | ||
'monday' => ['09:00-02:00'], | ||
], null); | ||
|
||
$shouldBeOpen = new DateTime('2019-04-23 01:00:00'); | ||
$this->assertTrue($openingHours->isOpenAt($shouldBeOpen)); | ||
} | ||
|
||
/** @test */ | ||
public function check_open_with_overflow_immutable() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'overflow' => true, | ||
'monday' => ['09:00-02:00'], | ||
], null); | ||
|
||
$shouldBeOpen = new DateTimeImmutable('2019-04-23 01:00:00'); | ||
$this->assertTrue($openingHours->isOpenAt($shouldBeOpen)); | ||
} | ||
|
||
/** @test */ | ||
public function next_close_with_overflow() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'overflow' => true, | ||
'monday' => ['09:00-02:00'], | ||
], null); | ||
|
||
$shouldBeOpen = new DateTime('2019-04-23 01:00:00'); | ||
$this->assertEquals('2019-04-23 02:00:00', $openingHours->nextClose($shouldBeOpen)->format('Y-m-d H:i:s')); | ||
} | ||
|
||
/** @test */ | ||
public function next_close_with_overflow_immutable() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'overflow' => true, | ||
'monday' => ['09:00-02:00'], | ||
], null); | ||
|
||
$shouldBeOpen = new DateTimeImmutable('2019-04-23 01:00:00'); | ||
$nextTimeClosed = $openingHours->nextClose($shouldBeOpen)->format('Y-m-d H:i:s'); | ||
$this->assertEquals('2019-04-23 02:00:00', $nextTimeClosed); | ||
$this->assertEquals('2019-04-23 01:00:00', $shouldBeOpen->format('Y-m-d H:i:s')); | ||
} | ||
} |