mirror of
https://github.com/rlanvin/php-rrule.git
synced 2024-11-28 05:24:10 +01:00
Test enhancement (#52)
This commit is contained in:
parent
157c266ce7
commit
8a3dd6d76a
@ -1,15 +1,16 @@
|
||||
dist: precise
|
||||
language: php
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.3
|
||||
dist: precise
|
||||
install:
|
||||
- composer install
|
||||
- composer require --dev phpunit/phpunit "<6"
|
||||
- composer install -n
|
||||
script:
|
||||
- vendor/bin/phpunit
|
@ -16,7 +16,12 @@
|
||||
"RRule\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"RRule\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "<6"
|
||||
"phpunit/phpunit": "^4.8|^5.5|^6.5"
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RRule\Tests;
|
||||
|
||||
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
|
||||
// Europe/Helsinki has DST
|
||||
date_default_timezone_set('Europe/Helsinki');
|
||||
|
||||
class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
class RRuleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* These rules are invalid according to the RFC
|
||||
@ -107,7 +110,8 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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-04'),date_create('2017-01-05')
|
||||
), $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()
|
||||
@ -1777,12 +1788,19 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
$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->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');
|
||||
$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'));
|
||||
$this->fail('Expected InvalidArgumentException (too many dtstart) not thrown');
|
||||
} catch ( \InvalidArgumentException $e ) {
|
||||
|
||||
}
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Too many DTSTART properties (there can be only one)
|
||||
*/
|
||||
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
|
||||
* @expectedException PHPUnit_Framework_Error_Notice
|
||||
* @expectedException PHPUnit\Framework\Error\Notice
|
||||
*/
|
||||
public function testQuirkyRfcStringsParserNotice($str,$occurrences)
|
||||
{
|
||||
@ -2076,6 +2096,7 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$str = $rrule->rfcString();
|
||||
$new_rrule = new RRule($str);
|
||||
$this->assertInstanceOf('RRule\RRule', $new_rrule);
|
||||
}
|
||||
|
||||
public function testUnsupportedTimezoneConvertedToUtc()
|
||||
|
@ -1,9 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RRule\Tests;
|
||||
|
||||
use RRule\RSet;
|
||||
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()
|
||||
{
|
||||
@ -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-04'),date_create('2017-01-05')
|
||||
), $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()
|
||||
@ -465,12 +479,20 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
$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->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-03')
|
||||
), $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()
|
||||
{
|
||||
return array(
|
||||
@ -569,7 +594,7 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider quirkyRfcStrings
|
||||
* @expectedException PHPUnit_Framework_Error_Notice
|
||||
* @expectedException PHPUnit\Framework\Error\Notice
|
||||
*/
|
||||
public function testParseQuirkyRfcStringNotice($string, $occurrences)
|
||||
{
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?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()
|
||||
{
|
||||
|
10
tests/bootstrap.php
Executable file → Normal file
10
tests/bootstrap.php
Executable file → Normal file
@ -1,3 +1,11 @@
|
||||
<?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…
Reference in New Issue
Block a user