diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 77ed5daf..5de128fd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,13 +12,9 @@ jobs: strategy: matrix: php-version: - - "7.1" - - "7.2" - - "7.3" - "7.4" - # I am to lazy to fix the CI now, because we will update PHPUnit and drop some PHP versions later, - # then this version will be activate again and everything should work... - # - "8.0" + - "8.0" + - "8.1" steps: - name: "Checkout" uses: "actions/checkout@v3" diff --git a/.gitignore b/.gitignore index da09e597..9e173a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.php_cs.cache +.phpunit.result.cache /composer.lock /vendor diff --git a/CHANGELOG.md b/CHANGELOG.md index fe4332af..31e4e0ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Added +- Support PHP 8.1 +### Changed +- Use PHPUnit v9.5 +### Removed +- Support for EOL PHP versions (7.1, 7.2, 7.3) + ## [0.16.1] ### Added - Support PHP 8.0 [#194](https://github.com/markuspoerschke/iCal/pull/194) diff --git a/composer.json b/composer.json index a4a93b70..310b7a6a 100644 --- a/composer.json +++ b/composer.json @@ -32,13 +32,13 @@ } }, "require": { - "php": ">=7.1 || ~8.0.0" + "php": ">=7.4" }, "suggest": { "ext-mbstring" : "Massive performance enhancement of line folding" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.5" }, "scripts": { "test": "phpunit" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9cea0ccd..7d7764eb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,23 +1,25 @@ - - - - - + bootstrap="./vendor/autoload.php" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"> + + + src + + + + + + ./tests/Eluceo/iCal/ - - - src - - diff --git a/src/Property/Event/RecurrenceRule.php b/src/Property/Event/RecurrenceRule.php index c5015c95..a424d254 100644 --- a/src/Property/Event/RecurrenceRule.php +++ b/src/Property/Event/RecurrenceRule.php @@ -245,9 +245,13 @@ public function getUntil() */ public function setFreq($freq) { - if (@constant('static::FREQ_' . $freq) !== null) { - $this->freq = $freq; - } else { + try { + if (@constant('static::FREQ_' . $freq) !== null) { + $this->freq = $freq; + } else { + throw new \InvalidArgumentException("The Frequency {$freq} is not supported."); + } + } catch (\Error $error) { throw new \InvalidArgumentException("The Frequency {$freq} is not supported."); } diff --git a/src/PropertyBag.php b/src/PropertyBag.php index 4ff82d88..df70ecd3 100644 --- a/src/PropertyBag.php +++ b/src/PropertyBag.php @@ -66,7 +66,7 @@ public function add(Property $property) return $this; } - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayObject($this->elements); } diff --git a/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php b/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php index eac4729b..1b4d55dc 100644 --- a/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php +++ b/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php @@ -61,7 +61,7 @@ public function testExample3() { $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line); - $this->assertRegExp($lines[$key], $line); + $this->assertMatchesRegularExpression($lines[$key], $line); } } @@ -116,7 +116,7 @@ public function testExample4b() { $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line); - $this->assertRegExp($lines[$key], $line); + $this->assertMatchesRegularExpression($lines[$key], $line); } } @@ -191,7 +191,7 @@ public function testEventAddAttachment() { $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line); - $this->assertRegExp($lines[$key], $line); + $this->assertMatchesRegularExpression($lines[$key], $line); } } } diff --git a/tests/Eluceo/iCal/Component/CalendarTest.php b/tests/Eluceo/iCal/Component/CalendarTest.php index 5237cc1f..751161c9 100644 --- a/tests/Eluceo/iCal/Component/CalendarTest.php +++ b/tests/Eluceo/iCal/Component/CalendarTest.php @@ -6,12 +6,11 @@ class CalendarTest extends TestCase { - /** - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage PRODID cannot be empty - */ public function testConstructorThrowsUnexpectedValueException() { + $this->expectExceptionMessage("PRODID cannot be empty"); + $this->expectException(\UnexpectedValueException::class); + new Calendar(null); } @@ -108,6 +107,6 @@ public function testAddEvent() $calendar = new Calendar('-//ABC Corporation//NONSGML My Product//EN'); $calendar->addEvent(new Event('unique_id')); - $this->assertContains("unique_id", $calendar->render()); + $this->assertStringContainsString("unique_id", $calendar->render()); } } diff --git a/tests/Eluceo/iCal/Component/EventTest.php b/tests/Eluceo/iCal/Component/EventTest.php index a46e2ff7..c2b08cc3 100644 --- a/tests/Eluceo/iCal/Component/EventTest.php +++ b/tests/Eluceo/iCal/Component/EventTest.php @@ -65,12 +65,11 @@ public function testSetLocation() $this->assertSame('LOCATION:Conference Room - F123\, Bldg. 002', $result['LOCATION']->toLine()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The parameter 'geo' must be a string or an instance of Eluceo\iCal\Property\Event\Geo but an instance of ArrayObject was given. - */ public function testSetLocationOnInvalidGeo() { + $this->expectExceptionMessage("The parameter 'geo' must be a string or an instance of Eluceo\iCal\Property\Event\Geo but an instance of ArrayObject was given."); + $this->expectException(\InvalidArgumentException::class); + $event = new Event('19960401T080045Z-4000F192713-0052@host1.com'); $event->setLocation('Conference Room - F123, Bldg. 002', '', new \ArrayObject([25.632, 122.072])); $result = $event->buildPropertyBag()->getIterator()->getArrayCopy(); diff --git a/tests/Eluceo/iCal/ComponentTest.php b/tests/Eluceo/iCal/ComponentTest.php index 1a1feae5..f8ee333a 100644 --- a/tests/Eluceo/iCal/ComponentTest.php +++ b/tests/Eluceo/iCal/ComponentTest.php @@ -26,7 +26,7 @@ public function testFoldWithMultibyte() $output = $vCalendar->render(); $output = preg_replace('/\r\n /u', '', $output); - $this->assertContains($input, $output); + $this->assertStringContainsString($input, $output); } public function testDescriptionWithNewLines() @@ -42,7 +42,7 @@ public function testDescriptionWithNewLines() $vCalendar->addComponent($vEvent); $output = $vCalendar->render(); - $this->assertContains(str_replace("\n", "\\n", $input), $output); + $this->assertStringContainsString(str_replace("\n", "\\n", $input), $output); } public function testAddComponentOnKey() @@ -58,7 +58,7 @@ public function testAddComponentOnKey() $vCalendar->addComponent($vEvent, 'eventKey'); $output = $vCalendar->render(); - $this->assertContains(str_replace("\n", "\\n", $input), $output); + $this->assertStringContainsString(str_replace("\n", "\\n", $input), $output); } public function testSetComponents() @@ -80,8 +80,8 @@ public function testSetComponents() $vCalendar->setComponents([$vEventTwo]); $output = $vCalendar->render(); - $this->assertContains($shouldBeFound, $output); - $this->assertNotContains($shouldNotBeFound, $output); + $this->assertStringContainsString($shouldBeFound, $output); + $this->assertStringNotContainsString($shouldNotBeFound, $output); } public function testToString() diff --git a/tests/Eluceo/iCal/Property/Event/AttendeesTest.php b/tests/Eluceo/iCal/Property/Event/AttendeesTest.php index 6083f565..2fa50238 100644 --- a/tests/Eluceo/iCal/Property/Event/AttendeesTest.php +++ b/tests/Eluceo/iCal/Property/Event/AttendeesTest.php @@ -30,22 +30,20 @@ public function testGetValue() $this->assertCount(0, $attendees->getValue()); } - /** - * @expectedException \BadMethodCallException - * @expectedExceptionMessage Cannot call setParam on Attendees Property - */ public function testSetParamThrowsBadMethodCallException() { + $this->expectExceptionMessage("Cannot call setParam on Attendees Property"); + $this->expectException(\BadMethodCallException::class); + $attendees = new Attendees(); $attendees->setParam('MAILTO', 'DEV-GROUP@host2.com'); } - /** - * @expectedException \BadMethodCallException - * @expectedExceptionMessage Cannot call getParam on Attendees Property - */ public function testGetParamThrowsBadMethodCallException() { + $this->expectExceptionMessage("Cannot call getParam on Attendees Property"); + $this->expectException(\BadMethodCallException::class); + $attendees = new Attendees(); $attendees->getParam('MAILTO'); } diff --git a/tests/Eluceo/iCal/Property/Event/GeoTest.php b/tests/Eluceo/iCal/Property/Event/GeoTest.php index c5c7d8c1..a698a216 100644 --- a/tests/Eluceo/iCal/Property/Event/GeoTest.php +++ b/tests/Eluceo/iCal/Property/Event/GeoTest.php @@ -13,21 +13,19 @@ public function testConstructor() $this->assertInstanceOf(Geo::class, $geo); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The geographical latitude must be a value between -90 and 90 degrees. '-100' was given. - */ public function testConstructorOnInvalidLatitude() { + $this->expectExceptionMessage("The geographical latitude must be a value between -90 and 90 degrees. '-100' was given."); + $this->expectException(\InvalidArgumentException::class); + new Geo(-100, 122.072); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The geographical longitude must be a value between -180 and 180 degrees. '-200' was given. - */ public function testConstructorOnInvalidLongitude() { + $this->expectExceptionMessage("The geographical longitude must be a value between -180 and 180 degrees. '-200' was given."); + $this->expectException(\InvalidArgumentException::class); + new Geo(25.632, -200); } diff --git a/tests/Eluceo/iCal/Property/Event/RecurrenceIdTest.php b/tests/Eluceo/iCal/Property/Event/RecurrenceIdTest.php index 0bf7721e..0483ab2b 100644 --- a/tests/Eluceo/iCal/Property/Event/RecurrenceIdTest.php +++ b/tests/Eluceo/iCal/Property/Event/RecurrenceIdTest.php @@ -8,7 +8,7 @@ class RecurrenceIdTest extends TestCase { public function testConstructorOnDateTime() { - $this->assertInstanceOf(RecurrenceId::class, new RecurrenceId(new \DateTime(null, new \DateTimeZone('Asia/Taipei')))); + $this->assertInstanceOf(RecurrenceId::class, new RecurrenceId(new \DateTime('now', new \DateTimeZone('Asia/Taipei')))); } public function testConstructorOnNullDateTime() @@ -21,7 +21,7 @@ public function testApplyTimeSettings() $recurrenceId = new RecurrenceId(); $recurrenceId->applyTimeSettings(); - $this->assertContains(date('Ymd'), $recurrenceId->getValue()->getValue()); + $this->assertStringContainsString(date('Ymd'), $recurrenceId->getValue()->getValue()); } public function testApplyTimeSettingsOnRange() @@ -30,7 +30,7 @@ public function testApplyTimeSettingsOnRange() $recurrenceId->setRange('RANGE=THISANDPRIOR:19980401T133000Z'); $recurrenceId->applyTimeSettings(); - $this->assertContains(date('Ymd'), $recurrenceId->getValue()->getValue()); + $this->assertStringContainsString(date('Ymd'), $recurrenceId->getValue()->getValue()); } public function testApplyTimeSettingsOnDefaultParams() @@ -38,13 +38,13 @@ public function testApplyTimeSettingsOnDefaultParams() $recurrenceId = new RecurrenceId(); $recurrenceId->applyTimeSettings(true, true, true, 'Europe/Berlin'); - $this->assertContains(date('Ymd'), $recurrenceId->getValue()->getValue()); + $this->assertStringContainsString(date('Ymd'), $recurrenceId->getValue()->getValue()); $this->assertSame(date('Ymd'), $recurrenceId->getValue()->getValue()); } public function testGetDatetime() { - $recurrenceId = new RecurrenceId(new \DateTime(null, new \DateTimeZone('Europe/Berlin'))); + $recurrenceId = new RecurrenceId(new \DateTime('now', new \DateTimeZone('Europe/Berlin'))); $this->assertInstanceOf(\DateTime::class, $recurrenceId->getDatetime()); $this->assertSame('Europe/Berlin', $recurrenceId->getDatetime()->getTimeZone()->getName()); @@ -53,7 +53,7 @@ public function testGetDatetime() public function testSetDatetime() { $recurrenceId = new RecurrenceId(); - $recurrenceId->setDatetime(new \DateTime(null, new \DateTimeZone('Asia/Taipei'))); + $recurrenceId->setDatetime(new \DateTime('now', new \DateTimeZone('Asia/Taipei'))); $this->assertInstanceOf(\DateTime::class, $recurrenceId->getDatetime()); $this->assertSame('Asia/Taipei', $recurrenceId->getDatetime()->getTimeZone()->getName()); @@ -82,12 +82,11 @@ public function testToLines() $this->assertSame(['RECURRENCE-ID:value1'], $recurrenceId->toLines()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The value must implement the ValueInterface. - */ public function testToLinesThrowsException() { + $this->expectExceptionMessage("The value must implement the ValueInterface."); + $this->expectException(\Exception::class); + $recurrenceId = new RecurrenceId(); $recurrenceId->toLines(); diff --git a/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php b/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php index 923aa8e8..ae9b7e14 100644 --- a/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php +++ b/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php @@ -60,12 +60,11 @@ public function testGetUntil() $this->assertSame('1997-12-24', $result->format('Y-m-d')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The Frequency invalid_freq_string is not supported. - */ public function testSetFreqOnInvalidFreq() { + $this->expectExceptionMessage("The Frequency invalid_freq_string is not supported."); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setFreq('invalid_freq_string'); } @@ -115,11 +114,12 @@ public function invalidMonthProvider() /** * @dataProvider invalidMonthProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYMONTH */ public function testSetByMonthOnInvalidMonth($month) { + $this->expectExceptionMessage("Invalid value for BYMONTH"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByMonth($month); } @@ -144,11 +144,12 @@ public function invalidByWeekNoProvider() /** * @dataProvider invalidByWeekNoProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYWEEKNO */ public function testSetByWeekNoOnInvalidByWeekNo($byWeekNo) { + $this->expectExceptionMessage("Invalid value for BYWEEKNO"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByWeekNo($byWeekNo); } @@ -173,11 +174,12 @@ public function invalidByYearDayProvider() /** * @dataProvider invalidByYearDayProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYYEARDAY */ public function testSetByYearDayOnInvalidByYeraDay($day) { + $this->expectExceptionMessage("Invalid value for BYYEARDAY"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByYearDay($day); } @@ -202,11 +204,12 @@ public function invalidByMonthDayProvider() /** * @dataProvider invalidByMonthDayProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYMONTHDAY */ public function testSetByMonthDayOnInvalidByMonthDay($day) { + $this->expectExceptionMessage("Invalid value for BYMONTHDAY"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByMonthDay($day); } @@ -230,11 +233,12 @@ public function invalidByHourProvider() /** * @dataProvider invalidByHourProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYHOUR */ public function testSetByHourOnInvalidByHour($value) { + $this->expectExceptionMessage("Invalid value for BYHOUR"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByHour($value); } @@ -258,11 +262,12 @@ public function invalidByMinuteProvider() /** * @dataProvider invalidByMinuteProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYMINUTE */ public function testSetByMinuteOnInvalidByMinute($value) { + $this->expectExceptionMessage("Invalid value for BYMINUTE"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setByMinute($value); } @@ -286,11 +291,12 @@ public function invalidBySecondProvider() /** * @dataProvider invalidBySecondProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for BYSECOND */ public function testSetBySecondOnInvalidBySecond($value) { + $this->expectExceptionMessage("Invalid value for BYSECOND"); + $this->expectException(\InvalidArgumentException::class); + $rule = new RecurrenceRule(); $rule->setBySecond($value); } diff --git a/tests/Eluceo/iCal/PropertyBagTest.php b/tests/Eluceo/iCal/PropertyBagTest.php index 7b868b4c..01a13029 100644 --- a/tests/Eluceo/iCal/PropertyBagTest.php +++ b/tests/Eluceo/iCal/PropertyBagTest.php @@ -6,12 +6,11 @@ class PropertyBagTest extends TestCase { - /** - * @expectedException \Exception - * @expectedExceptionMessage Property with name 'propName' already exists - */ public function testPropertyAlreadyExistsOnAddingProperty() { + $this->expectExceptionMessage("Property with name 'propName' already exists"); + $this->expectException(\Exception::class); + $propertyBag = new PropertyBag(); $propertyBag->add(new Property('propName', '')); $propertyBag->add(new Property('propName', '')); diff --git a/tests/Eluceo/iCal/PropertyTest.php b/tests/Eluceo/iCal/PropertyTest.php index b0e8762b..22ec314c 100644 --- a/tests/Eluceo/iCal/PropertyTest.php +++ b/tests/Eluceo/iCal/PropertyTest.php @@ -57,12 +57,11 @@ public function testSetValueOnArray() $this->assertSame('value1,value2', $property->getValue()->getEscapedValue()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The value must implement the ValueInterface. - */ public function testSetValueOnInvalidValue() { + $this->expectExceptionMessage("The value must implement the ValueInterface."); + $this->expectException(\Exception::class); + $property = new Property('DTSTAMP', '20131020T153112'); $property->setValue(new \DateTimeZone('Asia/Taipei')); } diff --git a/tests/Eluceo/iCal/Util/DateUtilTest.php b/tests/Eluceo/iCal/Util/DateUtilTest.php index edcd717d..93885cee 100644 --- a/tests/Eluceo/iCal/Util/DateUtilTest.php +++ b/tests/Eluceo/iCal/Util/DateUtilTest.php @@ -46,6 +46,6 @@ public function testGetDefaultParamsOnNoTime() public function testGetDefaultParamsOnUseTimezone() { - $this->assertSame(['TZID' => 'Asia/Taipei'], DateUtil::getDefaultParams(new \DateTime(null, new \DateTimeZone('Asia/Taipei')), false, true)); + $this->assertSame(['TZID' => 'Asia/Taipei'], DateUtil::getDefaultParams(new \DateTime('now', new \DateTimeZone('Asia/Taipei')), false, true)); } }