mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-26 15:54:14 +01:00
Test enhancement (#52)
This commit is contained in:
parent
157c266ce7
commit
8a3dd6d76a
@ -1,15 +1,16 @@
|
|||||||
dist: precise
|
|
||||||
language: php
|
language: php
|
||||||
php:
|
php:
|
||||||
- 5.3
|
|
||||||
- 5.4
|
- 5.4
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
- 7.2
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: 5.3
|
||||||
|
dist: precise
|
||||||
install:
|
install:
|
||||||
- composer install
|
- composer install -n
|
||||||
- composer require --dev phpunit/phpunit "<6"
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpunit
|
- vendor/bin/phpunit
|
@ -16,7 +16,12 @@
|
|||||||
"RRule\\": "src/"
|
"RRule\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"RRule\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "<6"
|
"phpunit/phpunit": "^4.8|^5.5|^6.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace RRule\Tests;
|
||||||
|
|
||||||
use RRule\RRule;
|
use RRule\RRule;
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeZone;
|
||||||
|
use ReflectionClass;
|
||||||
|
use stdClass;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
// make sure that the tests are run in the same timezone everywhere
|
class RRuleTest extends TestCase
|
||||||
// Europe/Helsinki has DST
|
|
||||||
date_default_timezone_set('Europe/Helsinki');
|
|
||||||
|
|
||||||
class RRuleTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* These rules are invalid according to the RFC
|
* These rules are invalid according to the RFC
|
||||||
@ -107,7 +110,8 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidRules($rule)
|
public function testValidRules($rule)
|
||||||
{
|
{
|
||||||
new RRule($rule);
|
$result = new RRule($rule);
|
||||||
|
$this->assertInstanceOf('RRule\RRule', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1758,12 +1762,19 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
date_create('2017-01-01'),date_create('2017-01-02'),date_create('2017-01-03'),
|
date_create('2017-01-01'),date_create('2017-01-02'),date_create('2017-01-03'),
|
||||||
date_create('2017-01-04'),date_create('2017-01-05')
|
date_create('2017-01-04'),date_create('2017-01-05')
|
||||||
), $rrule->getOccurrences(5));
|
), $rrule->getOccurrences(5));
|
||||||
try {
|
}
|
||||||
$rrule->getOccurrences();
|
|
||||||
$this->fail('Expected exception (infinite rule) not thrown');
|
|
||||||
} catch ( \LogicException $e ) {
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @expectedException LogicException
|
||||||
|
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
|
||||||
|
*/
|
||||||
|
public function testGetOccurrencesThrowsLogicException()
|
||||||
|
{
|
||||||
|
$rrule = new RRule(array(
|
||||||
|
'FREQ' => 'DAILY',
|
||||||
|
'DTSTART' => '2017-01-01'
|
||||||
|
));
|
||||||
|
$rrule->getOccurrences();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOccurrencesBetween()
|
public function testGetOccurrencesBetween()
|
||||||
@ -1777,12 +1788,19 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $rrule->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
$this->assertCount(1, $rrule->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||||
$this->assertEquals(array(date_create('2017-02-01')), $rrule->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
$this->assertEquals(array(date_create('2017-02-01')), $rrule->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||||
$this->assertCount(5, $rrule->getOccurrencesBetween('2017-01-01', null, 5));
|
$this->assertCount(5, $rrule->getOccurrencesBetween('2017-01-01', null, 5));
|
||||||
try {
|
}
|
||||||
$rrule->getOccurrencesBetween('2017-01-01', null);
|
|
||||||
$this->fail('Expected exception (infinite rule) not thrown');
|
|
||||||
} catch ( \LogicException $e ) {
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @expectedException LogicException
|
||||||
|
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
|
||||||
|
*/
|
||||||
|
public function testGetOccurrencesBetweenThrowsLogicException()
|
||||||
|
{
|
||||||
|
$rrule = new RRule(array(
|
||||||
|
'FREQ' => 'DAILY',
|
||||||
|
'DTSTART' => '2017-01-01'
|
||||||
|
));
|
||||||
|
$rrule->getOccurrencesBetween('2017-01-01', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -1943,13 +1961,15 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$rrule = new RRule('RRULE:FREQ=YEARLY', '2017-01-01');
|
$rrule = new RRule('RRULE:FREQ=YEARLY', '2017-01-01');
|
||||||
$this->assertEquals('2017-01-01', $rrule[0]->format('Y-m-d'));
|
$this->assertEquals('2017-01-01', $rrule[0]->format('Y-m-d'));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
/**
|
||||||
$rrule = new RRule("DTSTART:19970512\nRRULE:FREQ=YEARLY", date_create('2017-01-01'));
|
* @expectedException InvalidArgumentException
|
||||||
$this->fail('Expected InvalidArgumentException (too many dtstart) not thrown');
|
* @expectedExceptionMessage Too many DTSTART properties (there can be only one)
|
||||||
} catch ( \InvalidArgumentException $e ) {
|
*/
|
||||||
|
public function testRfcStringParserWithMultipleDtStart()
|
||||||
}
|
{
|
||||||
|
$rrule = new RRule("DTSTART:19970512\nRRULE:FREQ=YEARLY", date_create('2017-01-01'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1979,7 +1999,7 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider quirkyRfcStrings
|
* @dataProvider quirkyRfcStrings
|
||||||
* @expectedException PHPUnit_Framework_Error_Notice
|
* @expectedException PHPUnit\Framework\Error\Notice
|
||||||
*/
|
*/
|
||||||
public function testQuirkyRfcStringsParserNotice($str,$occurrences)
|
public function testQuirkyRfcStringsParserNotice($str,$occurrences)
|
||||||
{
|
{
|
||||||
@ -2076,6 +2096,7 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$str = $rrule->rfcString();
|
$str = $rrule->rfcString();
|
||||||
$new_rrule = new RRule($str);
|
$new_rrule = new RRule($str);
|
||||||
|
$this->assertInstanceOf('RRule\RRule', $new_rrule);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnsupportedTimezoneConvertedToUtc()
|
public function testUnsupportedTimezoneConvertedToUtc()
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace RRule\Tests;
|
||||||
|
|
||||||
use RRule\RSet;
|
use RRule\RSet;
|
||||||
use RRule\RRule;
|
use RRule\RRule;
|
||||||
|
use DateTimeZone;
|
||||||
|
use ReflectionObject;
|
||||||
|
use stdClass;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class RSetTest extends PHPUnit_Framework_TestCase
|
class RSetTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCombineRRule()
|
public function testCombineRRule()
|
||||||
{
|
{
|
||||||
@ -445,12 +451,20 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
|||||||
date_create('2017-01-01'),date_create('2017-01-02'),date_create('2017-01-03'),
|
date_create('2017-01-01'),date_create('2017-01-02'),date_create('2017-01-03'),
|
||||||
date_create('2017-01-04'),date_create('2017-01-05')
|
date_create('2017-01-04'),date_create('2017-01-05')
|
||||||
), $rset->getOccurrences(5));
|
), $rset->getOccurrences(5));
|
||||||
try {
|
}
|
||||||
$rset->getOccurrences();
|
|
||||||
$this->fail('Expected exception (infinite rule) not thrown');
|
|
||||||
} catch ( \LogicException $e ) {
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @expectedException LogicException
|
||||||
|
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence set.
|
||||||
|
*/
|
||||||
|
public function testGetOccurrencesThrowsLogicException()
|
||||||
|
{
|
||||||
|
$rset = new RSet();
|
||||||
|
$rset->addRRule(new RRule(array(
|
||||||
|
'FREQ' => 'DAILY',
|
||||||
|
'DTSTART' => '2017-01-01'
|
||||||
|
)));
|
||||||
|
$rset->getOccurrences();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOccurrencesBetween()
|
public function testGetOccurrencesBetween()
|
||||||
@ -465,12 +479,20 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
$this->assertCount(1, $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||||
$this->assertEquals(array(date_create('2017-02-01')), $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
$this->assertEquals(array(date_create('2017-02-01')), $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||||
$this->assertCount(5, $rset->getOccurrencesBetween('2017-01-01', null, 5));
|
$this->assertCount(5, $rset->getOccurrencesBetween('2017-01-01', null, 5));
|
||||||
try {
|
}
|
||||||
$rset->getOccurrencesBetween('2017-01-01', null);
|
|
||||||
$this->fail('Expected exception (infinite rule) not thrown');
|
|
||||||
} catch ( \LogicException $e ) {
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @expectedException LogicException
|
||||||
|
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
|
||||||
|
*/
|
||||||
|
public function testGetOccurrencesBetweenThrowsLogicException()
|
||||||
|
{
|
||||||
|
$rset = new RSet();
|
||||||
|
$rset->addRRule(new RRule(array(
|
||||||
|
'FREQ' => 'DAILY',
|
||||||
|
'DTSTART' => '2017-01-01'
|
||||||
|
)));
|
||||||
|
$rset->getOccurrencesBetween('2017-01-01', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -539,17 +561,20 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
|||||||
date_create('2017-01-02'),
|
date_create('2017-01-02'),
|
||||||
date_create('2017-01-03')
|
date_create('2017-01-03')
|
||||||
), $rset->getOccurrences());
|
), $rset->getOccurrences());
|
||||||
|
|
||||||
try {
|
|
||||||
$rset = new RSet(
|
|
||||||
"DTSTART:DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;COUNT=3\nEXRULE:FREQ=DAILY;INTERVAL=2;COUNT=1",
|
|
||||||
date_create('2017-01-01')
|
|
||||||
);
|
|
||||||
$this->fail('Expected InvalidArgumentException (too many start date) not thrown');
|
|
||||||
} catch ( InvalidArgumentException $e ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException InvalidArgumentException
|
||||||
|
* @expectedExcpetionMessage Failed to parse RFC string, multiple DTSTART found
|
||||||
|
*/
|
||||||
|
public function testParseRfcStringWithMultipleDtStart()
|
||||||
|
{
|
||||||
|
$rset = new RSet(
|
||||||
|
"DTSTART:DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;COUNT=3\nEXRULE:FREQ=DAILY;INTERVAL=2;COUNT=1",
|
||||||
|
date_create('2017-01-01')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function quirkyRfcStrings()
|
public function quirkyRfcStrings()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -569,7 +594,7 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider quirkyRfcStrings
|
* @dataProvider quirkyRfcStrings
|
||||||
* @expectedException PHPUnit_Framework_Error_Notice
|
* @expectedException PHPUnit\Framework\Error\Notice
|
||||||
*/
|
*/
|
||||||
public function testParseQuirkyRfcStringNotice($string, $occurrences)
|
public function testParseQuirkyRfcStringNotice($string, $occurrences)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use RRule\RfcParser;
|
namespace RRule\Tests;
|
||||||
|
|
||||||
class RfcParserTest extends PHPUnit_Framework_TestCase
|
use RRule\RfcParser;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class RfcParserTest extends TestCase
|
||||||
{
|
{
|
||||||
public function rfcLines()
|
public function rfcLines()
|
||||||
{
|
{
|
||||||
|
10
tests/bootstrap.php
Executable file → Normal file
10
tests/bootstrap.php
Executable file → Normal file
@ -1,3 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require __DIR__.'/../vendor/autoload.php';
|
require_once __DIR__.'/../vendor/autoload.php';
|
||||||
|
|
||||||
|
if (class_exists('PHPUnit_Framework_Error_Notice')) {
|
||||||
|
class_alias('PHPUnit_Framework_Error_Notice', 'PHPUnit\Framework\Error\Notice');
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure that the tests are run in the same timezone everywhere
|
||||||
|
// Europe/Helsinki has DST
|
||||||
|
date_default_timezone_set('Europe/Helsinki');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user