Skip to content

Commit

Permalink
Merge branch '1.x' into 1.next
Browse files Browse the repository at this point in the history
# Conflicts:
#	.phive/phars.xml
  • Loading branch information
LordSimal committed Nov 17, 2024
2 parents 767d369 + f377808 commit 28754c7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.12.3" installed="1.12.3" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
</phive>
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ parameters:
paths:
- src
- tests/TestCase
level: 5
level: 8
bootstrapFiles:
- tests/bootstrap.php
ignoreErrors:
-
identifier: missingType.iterableValue
6 changes: 5 additions & 1 deletion src/Scheduler/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function execute(string|callable $command, array $args = []): Event
}

try {
$commandObj = $this->container->get($command);
if ($this->container !== null) {
$commandObj = $this->container->get($command);
} elseif (class_exists($command)) {
$commandObj = new $command();
}
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $ex) {
if (class_exists($command)) {
$commandObj = new $command();
Expand Down
2 changes: 1 addition & 1 deletion src/Scheduler/Traits/FrequenciesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function days(int|string|array $days): self
*/
protected function spliceIntoPosition(int $position, mixed $value): self
{
$segments = preg_split("/\s+/", $this->expression);
$segments = preg_split("/\s+/", $this->expression) ?: [];

$segments[$position - 1] = $value;

Expand Down
66 changes: 33 additions & 33 deletions tests/TestCase/Scheduler/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,179 +26,179 @@ public function testIsDue(): void
Chronos::setTestNow('now');
}

public function testEveryMinute()
public function testEveryMinute(): void
{
$this->assertSame('* * * * *', $this->event->getExpression());
$this->assertSame('* * * * *', $this->event->everyMinute()->getExpression());
}

public function testEveryXMinutes()
public function testEveryXMinutes(): void
{
$this->assertSame('*/2 * * * *', $this->event->everyXMinutes(2)->getExpression());
$this->expectException(InvalidArgumentException::class);
$this->assertSame('*/2 * * * *', $this->event->everyXMinutes(-10)->getExpression());
}

public function testDaily()
public function testDaily(): void
{
$this->assertSame('0 0 * * *', $this->event->daily()->getExpression());
}

public function testDailyAt()
public function testDailyAt(): void
{
$this->assertSame('8 13 * * *', $this->event->dailyAt('13:08')->getExpression());
}

public function testTwiceDailyAt()
public function testTwiceDailyAt(): void
{
$this->assertSame('0 3,15 * * *', $this->event->twiceDailyAt(3, 15)->getExpression());
$this->assertSame('5 3,15 * * *', $this->event->twiceDailyAt(3, 15, 5)->getExpression());
}

public function testWeekly()
public function testWeekly(): void
{
$this->assertSame('0 0 * * 0', $this->event->weekly()->getExpression());
}

public function testWeeklyOn()
public function testWeeklyOn(): void
{
$this->assertSame('0 8 * * 1', $this->event->weeklyOn(Event::MONDAY, '8:00')->getExpression());
}

public function testOverrideWithHourly()
public function testOverrideWithHourly(): void
{
$this->assertSame('0 * * * *', $this->event->everyXMinutes(5)->hourly()->getExpression());
$this->assertSame('37 * * * *', $this->event->hourlyAt(37)->getExpression());
$this->assertSame('15,30,45 * * * *', $this->event->hourlyAt([15, 30, 45])->getExpression());
}

public function testHourly()
public function testHourly(): void
{
$this->assertSame('0 1-23/2 * * *', $this->event->everyOddHour()->getExpression());
$this->assertSame('0 */2 * * *', $this->event->everyXHours(2)->getExpression());
$this->expectException(InvalidArgumentException::class);
$this->assertSame('*/2 * * * *', $this->event->everyXHours(-10)->getExpression());
}

public function testMonthly()
public function testMonthly(): void
{
$this->assertSame('0 0 1 * *', $this->event->monthly()->getExpression());
}

public function testMonthlyOn()
public function testMonthlyOn(): void
{
$this->assertSame('0 15 4 * *', $this->event->monthlyOn(4, '15:00')->getExpression());
}

public function testLastDayOfMonth()
public function testLastDayOfMonth(): void
{
Chronos::setTestNow('2020-10-10 10:10:10');
$this->assertSame('0 0 31 * *', $this->event->lastDayOfMonth()->getExpression());
Chronos::setTestNow('now');
}

public function testTwiceMonthly()
public function testTwiceMonthly(): void
{
$this->assertSame('0 0 1,16 * *', $this->event->twiceMonthly(1, 16)->getExpression());
}

public function testTwiceMonthlyAtTime()
public function testTwiceMonthlyAtTime(): void
{
$this->assertSame('30 1 1,16 * *', $this->event->twiceMonthly(1, 16, '1:30')->getExpression());
}

public function testMonthlyOnWithMinutes()
public function testMonthlyOnWithMinutes(): void
{
$this->assertSame('15 15 4 * *', $this->event->monthlyOn(4, '15:15')->getExpression());
}

public function testWeekdaysDaily()
public function testWeekdaysDaily(): void
{
$this->assertSame('0 0 * * 1-5', $this->event->weekdays()->daily()->getExpression());
}

public function testWeekdaysHourly()
public function testWeekdaysHourly(): void
{
$this->assertSame('0 * * * 1-5', $this->event->weekdays()->hourly()->getExpression());
}

public function testWeekdays()
public function testWeekdays(): void
{
$this->assertSame('* * * * 1-5', $this->event->weekdays()->getExpression());
}

public function testWeekends()
public function testWeekends(): void
{
$this->assertSame('* * * * 6,0', $this->event->weekends()->getExpression());
}

public function testSundays()
public function testSundays(): void
{
$this->assertSame('* * * * 0', $this->event->sundays()->getExpression());
}

public function testMondays()
public function testMondays(): void
{
$this->assertSame('* * * * 1', $this->event->mondays()->getExpression());
}

public function testTuesdays()
public function testTuesdays(): void
{
$this->assertSame('* * * * 2', $this->event->tuesdays()->getExpression());
}

public function testWednesdays()
public function testWednesdays(): void
{
$this->assertSame('* * * * 3', $this->event->wednesdays()->getExpression());
}

public function testThursdays()
public function testThursdays(): void
{
$this->assertSame('* * * * 4', $this->event->thursdays()->getExpression());
}

public function testFridays()
public function testFridays(): void
{
$this->assertSame('* * * * 5', $this->event->fridays()->getExpression());
}

public function testSaturdays()
public function testSaturdays(): void
{
$this->assertSame('* * * * 6', $this->event->saturdays()->getExpression());
}

public function testDays()
public function testDays(): void
{
$this->assertSame('* * * * 1', $this->event->days(Event::MONDAY)->getExpression());
$this->assertSame('* * * * 1,4', $this->event->days([Event::MONDAY, Event::THURSDAY])->getExpression());
}

public function testQuarterly()
public function testQuarterly(): void
{
$this->assertSame('0 0 1 1-12/3 *', $this->event->quarterly()->getExpression());
}

public function testQuarterlyOn()
public function testQuarterlyOn(): void
{
$this->assertSame('0 0 2 1-12/3 *', $this->event->quarterlyOn(2)->getExpression());
}

public function testYearly()
public function testYearly(): void
{
$this->assertSame('0 0 1 1 *', $this->event->yearly()->getExpression());
}

public function testYearlyOn()
public function testYearlyOn(): void
{
$this->assertSame('8 15 5 4 *', $this->event->yearlyOn(4, '5', '15:08')->getExpression());
}

public function testYearlyOnMondaysOnly()
public function testYearlyOnMondaysOnly(): void
{
$this->assertSame('1 9 * 7 1', $this->event->mondays()->yearlyOn(7, '*', '09:01')->getExpression());
}

public function testYearlyOnTuesdaysAndDayOfMonth20()
public function testYearlyOnTuesdaysAndDayOfMonth20(): void
{
$this->assertSame('1 9 20 7 2', $this->event->tuesdays()->yearlyOn(7, '20', '09:01')->getExpression());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Scheduler/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testAddDueEvents(): void
{
$this->scheduler->execute(VersionCommand::class);
$events = $this->scheduler->dueEvents();
$this->assertNotEmpty($events);
$this->assertFalse($events->isEmpty());
}

public function testAddMultipleDueEvents(): void
Expand Down

0 comments on commit 28754c7

Please sign in to comment.