Skip to content

Commit

Permalink
Add tests for PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rlanvin committed Dec 9, 2020
1 parent 3036bf3 commit a14dd53
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 51 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4','8.0']
name: PHP ${{ matrix.php }}
steps:
- name: Checkout
Expand All @@ -19,6 +19,11 @@ jobs:
php-version: ${{ matrix.php }}
extensions: intl

- name: Display versions
run: |
php -v
php -i
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
Expand All @@ -30,10 +35,4 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install -n

- name: Display versions
run: |
php -v
php -i
vendor/bin/phpunit -v
- run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.5",
"phpunit/phpunit": "^5.7|^6.5|^8.0",
"phpmd/phpmd" : "@stable"
}
}
49 changes: 20 additions & 29 deletions tests/RRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public function invalidRules()

/**
* @dataProvider invalidRules
* @expectedException InvalidArgumentException
*/
public function testInvalidRules($rule)
{
$this->expectException(\InvalidArgumentException::class);
new RRule($rule);
}

Expand Down Expand Up @@ -1834,12 +1834,10 @@ public function testGetOccurrences()
), $rrule->getOccurrences(5));
}

/**
* @expectedException LogicException
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
*/
public function testGetOccurrencesThrowsLogicException()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Cannot get all occurrences of an infinite recurrence rule.");
$rrule = new RRule(array(
'FREQ' => 'DAILY',
'DTSTART' => '2017-01-01'
Expand Down Expand Up @@ -1889,12 +1887,10 @@ public function testGetOccurrencesBetween($rule, $begin, $end, $limit, $expected
$this->assertEquals($expected, $rrule->getOccurrencesBetween($begin, $end, $limit));
}

/**
* @expectedException LogicException
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
*/
public function testGetOccurrencesBetweenThrowsLogicException()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Cannot get all occurrences of an infinite recurrence rule.");
$rrule = new RRule(array(
'FREQ' => 'DAILY',
'DTSTART' => '2017-01-01'
Expand Down Expand Up @@ -1987,21 +1983,21 @@ public function testGetNthOccurrenceFrom($rrule, $date, $index, $result)
public function testGetNthOccurrenceFromInvalidIndex()
{
$rrule = new RRule(['FREQ' => 'DAILY']);
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$rrule->getNthOccurrenceFrom(date_create('2017-01-09'), []);
}

public function testGetNthOccurrenceBeforeInvalidIndex()
{
$rrule = new RRule(['FREQ' => 'DAILY']);
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$rrule->getNthOccurrenceBefore(date_create('2017-01-09'), -1);
}

public function testGetNthOccurrenceAfterInvalidIndex()
{
$rrule = new RRule(['FREQ' => 'DAILY']);
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$rrule->getNthOccurrenceAfter(date_create('2017-01-09'), -1);
}

Expand Down Expand Up @@ -2178,12 +2174,11 @@ public function testRfcStringParserWithDtStart()
$this->assertEquals('2017-01-01', $rrule[0]->format('Y-m-d'));
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Too many DTSTART properties (there can be only one)
*/
public function testRfcStringParserWithMultipleDtStart()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Too many DTSTART properties (there can be only one)");

$rrule = new RRule("DTSTART:19970512\nRRULE:FREQ=YEARLY", date_create('2017-01-01'));
}

Expand Down Expand Up @@ -2214,10 +2209,10 @@ public function quirkyRfcStrings()

/**
* @dataProvider quirkyRfcStrings
* @expectedException PHPUnit\Framework\Error\Notice
*/
public function testQuirkyRfcStringsParserNotice($str,$occurrences)
{
$this->expectException(\PHPUnit\Framework\Error\Notice::class);
$rule = new RRule($str);
}

Expand Down Expand Up @@ -2283,11 +2278,11 @@ public function invalidRfcStrings()
}

/**
* @expectedException InvalidArgumentException
* @dataProvider invalidRfcStrings
*/
public function testInvalidRfcStrings($str)
{
$this->expectException(\InvalidArgumentException::class);
$rule = new RRule($str);
}

Expand Down Expand Up @@ -2801,7 +2796,7 @@ public function testCannotCountInfinite()
$rrule = new RRule(array(
'freq' => 'yearly'
));
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
count($rrule);
}

Expand Down Expand Up @@ -2845,7 +2840,7 @@ public function testOffsetSetUnsupported()
'byday' => 'TU,TH',
'dtstart' => '2007-01-01'
));
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
$rrule[] = 'blah';
}

Expand All @@ -2857,7 +2852,7 @@ public function testOffsetUnsetUnsupported()
'byday' => 'TU,TH',
'dtstart' => '2007-01-01'
));
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
unset($rrule[0]);
}

Expand All @@ -2876,10 +2871,10 @@ public function illegalOffsets()

/**
* @dataProvider illegalOffsets
* @expectedException InvalidArgumentException
*/
public function testOffsetGetInvalidArgument($offset)
{
$this->expectException(\InvalidArgumentException::class);
$rrule = new RRule(array(
'freq' => 'daily',
'count' => 3,
Expand Down Expand Up @@ -3014,11 +3009,10 @@ public function testI18nLoadFallback($fallback)

/**
* Tests that the RRule::i18nLoad() fails as expected on invalid $locale settings
*
* @expectedException \InvalidArgumentException
*/
public function testI18nLoadFailsWithoutIntl()
{
$this->expectException(\InvalidArgumentException::class);
$reflector = new ReflectionClass('RRule\RRule');

$method = $reflector->getMethod('i18nLoad');
Expand All @@ -3028,23 +3022,20 @@ public function testI18nLoadFailsWithoutIntl()

/**
* Tests that the RRule::i18nLoad() fails as expected on invalid $fallback settings
*
* @expectedException \InvalidArgumentException
*/
public function testI18nLoadFallbackFailsWitoutIntl()
{
$this->expectException(\InvalidArgumentException::class);
$reflector = new ReflectionClass('RRule\RRule');

$method = $reflector->getMethod('i18nLoad');
$method->setAccessible(true);
$method->invokeArgs(null, array('xx', 'invalid', false));
}

/**
* @expectedException RuntimeException
*/
public function testHumanReadableRuntimeException()
{
$this->expectException(\RuntimeException::class);
$rrule = new RRule(array(
'freq' => 'daily',
'count' => 10,
Expand Down
25 changes: 11 additions & 14 deletions tests/RSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ public function illegalOffsets()

/**
* @dataProvider illegalOffsets
* @expectedException InvalidArgumentException
*/
public function testOffsetGetInvalidArgument($offset)
{
$this->expectException(\InvalidArgumentException::class);
$rset = new RSet();
$rset->addRRule(array(
'FREQ' => 'YEARLY',
Expand Down Expand Up @@ -621,12 +621,10 @@ public function testGetOccurrences()
), $rset->getOccurrences(5));
}

/**
* @expectedException LogicException
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence set.
*/
public function testGetOccurrencesThrowsLogicException()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Cannot get all occurrences of an infinite recurrence set.");
$rset = new RSet();
$rset->addRRule(new RRule(array(
'FREQ' => 'DAILY',
Expand Down Expand Up @@ -664,12 +662,12 @@ public function testGetOccurrencesBetween(RSet $rset, $begin, $end, $limit, $exp
$this->assertEquals($expected, $rset->getOccurrencesBetween($begin, $end, $limit));
}

/**
* @expectedException LogicException
* @expectedExceptionMessage Cannot get all occurrences of an infinite recurrence rule.
*/

public function testGetOccurrencesBetweenThrowsLogicException()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Cannot get all occurrences of an infinite recurrence rule.");

$rset = new RSet();
$rset->addRRule(new RRule(array(
'FREQ' => 'DAILY',
Expand Down Expand Up @@ -828,12 +826,10 @@ public function testParseRfcStringWithDtStart()
), $rset->getOccurrences());
}

/**
* @expectedException InvalidArgumentException
* @expectedExcpetionMessage Failed to parse RFC string, multiple DTSTART found
*/
public function testParseRfcStringWithMultipleDtStart()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Failed to parse RFC string, multiple DTSTART found");
$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')
Expand All @@ -859,10 +855,11 @@ public function quirkyRfcStrings()

/**
* @dataProvider quirkyRfcStrings
* @expectedException PHPUnit\Framework\Error\Notice
*/
public function testParseQuirkyRfcStringNotice($string, $occurrences)
{
$this->expectException(\PHPUnit\Framework\Error\Notice::class);

$object = new RSet($string);
}

Expand Down

0 comments on commit a14dd53

Please sign in to comment.