diff --git a/.gitattributes b/.gitattributes index f92bcd3..adfaba5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,3 +16,6 @@ # All test snapshots and text stubs must have CRLF line endings tests/**/__snapshots__/IcsGeneratorTest* text eol=crlf + +# PHPUnit +.phpunit.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 0588bd8..176a9ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to `calendar-links` will be documented in this file +## 1.8.2 - 2022-12-11 +### Changed + - ICS: Use `DESCRIPTION` instead of `X-ALT-DESC` (as it has better support) by @cdubz in #158 + - Chore: fix tests, fix and improve CI + +## 1.8.1 - 2022-12-01 +### Changed + - Remove PHP 7.4 support + - Update dependencies + ## 1.8.0 - 2022-08-20 ### Changed - ICS: Add `PRODID` and `DTSTAMP` required parameters to make ICS valid by @makbeta diff --git a/README.md b/README.md index aad0c8c..37067c7 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/calendar-links.svg?style=flat-square)](https://packagist.org/packages/spatie/calendar-links) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/calendar-links.svg?style=flat-square)](https://packagist.org/packages/spatie/calendar-links) -![Test](https://github.com/spatie/calendar-links/workflows/Test/badge.svg) +[![Test](https://github.com/spatie/calendar-links/workflows/Test/badge.svg)](https://github.com/spatie/calendar-links/actions/workflows/run-tests.yml) [![Quality Score](https://img.shields.io/scrutinizer/g/spatie/calendar-links.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/calendar-links) -![Type coverage](https://shepherd.dev/github/spatie/calendar-links/coverage.svg) -![Psalm level](https://shepherd.dev/github/spatie/calendar-links/level.svg) +[![Type coverage](https://shepherd.dev/github/spatie/calendar-links/coverage.svg)](https://shepherd.dev/github/spatie/calendar-links) +[![Psalm level](https://shepherd.dev/github/spatie/calendar-links/level.svg)](https://shepherd.dev/github/spatie/calendar-links) Using this package you can generate links to add events to calendar systems. Here's a quick example: diff --git a/composer.json b/composer.json index 64d1b62..c7390c5 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,10 @@ "php": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.13", - "phpunit/phpunit": "^9.5", - "spatie/phpunit-snapshot-assertions": "^4.2", - "vimeo/psalm": "^5.0" + "friendsofphp/php-cs-fixer": "^3.14", + "phpunit/phpunit": "^9.6 || ^10.0", + "spatie/phpunit-snapshot-assertions": "^4.2 || ^5.0", + "vimeo/psalm": "^5.6" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2b30133..93d19e0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,12 @@ - - + + src diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..793cfb5 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,36 @@ + + + + + setTimezone + setTimezone + + + + + setTimezone + setTimezone + + + + + setTimezone + setTimezone + + + + + $property + + + modify + + + clone $from + clone $to + + + new static($title, $from, $to, $allDay) + + + diff --git a/psalm.xml b/psalm.xml index f498de2..cb3e980 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,10 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - errorLevel="4" + errorLevel="2" findUnusedVariablesAndParams="true" resolveFromConfigFile="true" useDocblockPropertyTypes="true" + errorBaseline="psalm-baseline.xml" > diff --git a/src/Generators/Google.php b/src/Generators/Google.php index b1bf2a5..5ff4fe6 100644 --- a/src/Generators/Google.php +++ b/src/Generators/Google.php @@ -13,6 +13,7 @@ class Google implements Generator { /** @var string {@see https://www.php.net/manual/en/function.date.php} */ protected $dateFormat = 'Ymd'; + /** @var string */ protected $dateTimeFormat = 'Ymd\THis\Z'; /** {@inheritDoc} */ @@ -24,7 +25,7 @@ public function generate(Link $link): string $utcEndDateTime = (clone $link->to)->setTimezone(new DateTimeZone('UTC')); $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat; $url .= '&dates='.$utcStartDateTime->format($dateTimeFormat).'/'.$utcEndDateTime->format($dateTimeFormat); - + // Add timezone name if it is specified in both from and to dates and is the same for both if ( $link->from->getTimezone() && $link->to->getTimezone() diff --git a/src/Generators/Ics.php b/src/Generators/Ics.php index 54605fe..b3fb43f 100644 --- a/src/Generators/Ics.php +++ b/src/Generators/Ics.php @@ -41,13 +41,13 @@ public function generate(Link $link): string $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat; if ($link->allDay) { - $url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z'; - $url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z'; + $url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()); + $url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()); $url[] = 'DURATION:P'.(max(1, $link->from->diff($link->to)->days)).'D'; } else { - $url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z'; - $url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z'; - $url[] = 'DTEND:'.gmdate($dateTimeFormat, $link->to->getTimestamp()).'Z'; + $url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()); + $url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()); + $url[] = 'DTEND:'.gmdate($dateTimeFormat, $link->to->getTimestamp()); } if ($link->description) { diff --git a/src/Generators/Yahoo.php b/src/Generators/Yahoo.php index da3b77d..c6a18db 100644 --- a/src/Generators/Yahoo.php +++ b/src/Generators/Yahoo.php @@ -13,6 +13,7 @@ class Yahoo implements Generator { /** @var string {@see https://www.php.net/manual/en/function.date.php} */ protected $dateFormat = 'Ymd'; + /** @var string */ protected $dateTimeFormat = 'Ymd\THis\Z'; /** {@inheritDoc} */ diff --git a/tests/Generators/GeneratorTestContract.php b/tests/Generators/GeneratorTestContract.php index 3cd0e8b..69fdf1b 100644 --- a/tests/Generators/GeneratorTestContract.php +++ b/tests/Generators/GeneratorTestContract.php @@ -12,7 +12,7 @@ abstract protected function generator(): Generator; abstract protected function linkMethodName(): string; /** @test */ - public function it_can_generate_a_short_event_link() + public function it_can_generate_a_short_event_link(): void { $this->assertMatchesSnapshot( $this->generator()->generate($this->createShortEventLink()) @@ -25,7 +25,7 @@ public function it_can_generate_a_short_event_link() } /** @test */ - public function it_can_generate_a_single_day_allday_event_link() + public function it_can_generate_a_single_day_allday_event_link(): void { $this->assertMatchesSnapshot( $this->generator()->generate($this->createSingleDayAllDayEventLink()) @@ -38,7 +38,7 @@ public function it_can_generate_a_single_day_allday_event_link() } /** @test */ - public function it_can_generate_a_multiple_days_event_link() + public function it_can_generate_a_multiple_days_event_link(): void { $this->assertMatchesSnapshot( $this->generator()->generate($this->createMultipleDaysEventLink()) @@ -51,7 +51,7 @@ public function it_can_generate_a_multiple_days_event_link() } /** @test */ - public function it_can_generate_a_multiple_days_event_link_with_allday_flag() + public function it_can_generate_a_multiple_days_event_link_with_allday_flag(): void { $this->assertMatchesSnapshot( $this->generator()->generate($this->createMultipleDaysAllDayEventLink()) @@ -64,7 +64,7 @@ public function it_can_generate_a_multiple_days_event_link_with_allday_flag() } /** @test */ - public function it_can_generate_a_description_is_html_code_event_link_with_allday_flag() + public function it_can_generate_a_description_is_html_code_event_link_with_allday_flag(): void { $this->assertMatchesSnapshot( $this->generator()->generate($this->createDescriptionIsHTMLcodeEventLink()) diff --git a/tests/Generators/IcsGeneratorTest.php b/tests/Generators/IcsGeneratorTest.php index 3c9fb64..9c3b481 100644 --- a/tests/Generators/IcsGeneratorTest.php +++ b/tests/Generators/IcsGeneratorTest.php @@ -31,7 +31,7 @@ protected function linkMethodName(): string } /** @test */ - public function it_can_generate_an_ics_link_with_custom_uid() + public function it_can_generate_an_ics_link_with_custom_uid(): void { $this->assertMatchesSnapshot( $this->generator(['UID' => 'random-uid'])->generate($this->createShortEventLink()) @@ -39,7 +39,7 @@ public function it_can_generate_an_ics_link_with_custom_uid() } /** @test */ - public function it_has_a_product_id() + public function it_has_a_product_id(): void { $this->assertMatchesSnapshot( $this->generator(['PRODID' => 'Spatie calendar-links'])->generate($this->createShortEventLink()) @@ -47,7 +47,7 @@ public function it_has_a_product_id() } /** @test */ - public function it_has_a_product_dtstamp() + public function it_has_a_product_dtstamp(): void { $this->assertMatchesSnapshot( $this->generator(['DTSTAMP' => '20180201T090000Z'])->generate($this->createShortEventLink()) diff --git a/tests/Generators/YahooGeneratorTest.php b/tests/Generators/YahooGeneratorTest.php index 5b45e56..e77ac05 100644 --- a/tests/Generators/YahooGeneratorTest.php +++ b/tests/Generators/YahooGeneratorTest.php @@ -24,7 +24,7 @@ protected function linkMethodName(): string } /** @test */ - public function it_can_generate_a_yahoo_link_for_long_multiple_days_event() + public function it_can_generate_a_yahoo_link_for_long_multiple_days_event(): void { $link = Link::create( 'Christmas and New Year', diff --git a/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_multiple_days_event_link_with_allday_flag__1.txt b/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_multiple_days_event_link_with_allday_flag__1.txt index 2245885..72fcdfd 100644 --- a/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_multiple_days_event_link_with_allday_flag__1.txt +++ b/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_multiple_days_event_link_with_allday_flag__1.txt @@ -4,8 +4,8 @@ PRODID:Spatie calendar-links BEGIN:VEVENT UID:47e044bc36ced4538c62fc17c3ba087b SUMMARY:Birthday -DTSTAMP:20180201Z -DTSTART:20180201Z +DTSTAMP:20180201 +DTSTART:20180201 DURATION:P5D DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog LOCATION:Party Lane 1A\, 1337 Funtown diff --git a/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_single_day_allday_event_link__1.txt b/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_single_day_allday_event_link__1.txt index d4142ee..63f1831 100644 --- a/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_single_day_allday_event_link__1.txt +++ b/tests/Generators/__snapshots__/IcsGeneratorTest__it_can_generate_a_single_day_allday_event_link__1.txt @@ -4,8 +4,8 @@ PRODID:Spatie calendar-links BEGIN:VEVENT UID:aaf6b0d9a2c43d4a1c803a8c80793a08 SUMMARY:Birthday -DTSTAMP:20180201Z -DTSTART:20180201Z +DTSTAMP:20180201 +DTSTART:20180201 DURATION:P1D DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog LOCATION:Party Lane 1A\, 1337 Funtown diff --git a/tests/LinkTest.php b/tests/LinkTest.php index 11f6a86..70b14ad 100644 --- a/tests/LinkTest.php +++ b/tests/LinkTest.php @@ -9,13 +9,13 @@ class LinkTest extends TestCase { /** @test */ - public function it_is_initializable() + public function it_is_initializable(): void { $this->assertInstanceOf(Link::class, $this->createShortEventLink()); } /** @test */ - public function it_will_throw_an_exception_when_to_comes_after_from() + public function it_will_throw_an_exception_when_to_comes_after_from(): void { $this->expectException(InvalidLink::class); @@ -27,37 +27,37 @@ public function it_will_throw_an_exception_when_to_comes_after_from() } /** @test */ - public function it_has_a_title() + public function it_has_a_title(): void { $this->assertEquals('Birthday', $this->createShortEventLink()->title); } /** @test */ - public function it_has_a_mutable_from_date() + public function it_has_a_mutable_from_date(): void { $this->assertEquals(new DateTime('20180201T090000 UTC'), $this->createShortEventLink()->from); } /** @test */ - public function it_has_a_mutable_to_date() + public function it_has_a_mutable_to_date(): void { $this->assertEquals(new DateTime('20180201T180000 UTC'), $this->createShortEventLink()->to); } /** @test */ - public function it_has_an_immutable_from_date() + public function it_has_an_immutable_from_date(): void { $this->assertEquals(new DateTime('20180201T090000 UTC'), $this->createShortEventLink()->from); } /** @test */ - public function it_has_an_immutable_to_date() + public function it_has_an_immutable_to_date(): void { $this->assertEquals(new \DateTimeImmutable('20180201T180000 UTC'), $this->createShortEventLink()->to); } /** @test */ - public function it_can_have_a_description() + public function it_can_have_a_description(): void { $link = $this->createShortEventLink(); $correctDescription = 'With balloons, clowns and stuff @@ -66,7 +66,7 @@ public function it_can_have_a_description() } /** @test */ - public function it_can_have_an_address() + public function it_can_have_an_address(): void { $link = $this->createShortEventLink();