Skip to content

Commit

Permalink
Add tests for cap and limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Nov 11, 2023
1 parent 96128ab commit 6f80acd
Showing 1 changed file with 112 additions and 10 deletions.
122 changes: 112 additions & 10 deletions tests/OpeningHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTimeZone;
use PHPUnit\Framework\TestCase;
use Spatie\OpeningHours\Exceptions\MaximumLimitExceeded;
use Spatie\OpeningHours\Exceptions\SearchLimitReached;
use Spatie\OpeningHours\OpeningHours;
use Spatie\OpeningHours\OpeningHoursForDay;
use Spatie\OpeningHours\Time;
Expand Down Expand Up @@ -1079,7 +1080,7 @@ public function it_can_set_the_timezone_on_construct_with_string()
}

/** @test */
public function it_throw_an_exception_on_invalid_timezone()
public function it_throws_an_exception_on_invalid_timezone()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid Timezone');
Expand All @@ -1088,7 +1089,7 @@ public function it_throw_an_exception_on_invalid_timezone()
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_void_array_next_open()
public function it_throws_an_exception_on_limit_exceeded_void_array_next_open()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No open date/time found in the next 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1097,7 +1098,7 @@ public function it_throw_an_exception_on_limit_exceeded_void_array_next_open()
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_void_array_previous_open()
public function it_throws_an_exception_on_limit_exceeded_void_array_previous_open()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No open date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1106,7 +1107,7 @@ public function it_throw_an_exception_on_limit_exceeded_void_array_previous_open
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_full_array_next_open()
public function it_throws_an_exception_on_limit_exceeded_full_array_next_open()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No open date/time found in the next 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1123,7 +1124,7 @@ public function it_throw_an_exception_on_limit_exceeded_full_array_next_open()
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_full_array_previous_open()
public function it_throws_an_exception_on_limit_exceeded_full_array_previous_open()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No open date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1140,7 +1141,7 @@ public function it_throw_an_exception_on_limit_exceeded_full_array_previous_open
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_full_array_next_open_with_exceptions()
public function it_throws_an_exception_on_limit_exceeded_full_array_next_open_with_exceptions()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No open date/time found in the next 366 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1160,7 +1161,108 @@ public function it_throw_an_exception_on_limit_exceeded_full_array_next_open_wit
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_void_array_next_close()
public function it_throws_an_exception_on_search_limit_exceeded_with_next_open()
{
$this->expectException(SearchLimitReached::class);
$this->expectExceptionMessage('Search reached the limit: 2019-06-13 19:02:00.000000 UTC');

OpeningHours::create([])->nextOpen(
new DateTime('2019-06-06 19:02:00'),
new DateTime('2019-06-13 19:02:00'),
);
}

/** @test */
public function it_throws_an_exception_on_search_limit_exceeded_with_next_close()
{
$this->expectException(SearchLimitReached::class);
$this->expectExceptionMessage('Search reached the limit: 2019-06-13 19:02:00.000000 UTC');

OpeningHours::create([])->nextClose(
new DateTime('2019-06-06 19:02:00'),
new DateTime('2019-06-13 19:02:00'),
);
}


/** @test */
public function it_throws_an_exception_on_search_limit_exceeded_with_previous_open()
{
$this->expectException(SearchLimitReached::class);
$this->expectExceptionMessage('Search reached the limit: 2019-06-03 19:02:00.000000 UTC');

OpeningHours::create([])->previousOpen(
new DateTime('2019-06-06 19:02:00'),
new DateTime('2019-06-03 19:02:00'),
);
}

/** @test */
public function it_throws_an_exception_on_search_limit_exceeded_with_previous_close()
{
$this->expectException(SearchLimitReached::class);
$this->expectExceptionMessage('Search reached the limit: 2019-06-03 19:02:00.000000 UTC');

OpeningHours::create([])->previousClose(
new DateTime('2019-06-06 19:02:00'),
new DateTime('2019-06-03 19:02:00'),
);
}

/** @test */
public function it_stops_at_cap_limit_with_next_open()
{
$this->assertSame(
'2019-06-13 19:02:00',
OpeningHours::create([])->nextOpen(
new DateTime('2019-06-06 19:02:00'),
null,
new DateTime('2019-06-13 19:02:00'),
)->format('Y-m-d H:i:s'),
);
}

/** @test */
public function it_stops_at_cap_limit_exceeded_with_next_close()
{
$this->assertSame(
'2019-06-13 19:02:00',
OpeningHours::create([])->nextClose(
new DateTime('2019-06-06 19:02:00'),
null,
new DateTime('2019-06-13 19:02:00'),
)->format('Y-m-d H:i:s'),
);
}

/** @test */
public function it_stops_at_cap_limit_with_previous_open()
{
$this->assertSame(
'2019-06-03 19:02:00',
OpeningHours::create([])->previousOpen(
new DateTime('2019-06-06 19:02:00'),
null,
new DateTime('2019-06-03 19:02:00'),
)->format('Y-m-d H:i:s'),
);
}

/** @test */
public function it_stops_at_cap_limit_exceeded_with_previous_close()
{
$this->assertSame(
'2019-06-03 19:02:00',
OpeningHours::create([])->previousClose(
new DateTime('2019-06-06 19:02:00'),
null,
new DateTime('2019-06-03 19:02:00'),
)->format('Y-m-d H:i:s'),
);
}

/** @test */
public function it_throws_an_exception_on_limit_exceeded_void_array_next_close()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No close date/time found in the next 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1169,7 +1271,7 @@ public function it_throw_an_exception_on_limit_exceeded_void_array_next_close()
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_void_array_previous_close()
public function it_throws_an_exception_on_limit_exceeded_void_array_previous_close()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No close date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1178,7 +1280,7 @@ public function it_throw_an_exception_on_limit_exceeded_void_array_previous_clos
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_full_array_next_close()
public function it_throws_an_exception_on_limit_exceeded_full_array_next_close()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No close date/time found in the next 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand All @@ -1195,7 +1297,7 @@ public function it_throw_an_exception_on_limit_exceeded_full_array_next_close()
}

/** @test */
public function it_throw_an_exception_on_limit_exceeded_full_array_previous_close()
public function it_throws_an_exception_on_limit_exceeded_full_array_previous_close()
{
$this->expectException(MaximumLimitExceeded::class);
$this->expectExceptionMessage('No close date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.');
Expand Down

0 comments on commit 6f80acd

Please sign in to comment.