Skip to content

Commit d47e3d3

Browse files
committed
Added new unit tests
- fixed some class names - fixed psalm errors
1 parent 7b1b56f commit d47e3d3

28 files changed

+395
-12
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ echo $generator->set(new \Butschster\CronExpression\Parts\Days\LastDayOfMonth())
202202
```
203203

204204
### Manipulate days of week
205+
205206
```php
206207
// Every week on monday
207208
echo $generator->weekly(); // 0 0 * * 0
@@ -262,10 +263,10 @@ echo $generator->weeklyOn(Generator::MONDAY, 8); // 0 8 * * 1
262263
echo $generator->weeklyOn(Generator::MONDAY, 8, 6); // 6 8 * * 1
263264

264265
// Every day of a week
265-
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\EveryDaysOfWeek()); // * * * * *
266+
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\EveryDayOfWeek()); // * * * * *
266267

267268
// Every two days of a week
268-
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\EveryDaysOfWeek(2)); // * * * * */2
269+
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\EveryDayOfWeek(2)); // * * * * */2
269270

270271

271272
// Every Monday,Wednesday, Friday
@@ -275,10 +276,10 @@ echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\SpecificDay
275276
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\BetweenDayOfWeek(Generator::MONDAY, Generator::FRIDAY)); // * * * * 1-5
276277

277278
// Last monday of a week
278-
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\LastDayOwWeek()); // * * * * 1L
279+
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\LastDayOfWeek()); // * * * * 1L
279280

280281
// Last friday of a week
281-
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\LastDayOwWeek(Generator::FRIDAY)); // * * * * 5L
282+
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\LastDayOfWeek(Generator::FRIDAY)); // * * * * 5L
282283

283284
// Every first monday of every month
284285
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\NthDayOfWeek()); // * * * * 1#1

psalm.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
findUnusedVariablesAndParams="true"
5+
resolveFromConfigFile="true"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xmlns="https://getpsalm.org/schema/config"
8+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
9+
>
10+
<projectFiles>
11+
<directory name="src"/>
12+
<ignoreFiles>
13+
<directory name="vendor"/>
14+
</ignoreFiles>
15+
</projectFiles>
16+
</psalm>

src/Generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function __toString(): string
8686

8787
public function toExpression(): string
8888
{
89-
return $this->getExpression()->getExpression();
89+
return (string) $this->getExpression()->getExpression();
9090
}
9191

92-
public function setExpresion(CronExpression $expression): self
92+
public function setExpression(CronExpression $expression): self
9393
{
9494
$this->expression = $expression;
9595

src/Parts/DaysOfWeek/EveryDaysOfWeek.php renamed to src/Parts/DaysOfWeek/EveryDayOfWeek.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Butschster\CronExpression\Parts\Every;
88

9-
class EveryDaysOfWeek extends Every
9+
class EveryDayOfWeek extends Every
1010
{
1111
use DaysOfWeekIndex;
1212
}

src/Parts/DaysOfWeek/LastDayOwWeek.php renamed to src/Parts/DaysOfWeek/LastDayOfWeek.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Butschster\CronExpression\PartValueInterface;
99
use Cron\CronExpression;
1010

11-
class LastDayOwWeek implements PartValueInterface
11+
class LastDayOfWeek implements PartValueInterface
1212
{
1313
public function __construct(private int $dayOfWeek = Generator::MONDAY)
1414
{

src/Traits/Days.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public function dailyAt(int $hour, int $minute = 0): self
2626
);
2727
}
2828

29-
public function twiceDaily($first = 1, $second = 13): self
29+
public function twiceDaily(int $first = 1, int $second = 13): self
3030
{
3131
return $this->daily($first, $second);
3232
}
3333

34-
public function twiceDailyAt($first = 1, $second = 13, $minute = 0): self
34+
public function twiceDailyAt(int $first = 1, int $second = 13, int $minute = 0): self
3535
{
3636
return $this->daily($first, $second)->set(new SpecificMinutes($minute));
3737
}

src/Traits/Months.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Butschster\CronExpression\Traits;
66

77
use Butschster\CronExpression\Parts\Days\SpecificDays;
8-
use Butschster\CronExpression\Parts\DaysOfWeek\LastDayOwWeek;
8+
use Butschster\CronExpression\Parts\DaysOfWeek\LastDayOfWeek;
99
use Butschster\CronExpression\Parts\DaysOfWeek\NthDayOfWeek;
1010

1111
trait Months
@@ -36,7 +36,7 @@ public function twiceMonthly(int $first = 1, int $second = 16, int $hour = 0, in
3636

3737
public function lastDayOfWeekEveryMonth(int $dayOfWeek = self::MONDAY, int $hour = 0, int $minute = 0): self
3838
{
39-
return $this->dailyAt($hour, $minute)->set(new LastDayOwWeek($dayOfWeek));
39+
return $this->dailyAt($hour, $minute)->set(new LastDayOfWeek($dayOfWeek));
4040
}
4141

4242
public function nthDayOfWeekEveryMonth(int $dayOfWeek = self::MONDAY, int $nth = 1, int $hour = 0, int $minute = 0): self
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\CronExpression\Tests\Parts\Days;
6+
7+
use Butschster\CronExpression\Parts\Days\BetweenDays;
8+
use Butschster\CronExpression\Tests\TestCase;
9+
10+
class BetweenDaysTest extends TestCase
11+
{
12+
public function testUpdatesExpression()
13+
{
14+
$this->assertExpressionPart('* * 6-12 * *', new BetweenDays(6, 12));
15+
}
16+
}

tests/Parts/Days/EveryDayTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\CronExpression\Tests\Parts\Days;
6+
7+
use Butschster\CronExpression\Parts\Days\EveryDay;
8+
use Butschster\CronExpression\Tests\TestCase;
9+
10+
class EveryDayTest extends TestCase
11+
{
12+
public function testUpdatesExpression()
13+
{
14+
$this->assertExpressionPart('* * */3 * *', new EveryDay(3));
15+
}
16+
17+
public function testUpdatesExpressionWithoutArgs()
18+
{
19+
$this->assertExpressionPart('* * * * *', new EveryDay());
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\CronExpression\Tests\Parts\Days;
6+
7+
use Butschster\CronExpression\Parts\Days\LastDayOfMonth;
8+
use Butschster\CronExpression\Tests\TestCase;
9+
10+
class LastDayOfMonthTest extends TestCase
11+
{
12+
public function testUpdatesExpression()
13+
{
14+
$this->assertExpressionPart('* * L * *', new LastDayOfMonth());
15+
}
16+
}

0 commit comments

Comments
 (0)