Skip to content

Commit

Permalink
fix(ZMS-3253): unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fink authored and Thomas Fink committed Jan 29, 2025
1 parent 8d863ce commit ff16fc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions zmsapi/src/Zmsapi/AvailabilityAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ protected function checkForOverlaps(Collection $collection, \DateTimeImmutable $
{
foreach ($collection as $availability1) {
foreach ($collection as $availability2) {
$scope1Id = is_array($availability1->scope) ? ($availability1->scope['id'] ?? null) : ($availability1->scope->id ?? null);
$scope2Id = is_array($availability2->scope) ? ($availability2->scope['id'] ?? null) : ($availability2->scope->id ?? null);

if ($availability1 !== $availability2 &&
$availability1->type == $availability2->type &&
$availability1->scope->id == $availability2->scope->id &&
$scope1Id == $scope2Id &&
$availability1->hasSharedWeekdayWith($availability2)) {

$start1 = (new \DateTimeImmutable())->setTimestamp($availability1->startDate)
Expand All @@ -189,7 +192,7 @@ protected function checkForOverlaps(Collection $collection, \DateTimeImmutable $
->modify($availability2->startTime);
$end2 = (new \DateTimeImmutable())->setTimestamp($availability2->endDate)
->modify($availability2->endTime);

if ($start1 < $end2 && $start2 < $end1) {
throw new AvailabilityAddFailed('Neue Öffnungszeiten überschneiden sich.');
}
Expand Down
9 changes: 6 additions & 3 deletions zmsapi/src/Zmsapi/AvailabilityUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ protected function checkForOverlaps(Collection $collection, \DateTimeImmutable $
{
foreach ($collection as $availability1) {
foreach ($collection as $availability2) {
$scope1Id = is_array($availability1->scope) ? ($availability1->scope['id'] ?? null) : ($availability1->scope->id ?? null);
$scope2Id = is_array($availability2->scope) ? ($availability2->scope['id'] ?? null) : ($availability2->scope->id ?? null);

if ($availability1 !== $availability2 &&
$availability1->type == $availability2->type &&
$availability1->scope->id == $availability2->scope->id &&
$scope1Id == $scope2Id &&
$availability1->hasSharedWeekdayWith($availability2)) {

$start1 = (new \DateTimeImmutable())->setTimestamp($availability1->startDate)
Expand All @@ -198,9 +201,9 @@ protected function checkForOverlaps(Collection $collection, \DateTimeImmutable $
->modify($availability2->startTime);
$end2 = (new \DateTimeImmutable())->setTimestamp($availability2->endDate)
->modify($availability2->endTime);

if ($start1 < $end2 && $start2 < $end1) {
throw new AvailabilityUpdateFailed('Neue Öffnungszeiten überschneiden sich.');
throw new AvailabilityAddFailed('Neue Öffnungszeiten überschneiden sich.');
}
}
}
Expand Down

0 comments on commit ff16fc0

Please sign in to comment.