Skip to content

Commit

Permalink
fix: support for php82
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryk committed Jul 2, 2024
1 parent a7553a4 commit 6cab9f5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test": "./vendor/bin/testbench package:test --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
Expand Down
12 changes: 6 additions & 6 deletions src/Constraints/AfterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool
}

return $schedule->isOnce()
? $schedule->timestamp_target->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: $schedule->timestamp_target->diffInDays(now()->floorSeconds()) > $schedule->toDays();
? (int) $schedule->timestamp_target->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: (int) $schedule->timestamp_target->diffInDays(now()->floorSeconds()) > $schedule->toDays();
}

if ($schedule->toHours() > 0) {
Expand All @@ -34,8 +34,8 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours()
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->toHours();
? (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours()
: (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->toHours();
}

if (now()->floorSeconds()->lte($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) {
Expand All @@ -44,7 +44,7 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->delay_minutes
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->delay_minutes;
? (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->delay_minutes
: (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->delay_minutes;
}
}
12 changes: 6 additions & 6 deletions src/Constraints/BeforeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) < $schedule->toDays();
? (int) $schedule->timestampTarget()->diffInDays(now()->floorSeconds(), absolute: true) === $schedule->toDays()
: (int) $schedule->timestampTarget()->diffInDays(now()->floorSeconds(), absolute: true) < $schedule->toDays();
}

if ($schedule->toHours() > 0) {
Expand All @@ -40,15 +40,15 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool

//till ends we should have at least toHours days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours()
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) < $schedule->toHours();
? (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds(), absolute: true) === $schedule->toHours()
: (int) $schedule->timestamp_target->diffInHours(now()->floorSeconds(), absolute: true) < $schedule->toHours();
}



//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) < $schedule->toDays();
? (int) $schedule->timestampTarget()->diffInDays(now()->floorSeconds(), absolute: true) === $schedule->toDays()
: (int) $schedule->timestampTarget()->diffInDays(now()->floorSeconds(), absolute: true) < $schedule->toDays();
}
}
13 changes: 13 additions & 0 deletions tests/Feature/WithWeekendsConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

class WithWeekendsConstraintTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
TestTime::freeze(); // Freeze time at the beginning of each test
}

protected function tearDown(): void
{
TestTime::unfreeze(); // Unfreeze time after each test

parent::tearDown();
}

public function test_can_send_mail_with_precision_at_the_given_hour(): void
{
Mail::fake();
Expand Down

0 comments on commit 6cab9f5

Please sign in to comment.