Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1,17 +1,26 @@
# Change Log
## [Unreleased]
## [1.2.0] - 2017-01-22
### Added
### Changed
### Fixed
- Added IDE, CodeSniffer, and StyleCI.IO support
## [1.1.0] - 2015-01-26
### Changed
- Switched to PSR-4 Autoloading
### Fixed
- 0 step expressions are handled better
- Fixed `DayOfMonth` validation to be more strict
- Typos
## [1.1.0] - 2016-01-26
### Added
- Support for non-hourly offset timezones
- Checks for valid expressions
### Changed
- Max Iterations no longer hardcoded for `getRunDate()`
- Supports DateTimeImmutable for newer PHP verions
### Fixed
- Fixed looping bug for PHP 7 when determining the last specified weekday of a month
@@ -24,4 +33,4 @@
### Fixed
- Fixes issue [#28](https://github.com/mtdowling/cron-expression/issues/28) where PHP increments of ranges were failing due to PHP casting hyphens to 0
- Only set default timezone if the given $currentTime is not a DateTime instance ([#34](https://github.com/mtdowling/cron-expression/issues/34))
- Only set default timezone if the given $currentTime is not a DateTime instance ([#34](https://github.com/mtdowling/cron-expression/issues/34))

View File

@@ -16,8 +16,13 @@
"phpunit/phpunit": "~4.0|~5.0"
},
"autoload": {
"psr-0": {
"Cron": "src/"
"psr-4": {
"Cron\\": "src/Cron/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/Cron/"
}
}
}

View File

@@ -76,8 +76,13 @@ abstract class AbstractField implements FieldInterface
public function isInIncrementsOfRanges($dateValue, $value)
{
$parts = array_map('trim', explode('/', $value, 2));
$stepSize = isset($parts[1]) ? $parts[1] : 0;
if (($parts[0] == '*' || $parts[0] === '0') && 0 !== $stepSize) {
$stepSize = isset($parts[1]) ? (int) $parts[1] : 0;
if ($stepSize === 0) {
return false;
}
if (($parts[0] == '*' || $parts[0] === '0')) {
return (int) $dateValue % $stepSize == 0;
}

View File

@@ -2,6 +2,13 @@
namespace Cron;
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use Exception;
use InvalidArgumentException;
use RuntimeException;
/**
* CRON expression parser that can determine whether or not a CRON expression is
* due to run, the next run date and previous run date of a CRON expression.
@@ -83,13 +90,13 @@ class CronExpression
* @param string $expression The CRON expression to validate.
*
* @return bool True if a valid CRON expression was passed. False if not.
* @see Cron\CronExpression::factory
* @see \Cron\CronExpression::factory
*/
public static function isValidExpression($expression)
{
try {
self::factory($expression);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
return false;
}
@@ -120,7 +127,7 @@ class CronExpression
{
$this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY);
if (count($this->cronParts) < 5) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
$value . ' is not a valid CRON expression'
);
}
@@ -144,7 +151,7 @@ class CronExpression
public function setPart($position, $value)
{
if (!$this->fieldFactory->getField($position)->validate($value)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'Invalid CRON field value ' . $value . ' at position ' . $position
);
}
@@ -199,7 +206,7 @@ class CronExpression
*
* @return \DateTime
* @throws \RuntimeException on too many iterations
* @see Cron\CronExpression::getNextRunDate
* @see \Cron\CronExpression::getNextRunDate
*/
public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
{
@@ -223,7 +230,7 @@ class CronExpression
for ($i = 0; $i < max(0, $total); $i++) {
try {
$matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate);
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
break;
}
}
@@ -275,19 +282,19 @@ class CronExpression
if ('now' === $currentTime) {
$currentDate = date('Y-m-d H:i');
$currentTime = strtotime($currentDate);
} elseif ($currentTime instanceof \DateTime) {
} elseif ($currentTime instanceof DateTime) {
$currentDate = clone $currentTime;
// Ensure time in 'current' timezone is used
$currentDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$currentDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
$currentDate = $currentDate->format('Y-m-d H:i');
$currentTime = strtotime($currentDate);
} elseif ($currentTime instanceof \DateTimeImmutable) {
$currentDate = \DateTime::createFromFormat('U', $currentTime->format('U'));
$currentDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
} elseif ($currentTime instanceof DateTimeImmutable) {
$currentDate = DateTime::createFromFormat('U', $currentTime->format('U'));
$currentDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
$currentDate = $currentDate->format('Y-m-d H:i');
$currentTime = strtotime($currentDate);
} else {
$currentTime = new \DateTime($currentTime);
$currentTime = new DateTime($currentTime);
$currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0);
$currentDate = $currentTime->format('Y-m-d H:i');
$currentTime = $currentTime->getTimeStamp();
@@ -295,7 +302,7 @@ class CronExpression
try {
return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime;
} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}
}
@@ -314,14 +321,14 @@ class CronExpression
*/
protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false)
{
if ($currentTime instanceof \DateTime) {
if ($currentTime instanceof DateTime) {
$currentDate = clone $currentTime;
} elseif ($currentTime instanceof \DateTimeImmutable) {
$currentDate = \DateTime::createFromFormat('U', $currentTime->format('U'));
} elseif ($currentTime instanceof DateTimeImmutable) {
$currentDate = DateTime::createFromFormat('U', $currentTime->format('U'));
$currentDate->setTimezone($currentTime->getTimezone());
} else {
$currentDate = new \DateTime($currentTime ?: 'now');
$currentDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$currentDate = new DateTime($currentTime ?: 'now');
$currentDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
}
$currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0);
@@ -376,7 +383,7 @@ class CronExpression
}
// @codeCoverageIgnoreStart
throw new \RuntimeException('Impossible CRON expression');
throw new RuntimeException('Impossible CRON expression');
// @codeCoverageIgnoreEnd
}
}

View File

@@ -2,6 +2,8 @@
namespace Cron;
use DateTime;
/**
* Day of month field. Allows: * , / - ? L W
*
@@ -34,7 +36,7 @@ class DayOfMonthField extends AbstractField
private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
{
$tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
$target = \DateTime::createFromFormat('Y-m-d', "$currentYear-$currentMonth-$tday");
$target = DateTime::createFromFormat('Y-m-d', "$currentYear-$currentMonth-$tday");
$currentWeekday = (int) $target->format('N');
if ($currentWeekday < 6) {
@@ -54,7 +56,7 @@ class DayOfMonthField extends AbstractField
}
}
public function isSatisfiedBy(\DateTime $date, $value)
public function isSatisfiedBy(DateTime $date, $value)
{
// ? states that the field value is to be skipped
if ($value == '?') {
@@ -83,7 +85,7 @@ class DayOfMonthField extends AbstractField
return $this->isSatisfied($date->format('d'), $value);
}
public function increment(\DateTime $date, $invert = false)
public function increment(DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('previous day');
@@ -96,8 +98,76 @@ class DayOfMonthField extends AbstractField
return $this;
}
/**
* Validates that the value is valid for the Day of the Month field
* Days of the month can contain values of 1-31, *, L, or ? by default. This can be augmented with lists via a ',',
* ranges via a '-', or with a '[0-9]W' to specify the closest weekday.
*
* @param string $value
* @return bool
*/
public function validate($value)
{
return (bool) preg_match('/^[\*,\/\-\?LW0-9A-Za-z]+$/', $value);
// Allow wildcards and a single L
if ($value === '?' || $value === '*' || $value === 'L') {
return true;
}
// If you only contain numbers and are within 1-31
if ((bool) preg_match('/^\d{1,2}$/', $value) && ($value >= 1 && $value <= 31)) {
return true;
}
// If you have a -, we will deal with each of your chunks
if ((bool) preg_match('/-/', $value)) {
// We cannot have a range within a list or vice versa
if ((bool) preg_match('/,/', $value)) {
return false;
}
$chunks = explode('-', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you have a comma, we will deal with each value
if ((bool) preg_match('/,/', $value)) {
// We cannot have a range within a list or vice versa
if ((bool) preg_match('/-/', $value)) {
return false;
}
$chunks = explode(',', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you contain a /, we'll deal with it
if ((bool) preg_match('/\//', $value)) {
$chunks = explode('/', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you end in W, make sure that it has a numeric in front of it
if ((bool) preg_match('/^\d{1,2}W$/', $value)) {
return true;
}
return false;
}
}

View File

@@ -2,6 +2,10 @@
namespace Cron;
use DateTime;
use InvalidArgumentException;
/**
* Day of week field. Allows: * / , - ? L #
*
@@ -17,7 +21,7 @@ namespace Cron;
*/
class DayOfWeekField extends AbstractField
{
public function isSatisfiedBy(\DateTime $date, $value)
public function isSatisfiedBy(DateTime $date, $value)
{
if ($value == '?') {
return true;
@@ -36,7 +40,7 @@ class DayOfWeekField extends AbstractField
$tdate = clone $date;
$tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
while ($tdate->format('w') != $weekday) {
$tdateClone = new \DateTime();
$tdateClone = new DateTime();
$tdate = $tdateClone
->setTimezone($tdate->getTimezone())
->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
@@ -56,10 +60,10 @@ class DayOfWeekField extends AbstractField
// Validate the hash fields
if ($weekday < 0 || $weekday > 7) {
throw new \InvalidArgumentException("Weekday must be a value between 0 and 7. {$weekday} given");
throw new InvalidArgumentException("Weekday must be a value between 0 and 7. {$weekday} given");
}
if ($nth > 5) {
throw new \InvalidArgumentException('There are never more than 5 of a given weekday in a month');
throw new InvalidArgumentException('There are never more than 5 of a given weekday in a month');
}
// The current weekday must match the targeted weekday to proceed
if ($date->format('N') != $weekday) {
@@ -100,7 +104,7 @@ class DayOfWeekField extends AbstractField
return $this->isSatisfied($fieldValue, $value);
}
public function increment(\DateTime $date, $invert = false)
public function increment(DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('-1 day');

View File

@@ -2,6 +2,8 @@
namespace Cron;
use InvalidArgumentException;
/**
* CRON field factory implementing a flyweight factory
* @link http://en.wikipedia.org/wiki/Cron
@@ -44,7 +46,7 @@ class FieldFactory
$this->fields[$position] = new YearField();
break;
default:
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
$position . ' is not a valid position'
);
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Cron;
use DateTime;
/**
* CRON field interface
@@ -15,7 +16,7 @@ interface FieldInterface
*
* @return bool Returns TRUE if satisfied, FALSE otherwise
*/
public function isSatisfiedBy(\DateTime $date, $value);
public function isSatisfiedBy(DateTime $date, $value);
/**
* When a CRON expression is not satisfied, this method is used to increment
@@ -26,7 +27,7 @@ interface FieldInterface
*
* @return FieldInterface
*/
public function increment(\DateTime $date, $invert = false);
public function increment(DateTime $date, $invert = false);
/**
* Validates a CRON expression for a given field

View File

@@ -1,25 +1,28 @@
<?php
namespace Cron;
use DateTime;
use DateTimeZone;
/**
* Hours field. Allows: * , / -
*/
class HoursField extends AbstractField
{
public function isSatisfiedBy(\DateTime $date, $value)
public function isSatisfiedBy(DateTime $date, $value)
{
return $this->isSatisfied($date->format('H'), $value);
}
public function increment(\DateTime $date, $invert = false, $parts = null)
public function increment(DateTime $date, $invert = false, $parts = null)
{
// Change timezone to UTC temporarily. This will
// allow us to go back or forwards and hour even
// if DST will be changed between the hours.
if (is_null($parts) || $parts == '*') {
$timezone = $date->getTimezone();
$date->setTimezone(new \DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('UTC'));
if ($invert) {
$date->modify('-1 hour');
} else {

View File

@@ -2,17 +2,20 @@
namespace Cron;
use DateTime;
/**
* Minutes field. Allows: * , / -
*/
class MinutesField extends AbstractField
{
public function isSatisfiedBy(\DateTime $date, $value)
public function isSatisfiedBy(DateTime $date, $value)
{
return $this->isSatisfied($date->format('i'), $value);
}
public function increment(\DateTime $date, $invert = false, $parts = null)
public function increment(DateTime $date, $invert = false, $parts = null)
{
if (is_null($parts)) {
if ($invert) {

View File

@@ -2,17 +2,20 @@
namespace Cron;
use DateTime;
/**
* Year field. Allows: * , / -
*/
class YearField extends AbstractField
{
public function isSatisfiedBy(\DateTime $date, $value)
public function isSatisfiedBy(DateTime $date, $value)
{
return $this->isSatisfied($date->format('Y'), $value);
}
public function increment(\DateTime $date, $invert = false)
public function increment(DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('-1 year');

View File

@@ -3,11 +3,12 @@
namespace Cron\Tests;
use Cron\DayOfWeekField;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class AbstractFieldTest extends \PHPUnit_Framework_TestCase
class AbstractFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\AbstractField::isRange
@@ -26,7 +27,6 @@ class AbstractFieldTest extends \PHPUnit_Framework_TestCase
{
$f = new DayOfWeekField();
$this->assertFalse($f->isIncrementsOfRanges('1-2'));
$this->assertFalse($f->isIncrementsOfRanges('1-2'));
$this->assertTrue($f->isIncrementsOfRanges('1/2'));
$this->assertTrue($f->isIncrementsOfRanges('*/2'));
$this->assertTrue($f->isIncrementsOfRanges('3-12/2'));
@@ -38,11 +38,11 @@ class AbstractFieldTest extends \PHPUnit_Framework_TestCase
public function testTestsIfInRange()
{
$f = new DayOfWeekField();
$this->assertTrue($f->isInRange(1, '1-2'));
$this->assertTrue($f->isInRange(2, '1-2'));
$this->assertTrue($f->isInRange(5, '4-12'));
$this->assertFalse($f->isInRange(3, '4-12'));
$this->assertFalse($f->isInRange(13, '4-12'));
$this->assertTrue($f->isInRange('1', '1-2'));
$this->assertTrue($f->isInRange('2', '1-2'));
$this->assertTrue($f->isInRange('5', '4-12'));
$this->assertFalse($f->isInRange('3', '4-12'));
$this->assertFalse($f->isInRange('13', '4-12'));
}
/**
@@ -51,20 +51,22 @@ class AbstractFieldTest extends \PHPUnit_Framework_TestCase
public function testTestsIfInIncrementsOfRanges()
{
$f = new DayOfWeekField();
$this->assertTrue($f->isInIncrementsOfRanges(3, '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges(13, '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges(15, '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges(14, '*/2'));
$this->assertFalse($f->isInIncrementsOfRanges(2, '3-59/13'));
$this->assertFalse($f->isInIncrementsOfRanges(14, '*/13'));
$this->assertFalse($f->isInIncrementsOfRanges(14, '3-59/2'));
$this->assertFalse($f->isInIncrementsOfRanges(3, '2-59'));
$this->assertFalse($f->isInIncrementsOfRanges(3, '2'));
$this->assertFalse($f->isInIncrementsOfRanges(3, '*'));
$this->assertTrue($f->isInIncrementsOfRanges('3', '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges('13', '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges('15', '3-59/2'));
$this->assertTrue($f->isInIncrementsOfRanges('14', '*/2'));
$this->assertFalse($f->isInIncrementsOfRanges('2', '3-59/13'));
$this->assertFalse($f->isInIncrementsOfRanges('14', '*/13'));
$this->assertFalse($f->isInIncrementsOfRanges('14', '3-59/2'));
$this->assertFalse($f->isInIncrementsOfRanges('3', '2-59'));
$this->assertFalse($f->isInIncrementsOfRanges('3', '2'));
$this->assertFalse($f->isInIncrementsOfRanges('3', '*'));
$this->assertFalse($f->isInIncrementsOfRanges('0', '*/0'));
$this->assertFalse($f->isInIncrementsOfRanges('1', '*/0'));
$this->assertTrue($f->isInIncrementsOfRanges(4, '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges(14, '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges(34, '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges('4', '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges('14', '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges('34', '4/10'));
}
/**

View File

@@ -4,12 +4,14 @@ namespace Cron\Tests;
use Cron\CronExpression;
use DateTime;
use DateTimeZone;
use InvalidArgumentException;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class CronExpressionTest extends \PHPUnit_Framework_TestCase
class CronExpressionTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\CronExpression::factory
@@ -222,9 +224,9 @@ class CronExpressionTest extends \PHPUnit_Framework_TestCase
{
$cron = CronExpression::factory('0 15 * * 3'); //Wednesday at 15:00
$date = '2014-01-01 15:00'; //Wednesday
$utc = new \DateTimeZone('UTC');
$amsterdam = new \DateTimeZone('Europe/Amsterdam');
$tokyo = new \DateTimeZone('Asia/Tokyo');
$utc = new DateTimeZone('UTC');
$amsterdam = new DateTimeZone('Europe/Amsterdam');
$tokyo = new DateTimeZone('Asia/Tokyo');
date_default_timezone_set('UTC');
$this->assertTrue($cron->isDue(new DateTime($date, $utc)));
@@ -389,10 +391,10 @@ class CronExpressionTest extends \PHPUnit_Framework_TestCase
public function testKeepOriginalTime()
{
$now = new \DateTime;
$strNow = $now->format(\DateTime::ISO8601);
$strNow = $now->format(DateTime::ISO8601);
$cron = CronExpression::factory('0 0 * * *');
$cron->getPreviousRunDate($now);
$this->assertEquals($strNow, $now->format(\DateTime::ISO8601));
$this->assertEquals($strNow, $now->format(DateTime::ISO8601));
}
/**

View File

@@ -3,23 +3,22 @@
namespace Cron\Tests;
use Cron\DayOfMonthField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class DayOfMonthFieldTest extends \PHPUnit_Framework_TestCase
class DayOfMonthFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\DayOfMonthField::validate
*/
public function testValdatesField()
public function testValidatesField()
{
$f = new DayOfMonthField();
$this->assertTrue($f->validate('1'));
$this->assertTrue($f->validate('*'));
$this->assertTrue($f->validate('*/3,1,1-12'));
$this->assertTrue($f->validate('5W,L'));
$this->assertFalse($f->validate('1.'));
}
@@ -47,4 +46,16 @@ class DayOfMonthFieldTest extends \PHPUnit_Framework_TestCase
$f->increment($d, true);
$this->assertEquals('2011-03-14 23:59: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
*
* @since 2017-01-22
*/
public function testDoesNotAccept0Date()
{
$f = new DayOfMonthField();
$this->assertFalse($f->validate(0));
}
}

View File

@@ -4,11 +4,12 @@ namespace Cron\Tests;
use Cron\DayOfWeekField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class DayOfWeekFieldTest extends \PHPUnit_Framework_TestCase
class DayOfWeekFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\DayOfWeekField::validate

View File

@@ -3,11 +3,12 @@
namespace Cron\Tests;
use Cron\FieldFactory;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class FieldFactoryTest extends \PHPUnit_Framework_TestCase
class FieldFactoryTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\FieldFactory::getField

View File

@@ -4,16 +4,17 @@ namespace Cron\Tests;
use Cron\HoursField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class HoursFieldTest extends \PHPUnit_Framework_TestCase
class HoursFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\HoursField::validate
*/
public function testValdatesField()
public function testValidatesField()
{
$f = new HoursField();
$this->assertTrue($f->validate('1'));

View File

@@ -4,16 +4,17 @@ namespace Cron\Tests;
use Cron\MinutesField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class MinutesFieldTest extends \PHPUnit_Framework_TestCase
class MinutesFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\MinutesField::validate
*/
public function testValdatesField()
public function testValidatesField()
{
$f = new MinutesField();
$this->assertTrue($f->validate('1'));

View File

@@ -4,16 +4,17 @@ namespace Cron\Tests;
use Cron\MonthField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class MonthFieldTest extends \PHPUnit_Framework_TestCase
class MonthFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\MonthField::validate
*/
public function testValdatesField()
public function testValidatesField()
{
$f = new MonthField();
$this->assertTrue($f->validate('12'));

View File

@@ -4,16 +4,17 @@ namespace Cron\Tests;
use Cron\YearField;
use DateTime;
use PHPUnit_Framework_TestCase;
/**
* @author Michael Dowling <mtdowling@gmail.com>
*/
class YearFieldTest extends \PHPUnit_Framework_TestCase
class YearFieldTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Cron\YearField::validate
*/
public function testValdatesField()
public function testValidatesField()
{
$f = new YearField();
$this->assertTrue($f->validate('2011'));

View File

@@ -1,5 +1,10 @@
# CHANGELOG
## 2.4.0 - 2016-12-03
* Added support for floats when interpreting data.
* Added a function_exists check to work around redeclaration issues.
## 2.3.0 - 2016-01-05
* Added support for [JEP-9](https://github.com/jmespath/jmespath.site/blob/master/docs/proposals/improved-filters.rst),

View File

@@ -5,11 +5,13 @@ namespace JmesPath;
* Returns data from the input array that matches a JMESPath expression.
*
* @param string $expression Expression to search.
* @param mixed $data Data to search.
* @param mixed $data Data to search.
*
* @return mixed|null
*/
function search($expression, $data)
{
return Env::search($expression, $data);
if (!function_exists(__NAMESPACE__ . '\search')) {
function search($expression, $data)
{
return Env::search($expression, $data);
}
}

View File

@@ -401,8 +401,8 @@ class TreeCompiler
$this->write('$value = !Utils::isEqual(%s, %s);', $a, $b);
} else {
$this->write(
'$value = is_int(%s) && is_int(%s) && %s %s %s;',
$a, $b, $a, $node['value'], $b
'$value = (is_int(%s) || is_float(%s)) && (is_int(%s) || is_float(%s)) && %s %s %s;',
$a, $a, $b, $b, $a, $node['value'], $b
);
}

View File

@@ -220,7 +220,7 @@ class TreeInterpreter
*/
private static function relativeCmp($left, $right, $cmp)
{
if (!is_int($left) || !is_int($right)) {
if (!(is_int($left) || is_float($left)) || !(is_int($right) || is_float($right))) {
return false;
}

View File

@@ -80,6 +80,50 @@
}
]
},
{
"given": {"foo": [{"weight": 33.3},
{"weight": 44.4},
{"weight": 55.5}]},
"cases": [
{
"comment": "Greater than with a number",
"expression": "foo[?weight > `44.4`]",
"result": [{"weight": 55.5}]
},
{
"expression": "foo[?weight >= `44.4`]",
"result": [{"weight": 44.4}, {"weight": 55.5}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight > `55.5`]",
"result": []
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight < `44.4`]",
"result": [{"weight": 33.3}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight <= `44.4`]",
"result": [{"weight": 33.3}, {"weight": 44.4}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight < `33.3`]",
"result": []
},
{
"expression": "foo[?weight == `33.3`]",
"result": [{"weight": 33.3}]
},
{
"expression": "foo[?weight != `33.3`]",
"result": [{"weight": 44.4}, {"weight": 55.5}]
}
]
},
{
"given": {"foo": [{"top": {"name": "a"}},
{"top": {"name": "b"}}]},