updated-packages
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Cron\Tests;
|
||||
use Cron\CronExpression;
|
||||
use Cron\MonthField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -47,11 +48,12 @@ class CronExpressionTest extends TestCase
|
||||
* @covers \Cron\CronExpression::__construct
|
||||
* @covers \Cron\CronExpression::getExpression
|
||||
* @covers \Cron\CronExpression::__toString
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid CRON field value A at position 0
|
||||
*/
|
||||
public function testParsesCronScheduleThrowsAnException()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid CRON field value A at position 0');
|
||||
|
||||
CronExpression::factory('A 1 2 3 4');
|
||||
}
|
||||
|
||||
@@ -89,20 +91,22 @@ class CronExpressionTest extends TestCase
|
||||
* @covers \Cron\CronExpression::__construct
|
||||
* @covers \Cron\CronExpression::setExpression
|
||||
* @covers \Cron\CronExpression::setPart
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidCronsWillFail()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
// Only four values
|
||||
$cron = CronExpression::factory('* * * 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\CronExpression::setPart
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidPartsWillFail()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
// Only four values
|
||||
$cron = CronExpression::factory('* * * * *');
|
||||
$cron->setPart(1, 'abc');
|
||||
@@ -228,6 +232,7 @@ class CronExpressionTest extends TestCase
|
||||
$this->assertTrue($cron->isDue('now'));
|
||||
$this->assertTrue($cron->isDue(new DateTime('now')));
|
||||
$this->assertTrue($cron->isDue(date('Y-m-d H:i')));
|
||||
$this->assertTrue($cron->isDue(new DateTimeImmutable('now')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,6 +412,18 @@ class CronExpressionTest extends TestCase
|
||||
$this->assertEquals($nextRun, new DateTime("2008-11-30 00:00:00"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\CronExpression::getRunDate
|
||||
*/
|
||||
public function testGetRunDateHandlesDifferentDates()
|
||||
{
|
||||
$cron = CronExpression::factory('@weekly');
|
||||
$date = new DateTime("2019-03-10 00:00:00");
|
||||
$this->assertEquals($date, $cron->getNextRunDate("2019-03-03 08:00:00"));
|
||||
$this->assertEquals($date, $cron->getNextRunDate(new DateTime("2019-03-03 08:00:00")));
|
||||
$this->assertEquals($date, $cron->getNextRunDate(new DateTimeImmutable("2019-03-03 08:00:00")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\CronExpression::getRunDate
|
||||
*/
|
||||
@@ -557,4 +574,16 @@ class CronExpressionTest extends TestCase
|
||||
$nextRunDate = $e->getNextRunDate(new DateTime('2014-05-07 00:00:00'));
|
||||
$this->assertSame('2015-04-01 00:00:00', $nextRunDate->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* When there is an issue with a field, we should report the human readable position
|
||||
*
|
||||
* @see https://github.com/dragonmantank/cron-expression/issues/29
|
||||
*/
|
||||
public function testFieldPositionIsHumanAdjusted()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("6 is not a valid position");
|
||||
$e = CronExpression::factory('0 * * * * ? *');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Cron\Tests;
|
||||
|
||||
use Cron\DayOfMonthField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,7 @@ class DayOfMonthFieldTest extends TestCase
|
||||
{
|
||||
$f = new DayOfMonthField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTimeImmutable(), '?'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +52,17 @@ class DayOfMonthFieldTest extends TestCase
|
||||
$this->assertSame('2011-03-14 23:59:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\DayOfMonthField::increment
|
||||
*/
|
||||
public function testIncrementsDateTimeImmutable()
|
||||
{
|
||||
$d = new DateTimeImmutable('2011-03-15 11:15:00');
|
||||
$f = new DayOfMonthField();
|
||||
$f->increment($d);
|
||||
$this->assertSame('2011-03-16 00:00:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Day of the month cannot accept a 0 value, it must be between 1 and 31
|
||||
* See Github issue #120
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Cron\Tests;
|
||||
|
||||
use Cron\DayOfWeekField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,7 @@ class DayOfWeekFieldTest extends TestCase
|
||||
{
|
||||
$f = new DayOfWeekField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTimeImmutable(), '?'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,24 +52,37 @@ class DayOfWeekFieldTest extends TestCase
|
||||
$this->assertSame('2011-03-14 23:59:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\DayOfWeekField::increment
|
||||
*/
|
||||
public function testIncrementsDateTimeImmutable()
|
||||
{
|
||||
$d = new DateTimeImmutable('2011-03-15 11:15:00');
|
||||
$f = new DayOfWeekField();
|
||||
$f->increment($d);
|
||||
$this->assertSame('2011-03-16 00:00:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\DayOfWeekField::isSatisfiedBy
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Weekday must be a value between 0 and 7. 12 given
|
||||
*/
|
||||
public function testValidatesHashValueWeekday()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Weekday must be a value between 0 and 7. 12 given');
|
||||
|
||||
$f = new DayOfWeekField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '12#1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\DayOfWeekField::isSatisfiedBy
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage There are never more than 5 or less than 1 of a given weekday in a month
|
||||
*/
|
||||
public function testValidatesHashValueNth()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('There are never more than 5 or less than 1 of a given weekday in a month');
|
||||
|
||||
$f = new DayOfWeekField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '3#6'));
|
||||
}
|
||||
@@ -103,6 +118,18 @@ class DayOfWeekFieldTest extends TestCase
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime('2014-04-20 00:00:00'), '7#3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\DayOfWeekField::isSatisfiedBy
|
||||
*/
|
||||
public function testHandlesLastWeekdayOfTheMonth()
|
||||
{
|
||||
$f = new DayOfWeekField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime('2018-12-28 00:00:00'), 'FRIL'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime('2018-12-28 00:00:00'), '5L'));
|
||||
$this->assertFalse($f->isSatisfiedBy(new DateTime('2018-12-21 00:00:00'), 'FRIL'));
|
||||
$this->assertFalse($f->isSatisfiedBy(new DateTime('2018-12-21 00:00:00'), '5L'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/mtdowling/cron-expression/issues/47
|
||||
*/
|
||||
|
||||
@@ -32,10 +32,11 @@ class FieldFactoryTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \Cron\FieldFactory::getField
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testValidatesFieldPosition()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$f = new FieldFactory();
|
||||
$f->getField(-1);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Cron\Tests;
|
||||
|
||||
use Cron\HoursField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,17 @@ class HoursFieldTest extends TestCase
|
||||
$this->assertTrue($f->validate('01'));
|
||||
$this->assertTrue($f->validate('*'));
|
||||
$this->assertFalse($f->validate('*/3,1,1-12'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\HoursField::isSatisfiedBy
|
||||
*/
|
||||
public function testChecksIfSatisfied()
|
||||
{
|
||||
$f = new HoursField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTimeImmutable(), '?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\HoursField::increment
|
||||
@@ -39,6 +50,17 @@ class HoursFieldTest extends TestCase
|
||||
$this->assertSame('2011-03-15 10:59:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\HoursField::increment
|
||||
*/
|
||||
public function testIncrementsDateTimeImmutable()
|
||||
{
|
||||
$d = new DateTimeImmutable('2011-03-15 11:15:00');
|
||||
$f = new HoursField();
|
||||
$f->increment($d);
|
||||
$this->assertSame('2011-03-15 12:00:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\HoursField::increment
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Cron\Tests;
|
||||
|
||||
use Cron\MinutesField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,16 @@ class MinutesFieldTest extends TestCase
|
||||
$this->assertFalse($f->validate('*/3,1,1-12'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MinutesField::isSatisfiedBy
|
||||
*/
|
||||
public function testChecksIfSatisfied()
|
||||
{
|
||||
$f = new MinutesField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTimeImmutable(), '?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MinutesField::increment
|
||||
*/
|
||||
@@ -35,6 +46,17 @@ class MinutesFieldTest extends TestCase
|
||||
$this->assertSame('2011-03-15 11:15:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MinutesField::increment
|
||||
*/
|
||||
public function testIncrementsDateTimeImmutable()
|
||||
{
|
||||
$d = new DateTimeImmutable('2011-03-15 11:15:00');
|
||||
$f = new MinutesField();
|
||||
$f->increment($d);
|
||||
$this->assertSame('2011-03-15 11:16:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Various bad syntaxes that are reported to work, but shouldn't.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Cron\Tests;
|
||||
|
||||
use Cron\MonthField;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -23,6 +24,16 @@ class MonthFieldTest extends TestCase
|
||||
$this->assertFalse($f->validate('1.fix-regexp'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MonthField::isSatisfiedBy
|
||||
*/
|
||||
public function testChecksIfSatisfied()
|
||||
{
|
||||
$f = new MonthField();
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
|
||||
$this->assertTrue($f->isSatisfiedBy(new DateTimeImmutable(), '?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MonthField::increment
|
||||
*/
|
||||
@@ -38,6 +49,17 @@ class MonthFieldTest extends TestCase
|
||||
$this->assertSame('2011-02-28 23:59:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MonthField::increment
|
||||
*/
|
||||
public function testIncrementsDateTimeImmutable()
|
||||
{
|
||||
$d = new DateTimeImmutable('2011-03-15 11:15:00');
|
||||
$f = new MonthField();
|
||||
$f->increment($d);
|
||||
$this->assertSame('2011-04-01 00:00:00', $d->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Cron\MonthField::increment
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user