Skip to content

Commit

Permalink
Added new unit tests
Browse files Browse the repository at this point in the history
- fixed some class names
- fixed psalm errors
  • Loading branch information
butschster committed Aug 9, 2021
1 parent 7b1b56f commit d47e3d3
Show file tree
Hide file tree
Showing 28 changed files with 395 additions and 12 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ echo $generator->set(new \Butschster\CronExpression\Parts\Days\LastDayOfMonth())
```

### Manipulate days of week

```php
// Every week on monday
echo $generator->weekly(); // 0 0 * * 0
Expand Down Expand Up @@ -262,10 +263,10 @@ echo $generator->weeklyOn(Generator::MONDAY, 8); // 0 8 * * 1
echo $generator->weeklyOn(Generator::MONDAY, 8, 6); // 6 8 * * 1

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

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


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

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

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

// Every first monday of every month
echo $generator->set(new \Butschster\CronExpression\Parts\DaysOfWeek\NthDayOfWeek()); // * * * * 1#1
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function __toString(): string

public function toExpression(): string
{
return $this->getExpression()->getExpression();
return (string) $this->getExpression()->getExpression();
}

public function setExpresion(CronExpression $expression): self
public function setExpression(CronExpression $expression): self
{
$this->expression = $expression;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Butschster\CronExpression\Parts\Every;

class EveryDaysOfWeek extends Every
class EveryDayOfWeek extends Every
{
use DaysOfWeekIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Butschster\CronExpression\PartValueInterface;
use Cron\CronExpression;

class LastDayOwWeek implements PartValueInterface
class LastDayOfWeek implements PartValueInterface
{
public function __construct(private int $dayOfWeek = Generator::MONDAY)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Days.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function dailyAt(int $hour, int $minute = 0): self
);
}

public function twiceDaily($first = 1, $second = 13): self
public function twiceDaily(int $first = 1, int $second = 13): self
{
return $this->daily($first, $second);
}

public function twiceDailyAt($first = 1, $second = 13, $minute = 0): self
public function twiceDailyAt(int $first = 1, int $second = 13, int $minute = 0): self
{
return $this->daily($first, $second)->set(new SpecificMinutes($minute));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Months.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Butschster\CronExpression\Traits;

use Butschster\CronExpression\Parts\Days\SpecificDays;
use Butschster\CronExpression\Parts\DaysOfWeek\LastDayOwWeek;
use Butschster\CronExpression\Parts\DaysOfWeek\LastDayOfWeek;
use Butschster\CronExpression\Parts\DaysOfWeek\NthDayOfWeek;

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

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

public function nthDayOfWeekEveryMonth(int $dayOfWeek = self::MONDAY, int $nth = 1, int $hour = 0, int $minute = 0): self
Expand Down
16 changes: 16 additions & 0 deletions tests/Parts/Days/BetweenDaysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Days;

use Butschster\CronExpression\Parts\Days\BetweenDays;
use Butschster\CronExpression\Tests\TestCase;

class BetweenDaysTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * 6-12 * *', new BetweenDays(6, 12));
}
}
21 changes: 21 additions & 0 deletions tests/Parts/Days/EveryDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Days;

use Butschster\CronExpression\Parts\Days\EveryDay;
use Butschster\CronExpression\Tests\TestCase;

class EveryDayTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * */3 * *', new EveryDay(3));
}

public function testUpdatesExpressionWithoutArgs()
{
$this->assertExpressionPart('* * * * *', new EveryDay());
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Days/LastDayOfMonthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Days;

use Butschster\CronExpression\Parts\Days\LastDayOfMonth;
use Butschster\CronExpression\Tests\TestCase;

class LastDayOfMonthTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * L * *', new LastDayOfMonth());
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Days/LastWeekdayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Days;

use Butschster\CronExpression\Parts\Days\LastWeekday;
use Butschster\CronExpression\Tests\TestCase;

class LastWeekdayTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * LW * *', new LastWeekday());
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Days/SpecificDaysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Days;

use Butschster\CronExpression\Parts\Days\SpecificDays;
use Butschster\CronExpression\Tests\TestCase;

class SpecificDaysTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * 2,4,6,8,10,12 * *', new SpecificDays(2, 4, 6, 8, 10, 12));
}
}
17 changes: 17 additions & 0 deletions tests/Parts/DaysOfWeek/BetweenDayOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\DaysOfWeek;

use Butschster\CronExpression\Generator;
use Butschster\CronExpression\Parts\DaysOfWeek\BetweenDayOfWeek;
use Butschster\CronExpression\Tests\TestCase;

class BetweenDayOfWeekTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * * * 1-6', new BetweenDayOfWeek(Generator::MONDAY, Generator::SATURDAY));
}
}
21 changes: 21 additions & 0 deletions tests/Parts/DaysOfWeek/EveryDayOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\DaysOfWeek;

use Butschster\CronExpression\Parts\DaysOfWeek\EveryDayOfWeek;
use Butschster\CronExpression\Tests\TestCase;

class EveryDayOfWeekTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * * * */3', new EveryDayOfWeek(3));
}

public function testUpdatesExpressionWithoutArgs()
{
$this->assertExpressionPart('* * * * *', new EveryDayOfWeek());
}
}
19 changes: 19 additions & 0 deletions tests/Parts/DaysOfWeek/LastDayOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\DaysOfWeek;

use Butschster\CronExpression\Generator;
use Butschster\CronExpression\Parts\DaysOfWeek\LastDayOfWeek;
use Butschster\CronExpression\Tests\TestCase;

class LastDayOfWeekTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * * * 1L', new LastDayOfWeek());

$this->assertExpressionPart('* * * * 5L', new LastDayOfWeek(Generator::FRIDAY));
}
}
19 changes: 19 additions & 0 deletions tests/Parts/DaysOfWeek/NthDayOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\DaysOfWeek;

use Butschster\CronExpression\Generator;
use Butschster\CronExpression\Parts\DaysOfWeek\NthDayOfWeek;
use Butschster\CronExpression\Tests\TestCase;

class NthDayOfWeekTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * * * 1#1', new NthDayOfWeek());

$this->assertExpressionPart('* * * * 5#3', new NthDayOfWeek(Generator::FRIDAY, 3));
}
}
16 changes: 16 additions & 0 deletions tests/Parts/DaysOfWeek/SpecificDaysOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\DaysOfWeek;

use Butschster\CronExpression\Parts\DaysOfWeek\SpecificDaysOfWeek;
use Butschster\CronExpression\Tests\TestCase;

class SpecificDaysOfWeekTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* * * * 2,4,6', new SpecificDaysOfWeek(2, 4, 6));
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Hours/BetweenHoursTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Hours;

use Butschster\CronExpression\Parts\Hours\BetweenHours;
use Butschster\CronExpression\Tests\TestCase;

class BetweenHoursTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* 6-12 * * *', new BetweenHours(6, 12));
}
}
21 changes: 21 additions & 0 deletions tests/Parts/Hours/EveryHourTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Hours;

use Butschster\CronExpression\Parts\Hours\EveryHour;
use Butschster\CronExpression\Tests\TestCase;

class EveryHourTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* */3 * * *', new EveryHour(3));
}

public function testUpdatesExpressionWithoutArgs()
{
$this->assertExpressionPart('* * * * *', new EveryHour());
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Hours/SpecificHoursTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Hours;

use Butschster\CronExpression\Parts\Hours\SpecificHours;
use Butschster\CronExpression\Tests\TestCase;

class SpecificHoursTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('* 2,4,6,8,10,12 * * *', new SpecificHours(2, 4, 6, 8, 10, 12));
}
}
16 changes: 16 additions & 0 deletions tests/Parts/Minutes/BetweenMinutesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Minutes;

use Butschster\CronExpression\Parts\Minutes\BetweenMinutes;
use Butschster\CronExpression\Tests\TestCase;

class BetweenMinutesTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('6-12 * * * *', new BetweenMinutes(6, 12));
}
}
21 changes: 21 additions & 0 deletions tests/Parts/Minutes/EveryMinuteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Butschster\CronExpression\Tests\Parts\Minutes;

use Butschster\CronExpression\Parts\Minutes\EveryMinute;
use Butschster\CronExpression\Tests\TestCase;

class EveryMinuteTest extends TestCase
{
public function testUpdatesExpression()
{
$this->assertExpressionPart('*/3 * * * *', new EveryMinute(3));
}

public function testUpdatesExpressionWithoutArgs()
{
$this->assertExpressionPart('* * * * *', new EveryMinute());
}
}
Loading

0 comments on commit d47e3d3

Please sign in to comment.