From a14dd53090fe18cb7ef6f05afe32cbd394efe256 Mon Sep 17 00:00:00 2001 From: rlanvin Date: Wed, 9 Dec 2020 22:26:35 +0100 Subject: [PATCH] Add tests for PHP 8.0 --- .github/workflows/tests.yml | 13 +++++----- composer.json | 2 +- tests/RRuleTest.php | 49 +++++++++++++++---------------------- tests/RSetTest.php | 25 +++++++++---------- 4 files changed, 38 insertions(+), 51 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89ab407..68ddd1a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 @@ -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 diff --git a/composer.json b/composer.json index f53c11c..3771d12 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^5.7|^6.5", + "phpunit/phpunit": "^5.7|^6.5|^8.0", "phpmd/phpmd" : "@stable" } } diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php index 078133f..2c28583 100755 --- a/tests/RRuleTest.php +++ b/tests/RRuleTest.php @@ -94,10 +94,10 @@ class RRuleTest extends TestCase /** * @dataProvider invalidRules - * @expectedException InvalidArgumentException */ public function testInvalidRules($rule) { + $this->expectException(\InvalidArgumentException::class); new RRule($rule); } @@ -1834,12 +1834,10 @@ class RRuleTest extends TestCase ), $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' @@ -1889,12 +1887,10 @@ class RRuleTest extends TestCase $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' @@ -1987,21 +1983,21 @@ class RRuleTest extends TestCase 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); } @@ -2178,12 +2174,11 @@ class RRuleTest extends TestCase $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')); } @@ -2214,10 +2209,10 @@ class RRuleTest extends TestCase /** * @dataProvider quirkyRfcStrings - * @expectedException PHPUnit\Framework\Error\Notice */ public function testQuirkyRfcStringsParserNotice($str,$occurrences) { + $this->expectException(\PHPUnit\Framework\Error\Notice::class); $rule = new RRule($str); } @@ -2283,11 +2278,11 @@ class RRuleTest extends TestCase } /** - * @expectedException InvalidArgumentException * @dataProvider invalidRfcStrings */ public function testInvalidRfcStrings($str) { + $this->expectException(\InvalidArgumentException::class); $rule = new RRule($str); } @@ -2801,7 +2796,7 @@ class RRuleTest extends TestCase $rrule = new RRule(array( 'freq' => 'yearly' )); - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); count($rrule); } @@ -2845,7 +2840,7 @@ class RRuleTest extends TestCase 'byday' => 'TU,TH', 'dtstart' => '2007-01-01' )); - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $rrule[] = 'blah'; } @@ -2857,7 +2852,7 @@ class RRuleTest extends TestCase 'byday' => 'TU,TH', 'dtstart' => '2007-01-01' )); - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); unset($rrule[0]); } @@ -2876,10 +2871,10 @@ class RRuleTest extends TestCase /** * @dataProvider illegalOffsets - * @expectedException InvalidArgumentException */ public function testOffsetGetInvalidArgument($offset) { + $this->expectException(\InvalidArgumentException::class); $rrule = new RRule(array( 'freq' => 'daily', 'count' => 3, @@ -3014,11 +3009,10 @@ class RRuleTest extends TestCase /** * 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'); @@ -3028,11 +3022,10 @@ class RRuleTest extends TestCase /** * 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'); @@ -3040,11 +3033,9 @@ class RRuleTest extends TestCase $method->invokeArgs(null, array('xx', 'invalid', false)); } - /** - * @expectedException RuntimeException - */ public function testHumanReadableRuntimeException() { + $this->expectException(\RuntimeException::class); $rrule = new RRule(array( 'freq' => 'daily', 'count' => 10, diff --git a/tests/RSetTest.php b/tests/RSetTest.php index 33bf37a..b606636 100755 --- a/tests/RSetTest.php +++ b/tests/RSetTest.php @@ -425,10 +425,10 @@ class RSetTest extends TestCase /** * @dataProvider illegalOffsets - * @expectedException InvalidArgumentException */ public function testOffsetGetInvalidArgument($offset) { + $this->expectException(\InvalidArgumentException::class); $rset = new RSet(); $rset->addRRule(array( 'FREQ' => 'YEARLY', @@ -621,12 +621,10 @@ class RSetTest extends TestCase ), $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', @@ -664,12 +662,12 @@ class RSetTest extends TestCase $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', @@ -828,12 +826,10 @@ class RSetTest extends TestCase ), $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') @@ -859,10 +855,11 @@ class RSetTest extends TestCase /** * @dataProvider quirkyRfcStrings - * @expectedException PHPUnit\Framework\Error\Notice */ public function testParseQuirkyRfcStringNotice($string, $occurrences) { + $this->expectException(\PHPUnit\Framework\Error\Notice::class); + $object = new RSet($string); }