-
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.
Browse files
Browse the repository at this point in the history
* Add asStructuredData to README usage * Allow on construction for setting a flag for overlapping times. A night club opens that opens till 3am on Friday and Saturday. And modify the API to search for yesterday * Oops, change docs to use overflowing rather than overlapping * Fix styleguide
- Loading branch information
1 parent
b6b141a
commit 03d2d44
Showing
3 changed files
with
140 additions
and
13 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
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,69 @@ | ||
<?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([ | ||
'monday' => ['09:00-02:00'], | ||
], null, true); | ||
|
||
$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([ | ||
'monday' => ['09:00-02:00'], | ||
], null, true); | ||
|
||
$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([ | ||
'monday' => ['09:00-02:00'], | ||
], null, true); | ||
|
||
$shouldBeOpen = new DateTimeImmutable('2019-04-23 01:00:00'); | ||
$this->assertTrue($openingHours->isOpenAt($shouldBeOpen)); | ||
} | ||
|
||
/** @test */ | ||
public function next_close_with_overflow() | ||
{ | ||
$openingHours = OpeningHours::create([ | ||
'monday' => ['09:00-02:00'], | ||
], null, true); | ||
|
||
$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([ | ||
'monday' => ['09:00-02:00'], | ||
], null, true); | ||
|
||
$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')); | ||
} | ||
} |