diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d794a0d3..00bae8f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1', '8.2'] + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] coverage: ['pcov'] code-analysis: ['no'] include: diff --git a/composer.json b/composer.json index c90c844f..0a3c1f7c 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "require-dev" : { "friendsofphp/php-cs-fixer": "^3.14", "phpunit/phpunit" : "^9.6", - "phpunit/php-invoker" : "^2.0 || ^3.1", + "phpunit/php-invoker" : "^3.1", "phpstan/phpstan": "^1.9" }, "suggest" : { @@ -91,7 +91,7 @@ }, "scripts": { "phpstan": [ - "phpstan analyse lib tests --memory-limit 1G" + "phpstan analyse lib tests --memory-limit 2G" ], "cs-fixer": [ "php-cs-fixer fix" diff --git a/lib/Component.php b/lib/Component.php index da2c5ebd..a3a1ec9d 100644 --- a/lib/Component.php +++ b/lib/Component.php @@ -2,7 +2,7 @@ namespace Sabre\VObject; -use Sabre\VObject; +use Sabre\VObject\Property\FlatText; use Sabre\Xml; /** @@ -15,21 +15,16 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\FlatText UID + * @property FlatText $UID */ class Component extends Node { - /** - * Component name. - * - * This will contain a string such as VEVENT, VTODO, VCALENDAR, VCARD. - */ - public string $name; - /** * A list of properties and/or sub-components. * - * @var array + * ToDo: maybe be more specific array|Property> + * + * @var array> */ protected array $children = []; @@ -44,7 +39,9 @@ class Component extends Node * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To * ensure that this does not happen, set $defaults to false. * - * @param string|null $name such as VCALENDAR, VEVENT + * @param Document $root + * @param string|null $name such as VCALENDAR, VEVENT + * @param array $children */ public function __construct(Document $root, ?string $name, array $children = [], bool $defaults = true) { @@ -54,7 +51,7 @@ public function __construct(Document $root, ?string $name, array $children = [], if ($defaults) { // This is a terribly convoluted way to do this, but this ensures // that the order of properties as they are specified in both - // defaults and the childrens list, are inserted in the object in a + // defaults and the children's list, are inserted in the object in a // natural way. $list = $this->getDefaults(); $nodes = []; @@ -97,6 +94,8 @@ public function __construct(Document $root, ?string $name, array $children = [], * add($name, $value, array $parameters = []) // Adds a new property * add($name, array $children = []) // Adds a new component * by name. + * + * @return Node */ public function add(): Node { @@ -114,7 +113,7 @@ public function add(): Node throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string'); } - /** @var Component|Property|Parameter $newNode */ + /** @var Component|Property|Parameter $newNode */ $name = $newNode->name; if (isset($this->children[$name])) { $this->children[$name][] = $newNode; @@ -133,7 +132,7 @@ public function add(): Node * pass an instance of a property or component, in which case only that * exact item will be removed. * - * @param string|Property|Component $item + * @param string|Property|Component $item */ public function remove($item): void { @@ -167,6 +166,8 @@ public function remove($item): void /** * Returns a flat list of all the properties and components in this * component. + * + * @return array|Property> */ public function children(): array { @@ -181,6 +182,8 @@ public function children(): array /** * This method only returns a list of sub-components. Properties are * ignored. + * + * @return array> */ public function getComponents(): array { @@ -206,6 +209,10 @@ public function getComponents(): array * search for a property in a specific group, you can select on the entire * string ("HOME.EMAIL"). If you want to search on a specific property that * has not been assigned a group, specify ".EMAIL". + * + * ToDo: something like (array & Component)|(array & Property) + * + * @return array */ public function select(string $name): array { @@ -271,7 +278,7 @@ public function serialize(): string * * @return int */ - $sortScore = function (int $key, array $array): ?int { + $sortScore = function (int $key, array $array): int { if ($array[$key] instanceof Component) { // We want to encode VTIMEZONE first, this is a personal // preference. @@ -322,6 +329,8 @@ function ($a, $b) use ($sortScore, $tmp): int { /** * This method returns an array, with the representation as it should be * encoded in JSON. This is used to create jCard or jCal documents. + * + * @return array{0: string, 1: array, 2: array} */ #[\ReturnTypeWillChange] public function jsonSerialize(): array @@ -394,6 +403,8 @@ public function xmlSerialize(Xml\Writer $writer): void /** * This method should return a list of default property values. + * + * @return array */ protected function getDefaults(): array { @@ -412,7 +423,7 @@ protected function getDefaults(): array * * $event = $calendar->VEVENT; * - * @return Property|Component + * @return Property|Component */ public function __get(string $name): ?Node { @@ -507,6 +518,8 @@ public function __clone() * * See the VEVENT implementation for getValidationRules for a more complex * example. + * + * @return array */ public function getValidationRules(): array { @@ -532,6 +545,8 @@ public function getValidationRules(): array * 1 - The issue was repaired (only happens if REPAIR was turned on). * 2 - A warning. * 3 - An error. + * + * @return array */ public function validate(int $options = 0): array { @@ -578,7 +593,7 @@ public function validate(int $options = 0): array } break; case '+': - if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] < 1) { + if (!isset($propertyCounters[$propName])) { $messages[] = [ 'level' => 3, 'message' => $propName.' MUST appear at least once in a '.$this->name.' component', diff --git a/lib/Component/Available.php b/lib/Component/Available.php index b3ba40b0..ecdb077b 100644 --- a/lib/Component/Available.php +++ b/lib/Component/Available.php @@ -14,9 +14,9 @@ * @author Ivan Enderlin * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART - * @property VObject\Property\ICalendar\DateTime DTEND - * @property VObject\Property\ICalendar\Duration DURATION + * @property VObject\Property\ICalendar\DateTime $DTSTART + * @property VObject\Property\ICalendar\DateTime $DTEND + * @property VObject\Property\ICalendar\Duration $DURATION */ class Available extends VObject\Component { diff --git a/lib/Component/VAlarm.php b/lib/Component/VAlarm.php index 3e5797b0..53d30963 100644 --- a/lib/Component/VAlarm.php +++ b/lib/Component/VAlarm.php @@ -14,11 +14,11 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART - * @property VObject\Property\ICalendar\DateTime DTEND - * @property VObject\Property\ICalendar\Duration DURATION - * @property VObject\Property\ICalendar\Duration|VObject\Property\ICalendar\DateTime TRIGGER - * @property VObject\Property\IntegerValue REPEAT + * @property VObject\Property\ICalendar\DateTime $DTSTART + * @property VObject\Property\ICalendar\DateTime $DTEND + * @property VObject\Property\ICalendar\Duration $DURATION + * @property VObject\Property\ICalendar\Duration|VObject\Property\ICalendar\DateTime $TRIGGER + * @property VObject\Property\IntegerValue $REPEAT */ class VAlarm extends VObject\Component { diff --git a/lib/Component/VAvailability.php b/lib/Component/VAvailability.php index ff6e9bd6..d40e0f00 100644 --- a/lib/Component/VAvailability.php +++ b/lib/Component/VAvailability.php @@ -14,9 +14,9 @@ * @author Ivan Enderlin * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART - * @property VObject\Property\ICalendar\DateTime DTEND - * @property VObject\Property\ICalendar\Duration DURATION + * @property VObject\Property\ICalendar\DateTime $DTSTART + * @property VObject\Property\ICalendar\DateTime $DTEND + * @property VObject\Property\ICalendar\Duration $DURATION */ class VAvailability extends VObject\Component { diff --git a/lib/Component/VCalendar.php b/lib/Component/VCalendar.php index b317e02c..fe718706 100644 --- a/lib/Component/VCalendar.php +++ b/lib/Component/VCalendar.php @@ -18,10 +18,10 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VEvent VEVENT - * @property VJournal VJOURNAL - * @property VObject\Property\Text ORG - * @property VObject\Property\FlatText METHOD + * @property VEvent $VEVENT + * @property VJournal $VJOURNAL + * @property VObject\Property\Text $ORG + * @property VObject\Property\FlatText $METHOD */ class VCalendar extends VObject\Document { diff --git a/lib/Component/VCard.php b/lib/Component/VCard.php index 2ace81e5..3664c346 100644 --- a/lib/Component/VCard.php +++ b/lib/Component/VCard.php @@ -15,9 +15,9 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\FlatText FN - * @property VObject\Property\Text ORG - * @property VObject\Property\FlatText EMAIL + * @property VObject\Property\FlatText $FN + * @property VObject\Property\Text $ORG + * @property VObject\Property\FlatText $EMAIL */ class VCard extends VObject\Document { @@ -272,17 +272,17 @@ public function validate(int $options = 0): array } $repaired = true; - // Otherwise, the ORG property may work + // Otherwise, the ORG property may work } elseif (isset($this->ORG)) { $this->FN = (string) $this->ORG; $repaired = true; - // Otherwise, the NICKNAME property may work + // Otherwise, the NICKNAME property may work } elseif (isset($this->NICKNAME)) { $this->FN = (string) $this->NICKNAME; $repaired = true; - // Otherwise, the EMAIL property may work + // Otherwise, the EMAIL property may work } elseif (isset($this->EMAIL)) { $this->FN = (string) $this->EMAIL; $repaired = true; diff --git a/lib/Component/VEvent.php b/lib/Component/VEvent.php index e29e5632..6be5a6d6 100644 --- a/lib/Component/VEvent.php +++ b/lib/Component/VEvent.php @@ -15,17 +15,18 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART - * @property VObject\Property\ICalendar\DateTime DTEND - * @property VObject\Property\ICalendar\DateTime DTSTAMP - * @property VObject\Property\ICalendar\Duration DURATION - * @property VObject\Property\ICalendar\Recur RRULE - * @property VObject\Property\ICalendar\DateTime[] EXDATE - * @property VObject\Property\ICalendar\DateTime RDATE - * @property VObject\Property\ICalendar\Recur EXRULE - * @property VObject\Property\ICalendar\DateTime RECURRENCE-ID - * @property VObject\Property\FlatText TRANSP - * @property VObject\Property\FlatText STATUS + * @property VObject\Property\ICalendar\DateTime $DTSTART + * @property VObject\Property\ICalendar\DateTime $DTEND + * @property VObject\Property\ICalendar\DateTime $DTSTAMP + * @property VObject\Property\ICalendar\Duration $DURATION + * @property VObject\Property\ICalendar\Recur $RRULE + * @property VObject\Property\ICalendar\DateTime[] $EXDATE + * @property VObject\Property\ICalendar\DateTime $RDATE + * @property VObject\Property\ICalendar\Recur $EXRULE + * @property VObject\Property\ICalendar\DateTime $RECURRENCE-ID + * @property VObject\Property\ICalendar\CalAddress $ATTENDEE + * @property VObject\Property\FlatText $TRANSP + * @property VObject\Property\FlatText $STATUS */ class VEvent extends VObject\Component { @@ -61,18 +62,26 @@ public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end return $it->getDTStart() < $end && $it->getDTEnd() > $start; } - $effectiveStart = $this->DTSTART->getDateTime($start->getTimezone()); + /** + * @var \Sabre\VObject\Property\ICalendar\DateTime $dateTimeStart + */ + $dateTimeStart = $this->DTSTART; + $effectiveStart = $dateTimeStart->getDateTime($start->getTimezone()); if (isset($this->DTEND)) { + /** + * @var \Sabre\VObject\Property\ICalendar\DateTime $dateTimeEnd + */ + $dateTimeEnd = $this->DTEND; // The DTEND property is considered non-inclusive. So for a 3-day // event in july, dtstart and dtend would have to be July 1st and // July 4th respectively. // // See: // http://tools.ietf.org/html/rfc5545#page-54 - $effectiveEnd = $this->DTEND->getDateTime($end->getTimezone()); + $effectiveEnd = $dateTimeEnd->getDateTime($end->getTimezone()); } elseif (isset($this->DURATION)) { $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); - } elseif (!$this->DTSTART->hasTime()) { + } elseif (!$dateTimeStart->hasTime()) { $effectiveEnd = $effectiveStart->modify('+1 day'); } else { $effectiveEnd = $effectiveStart; @@ -85,6 +94,8 @@ public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end /** * This method should return a list of default property values. + * + * @return array */ protected function getDefaults(): array { @@ -106,6 +117,8 @@ protected function getDefaults(): array * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. + * + * @return array */ public function getValidationRules(): array { diff --git a/lib/Component/VFreeBusy.php b/lib/Component/VFreeBusy.php index a9891c92..77e338e6 100644 --- a/lib/Component/VFreeBusy.php +++ b/lib/Component/VFreeBusy.php @@ -14,7 +14,7 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\Period FREEBUSY + * @property VObject\Property\ICalendar\Period $FREEBUSY */ class VFreeBusy extends VObject\Component { diff --git a/lib/Component/VJournal.php b/lib/Component/VJournal.php index 30e40adf..c7211454 100644 --- a/lib/Component/VJournal.php +++ b/lib/Component/VJournal.php @@ -13,7 +13,7 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime $DTSTART */ class VJournal extends VObject\Component { diff --git a/lib/Component/VTimeZone.php b/lib/Component/VTimeZone.php index 9dcf9b97..8c24e674 100644 --- a/lib/Component/VTimeZone.php +++ b/lib/Component/VTimeZone.php @@ -15,7 +15,7 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\FlatText TZID + * @property VObject\Property\FlatText $TZID */ class VTimeZone extends VObject\Component { diff --git a/lib/Component/VTodo.php b/lib/Component/VTodo.php index bda49da7..f6013505 100644 --- a/lib/Component/VTodo.php +++ b/lib/Component/VTodo.php @@ -13,18 +13,18 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\ICalendar\DateTime DTSTART - * @property VObject\Property\ICalendar\DateTime DTEND - * @property VObject\Property\ICalendar\DateTime DTSTAMP - * @property VObject\Property\ICalendar\Duration DURATION - * @property VObject\Property\ICalendar\Recur RRULE - * @property VObject\Property\ICalendar\DateTime EXDATE - * @property VObject\Property\ICalendar\DateTime RDATE - * @property VObject\Property\ICalendar\Recur EXRULE - * @property VObject\Property\ICalendar\DateTime {'RECURRENCE-ID'} - * @property VObject\Property\ICalendar\DateTime DUE - * @property VObject\Property\ICalendar\DateTime COMPLETED - * @property VObject\Property\ICalendar\DateTime CREATED + * @property VObject\Property\ICalendar\DateTime $DTSTART + * @property VObject\Property\ICalendar\DateTime $DTEND + * @property VObject\Property\ICalendar\DateTime $DTSTAMP + * @property VObject\Property\ICalendar\Duration $DURATION + * @property VObject\Property\ICalendar\Recur $RRULE + * @property VObject\Property\ICalendar\DateTime $EXDATE + * @property VObject\Property\ICalendar\DateTime $RDATE + * @property VObject\Property\ICalendar\Recur $EXRULE + * @property VObject\Property\ICalendar\DateTime $RECURRENCE-ID + * @property VObject\Property\ICalendar\DateTime $DUE + * @property VObject\Property\ICalendar\DateTime $COMPLETED + * @property VObject\Property\ICalendar\DateTime $CREATED */ class VTodo extends VObject\Component { diff --git a/lib/Document.php b/lib/Document.php index b311987d..d59dfa93 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -18,7 +18,7 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License * - * @property VObject\Property\FlatText VERSION + * @property VObject\Property\FlatText $VERSION */ abstract class Document extends Component { diff --git a/lib/Node.php b/lib/Node.php index 9ea14db9..d86c5b4b 100644 --- a/lib/Node.php +++ b/lib/Node.php @@ -11,6 +11,8 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ + +/** @implements \IteratorAggregate */ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable, Xml\XmlSerializable { /** @@ -54,6 +56,15 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \Js */ protected ?Component $root; + /** + * Name of the item (a Component or Parameter or Property). + * + * This will contain a component name such as VEVENT, VTODO, VCALENDAR, VCARD. + * Or a parameter name (vCard 2.1 allows parameters to be encoded without a name) + * Or a property name such as DTSTART, SUMMARY, FN. + */ + public ?string $name; + /** * Serializes the node into a mimedir format. */ @@ -92,8 +103,6 @@ public function destroy(): void /** * Returns the iterator for this object. - * - * @return ElementList */ #[\ReturnTypeWillChange] public function getIterator(): ?ElementList diff --git a/lib/PHPUnitAssertions.php b/lib/PHPUnitAssertions.php index 1976c3af..cc467268 100644 --- a/lib/PHPUnitAssertions.php +++ b/lib/PHPUnitAssertions.php @@ -31,7 +31,7 @@ trait PHPUnitAssertions * @param resource|string|Component $expected * @param resource|string|Component $actual */ - public function assertVObjectEqualsVObject($expected, $actual, string $message = ''): void + public static function assertVObjectEqualsVObject($expected, $actual, string $message = ''): void { $getObj = function ($input) { if (is_resource($input)) { @@ -41,7 +41,7 @@ public function assertVObjectEqualsVObject($expected, $actual, string $message = $input = Reader::read($input); } if (!$input instanceof Component) { - $this->fail('Input must be a string, stream or VObject component'); + self::fail('Input must be a string, stream or VObject component'); } unset($input->PRODID); if ($input instanceof Component\VCalendar && 'GREGORIAN' === (string) $input->CALSCALE) { @@ -65,7 +65,7 @@ public function assertVObjectEqualsVObject($expected, $actual, string $message = ); } - $this->assertEquals( + self::assertEquals( $expected, $actual, $message diff --git a/lib/Parameter.php b/lib/Parameter.php index 1900cb63..b636fa11 100644 --- a/lib/Parameter.php +++ b/lib/Parameter.php @@ -18,11 +18,6 @@ */ class Parameter extends Node { - /** - * Parameter name. - */ - public string $name; - /** * vCard 2.1 allows parameters to be encoded without a name. * @@ -160,7 +155,7 @@ public static function guessParameterNameByValue(string $value): string * * This may be either a single, or multiple strings in an array. * - * @param string|array $value + * @param int|string|array $value */ public function setValue($value): void { @@ -212,7 +207,7 @@ public function getParts(): array * If the argument is specified as an array, all items will be added to the * parameter value list. * - * @param string|array $part + * @param int|string|array $part */ public function addValue($part): void { diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php index 10bc3174..bbef0ea6 100644 --- a/lib/Parser/MimeDir.php +++ b/lib/Parser/MimeDir.php @@ -265,8 +265,6 @@ protected function parseLine(string $line) * * This method strips any newlines and also takes care of unfolding. * - * @return string - * * @throws EofException|ParseException */ protected function readLine(): ?string diff --git a/lib/Property.php b/lib/Property.php index 53a252fb..bd178fcc 100644 --- a/lib/Property.php +++ b/lib/Property.php @@ -21,13 +21,6 @@ abstract class Property extends Node */ public ?Component $root; - /** - * Property name. - * - * This will contain a string such as DTSTART, SUMMARY, FN. - */ - public ?string $name; - /** * Property group. * @@ -115,6 +108,8 @@ public function getValue() /** * Sets a multi-valued property. + * + * @param array $parts */ public function setParts(array $parts): void { diff --git a/lib/Property/ICalendar/DateTime.php b/lib/Property/ICalendar/DateTime.php index 7ee90797..571df54a 100644 --- a/lib/Property/ICalendar/DateTime.php +++ b/lib/Property/ICalendar/DateTime.php @@ -28,8 +28,6 @@ class DateTime extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string|null */ public string $delimiter = ','; @@ -38,6 +36,8 @@ class DateTime extends Property * * You may also specify DateTime objects here. * + * @param array $parts + * * @throws InvalidDataException */ public function setParts(array $parts): void diff --git a/lib/Property/VCard/DateAndOrTime.php b/lib/Property/VCard/DateAndOrTime.php index 9826bdbb..e87bf1b3 100644 --- a/lib/Property/VCard/DateAndOrTime.php +++ b/lib/Property/VCard/DateAndOrTime.php @@ -259,11 +259,11 @@ protected function xmlSerializeValue(Xml\Writer $writer): void $value .= '---'.$r('date'); } - // # 4.3.2 - // value-time = element time { - // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" - // ~ "(Z|[+\-]\d\d(\d\d)?)?" } - // } + // # 4.3.2 + // value-time = element time { + // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" + // ~ "(Z|[+\-]\d\d(\d\d)?)?" } + // } } elseif ((!$d('year') && !$d('month') && !$d('date')) && ($d('hour') || $d('minute') || $d('second'))) { if ($d('hour')) { @@ -276,11 +276,11 @@ protected function xmlSerializeValue(Xml\Writer $writer): void $value .= $r('timezone'); - // # 4.3.3 - // value-date-time = element date-time { - // xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?" - // ~ "(Z|[+\-]\d\d(\d\d)?)?" } - // } + // # 4.3.3 + // value-date-time = element date-time { + // xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?" + // ~ "(Z|[+\-]\d\d(\d\d)?)?" } + // } } elseif ($d('date') && $d('hour')) { if ($d('year') && $d('month') && $d('date')) { $value .= $r('year').$r('month').$r('date'); diff --git a/lib/Recur/EventIterator.php b/lib/Recur/EventIterator.php index c08331f2..d79cf313 100644 --- a/lib/Recur/EventIterator.php +++ b/lib/Recur/EventIterator.php @@ -191,8 +191,6 @@ public function __construct($input, string $uid = null, \DateTimeZone $timeZone /** * Returns the date for the current position of the iterator. - * - * @return \DateTimeImmutable */ #[\ReturnTypeWillChange] public function current(): ?\DateTimeImmutable @@ -207,8 +205,6 @@ public function current(): ?\DateTimeImmutable /** * This method returns the start date for the current iteration of the * event. - * - * @return \DateTimeImmutable */ public function getDtStart(): ?\DateTimeImmutable { @@ -223,8 +219,6 @@ public function getDtStart(): ?\DateTimeImmutable * This method returns the end date for the current iteration of the * event. * - * @return \DateTimeImmutable - * * @throws MaxInstancesExceededException|InvalidDataException */ public function getDtEnd(): ?\DateTimeImmutable diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index 888556ee..78051c48 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -33,7 +33,7 @@ class RRuleIterator implements \Iterator /** * Creates the Iterator. * - * @param string|array $rrule + * @param string|array $rrule * * @throws InvalidDataException */ @@ -675,7 +675,7 @@ protected function nextYearly(): void * This method receives a string from an RRULE property, and populates this * class with all the values. * - * @param string|array $rrule + * @param string|array $rrule * * @throws InvalidDataException */ diff --git a/lib/Splitter/ICalendar.php b/lib/Splitter/ICalendar.php index ccf0d1ad..c3fca30a 100644 --- a/lib/Splitter/ICalendar.php +++ b/lib/Splitter/ICalendar.php @@ -25,11 +25,13 @@ class ICalendar implements SplitterInterface /** * Timezones. */ + /** @var array */ protected array $vtimezones = []; /** * iCalendar objects. */ + /** @var array */ protected array $objects = []; /** diff --git a/lib/VCardConverter.php b/lib/VCardConverter.php index 88d74602..bbcf519c 100644 --- a/lib/VCardConverter.php +++ b/lib/VCardConverter.php @@ -2,6 +2,7 @@ namespace Sabre\VObject; +use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Binary; use Sabre\VObject\Property\Uri; @@ -29,6 +30,10 @@ class VCardConverter * * If input and output version are identical, a clone is returned. * + * @param VCard $input + * + * @return VCard + * * @throws InvalidDataException */ public function convert(Component\VCard $input, int $targetVersion): Component\VCard @@ -64,6 +69,10 @@ public function convert(Component\VCard $input, int $targetVersion): Component\V /** * Handles conversion of a single property. * + * @param VCard $input + * @param VCard $output + * @param Property $property + * * @throws InvalidDataException */ protected function convertProperty(Component\VCard $input, Component\VCard $output, Property $property, int $targetVersion): void @@ -94,8 +103,11 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp if (Document::VCARD30 === $targetVersion) { if ($property instanceof Property\Uri && in_array($property->name, ['PHOTO', 'LOGO', 'SOUND'])) { - /** @var Property\Uri $newProperty */ - $newProperty = $this->convertUriToBinary($output, $newProperty); + /* We need to tell phpstan that newProperty (as well as property) is instanceof Property\Uri */ + /** @var Property\Uri $uriProperty */ + $uriProperty = $newProperty; + /** @var Property\Uri $newProperty */ + $newProperty = $this->convertUriToBinary($output, $uriProperty); } elseif ($property instanceof Property\VCard\DateAndOrTime) { // In vCard 4, the birth year may be optional. This is not the // case for vCard 3. Apple has a workaround for this that @@ -154,12 +166,16 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp } if ($property instanceof Property\Binary) { - /** @var Property\Binary $newProperty */ - $newProperty = $this->convertBinaryToUri($output, $newProperty, $parameters); + /* We need to tell phpstan that newProperty (as well as property) is instanceof Property\Uri */ + /** @var Property\Binary $binaryProperty */ + $binaryProperty = $newProperty; + /** @var Property\Binary $newProperty */ + $newProperty = $this->convertBinaryToUri($output, $binaryProperty, $parameters); } elseif ($property instanceof Property\VCard\DateAndOrTime && isset($parameters['X-APPLE-OMIT-YEAR'])) { // If a property such as BDAY contained 'X-APPLE-OMIT-YEAR', // then we're stripping the year from the vcard 4 value. $parts = DateTimeParser::parseVCardDateTime($property->getValue()); + /* @phpstan-ignore-next-line 'Call to an undefined method Sabre\VObject\Node::getValue().' */ if ($parts['year'] === $property['X-APPLE-OMIT-YEAR']->getValue()) { $newValue = '--'.$parts['month'].'-'.$parts['date']; $newProperty->setValue($newValue); @@ -251,15 +267,19 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp * * vCard 4.0 no longer supports BINARY properties. * - * @param array $parameters list of parameters that will eventually be added to - * the new property + * @param Component\VCard $output + * @param Property\Binary $newProperty + * @param array $parameters list of parameters that will eventually be added to + * the new property + * + * @return Uri * * @throws InvalidDataException */ protected function convertBinaryToUri(Component\VCard $output, Property\Binary $newProperty, array &$parameters): Uri { $value = $newProperty->getValue(); - /** @var Uri $newProperty */ + /** @var Uri $newProperty */ $newProperty = $output->createProperty( $newProperty->name, null, // no value @@ -304,7 +324,10 @@ protected function convertBinaryToUri(Component\VCard $output, Property\Binary $ * be valid in vCard 3.0 as well, we should convert those to BINARY if * possible, to improve compatibility. * - * @return Property\Binary|Property\Uri|null + * @param Component\VCard $output + * @param Property\Uri $newProperty + * + * @return Property\Binary|Property\Uri * * @throws InvalidDataException */ @@ -317,7 +340,7 @@ protected function convertUriToBinary(Component\VCard $output, Property\Uri $new return $newProperty; } - /** @var Binary $newProperty */ + /** @var Binary $newProperty */ $newProperty = $output->createProperty( $newProperty->name, null, // no value @@ -352,6 +375,9 @@ protected function convertUriToBinary(Component\VCard $output, Property\Uri $new /** * Adds parameters to a new property for vCard 4.0. + * + * @param Property $newProperty + * @param array $parameters */ protected function convertParameters40(Property $newProperty, array $parameters): void { @@ -388,6 +414,9 @@ protected function convertParameters40(Property $newProperty, array $parameters) /** * Adds parameters to a new property for vCard 3.0. + * + * @param Property $newProperty + * @param array $parameters */ protected function convertParameters30(Property $newProperty, array $parameters): void { diff --git a/lib/Writer.php b/lib/Writer.php index 504e38a7..4deede59 100644 --- a/lib/Writer.php +++ b/lib/Writer.php @@ -18,6 +18,8 @@ class Writer { /** * Serializes a vCard or iCalendar object. + * + * @param Component $component */ public static function write(Component $component): string { @@ -26,6 +28,8 @@ public static function write(Component $component): string /** * Serializes a jCal or jCard object. + * + * @param Component $component */ public static function writeJson(Component $component, int $options = 0): string { @@ -34,6 +38,8 @@ public static function writeJson(Component $component, int $options = 0): string /** * Serializes a xCal or xCard object. + * + * @param Component $component */ public static function writeXml(Component $component): string { diff --git a/phpstan.neon b/phpstan.neon index c705178c..2b3fd492 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ parameters: - level: 1 + level: 6 + phpVersion: 70430 # PHP 7.4.30 universalObjectCratesClasses: - \Sabre\VObject\Component diff --git a/tests/VObject/Component/AvailableTest.php b/tests/VObject/Component/AvailableTest.php index 98202ffc..c2ce0476 100644 --- a/tests/VObject/Component/AvailableTest.php +++ b/tests/VObject/Component/AvailableTest.php @@ -34,14 +34,19 @@ public function testGetEffectiveStartEnd(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); $tz = new \DateTimeZone('UTC'); + /** + * @var Available $available + */ + $available = $document->AVAILABLE; self::assertEquals( [ new \DateTimeImmutable('2015-07-17 16:22:00', $tz), new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], - $document->AVAILABLE->getEffectiveStartEnd() + $available->getEffectiveStartEnd() ); } @@ -56,14 +61,19 @@ public function testGetEffectiveStartEndDuration(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); $tz = new \DateTimeZone('UTC'); + /** + * @var Available $available + */ + $available = $document->AVAILABLE; self::assertEquals( [ new \DateTimeImmutable('2015-07-17 16:22:00', $tz), new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], - $document->AVAILABLE->getEffectiveStartEnd() + $available->getEffectiveStartEnd() ); } } diff --git a/tests/VObject/Component/VAlarmTest.php b/tests/VObject/Component/VAlarmTest.php index 4694d636..7b098f37 100644 --- a/tests/VObject/Component/VAlarmTest.php +++ b/tests/VObject/Component/VAlarmTest.php @@ -4,11 +4,15 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\InvalidDataException; +use Sabre\VObject\Property\IntegerValue; use Sabre\VObject\Reader; +use Sabre\VObject\TestHelper; class VAlarmTest extends TestCase { /** + * @param VAlarm $valarm + * * @dataProvider timeRangeTestData */ public function testInTimeRange(VAlarm $valarm, \DateTime $start, \DateTime $end, bool $outcome): void @@ -16,6 +20,9 @@ public function testInTimeRange(VAlarm $valarm, \DateTime $start, \DateTime $end self::assertEquals($outcome, $valarm->isInTimeRange($start, $end)); } + /** + * @return array> + */ public function timeRangeTestData(): array { $tests = []; @@ -37,8 +44,9 @@ public function timeRangeTestData(): array $calendar->createProperty('TRIGGER', '-P1D', ['VALUE' => 'DURATION']) ); + /** @var VEvent $vevent2 */ $vevent2 = $calendar->createComponent('VEVENT'); - $vevent2->DTSTART = '20120313T130000Z'; + $vevent2->DTSTART = TestHelper::createDtStart($calendar, '20120313T130000Z'); $vevent2->add($valarm2); $tests[] = [$valarm2, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true]; @@ -48,76 +56,90 @@ public function timeRangeTestData(): array $valarm3 = $calendar->createComponent('VALARM'); $valarm3->add($calendar->createProperty('TRIGGER', '-P1D', ['VALUE' => 'DURATION', 'RELATED' => 'END'])); + /** @var VEvent $vevent3 */ $vevent3 = $calendar->createComponent('VEVENT'); - $vevent3->DTSTART = '20120301T130000Z'; - $vevent3->DTEND = '20120401T130000Z'; + $vevent3->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z'); + $vevent3->DTEND = TestHelper::createDtEnd($calendar, '20120401T130000Z'); $vevent3->add($valarm3); $tests[] = [$valarm3, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; $tests[] = [$valarm3, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to end time of todo + /** @var VAlarm $valarm4 */ $valarm4 = $calendar->createComponent('VALARM'); - $valarm4->TRIGGER = '-P1D'; + $valarm4->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm4->TRIGGER['VALUE'] = 'DURATION'; $valarm4->TRIGGER['RELATED'] = 'END'; + /** @var VTodo $vtodo4 */ $vtodo4 = $calendar->createComponent('VTODO'); - $vtodo4->DTSTART = '20120301T130000Z'; - $vtodo4->DUE = '20120401T130000Z'; + $vtodo4->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z'); + $vtodo4->DUE = TestHelper::createDateDue($calendar, '20120401T130000Z'); $vtodo4->add($valarm4); $tests[] = [$valarm4, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; $tests[] = [$valarm4, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to start time of event + repeat + /** @var VAlarm $valarm5 */ $valarm5 = $calendar->createComponent('VALARM'); - $valarm5->TRIGGER = '-P1D'; + $valarm5->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm5->TRIGGER['VALUE'] = 'DURATION'; - $valarm5->REPEAT = 10; - $valarm5->DURATION = 'P1D'; + /** @var IntegerValue $property */ + $property = $calendar->createProperty('REPEAT'); + $property->setValue([10]); + $valarm5->REPEAT = $property; + $valarm5->DURATION = TestHelper::createDuration($calendar, 'P1D'); + /** @var VEvent $vevent5 */ $vevent5 = $calendar->createComponent('VEVENT'); - $vevent5->DTSTART = '20120301T130000Z'; + $vevent5->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z'); $vevent5->add($valarm5); $tests[] = [$valarm5, new \DateTime('2012-03-09 01:00:00'), new \DateTime('2012-03-10 01:00:00'), true]; // Relation to start time of event + duration, but no repeat + /** @var VAlarm $valarm6 */ $valarm6 = $calendar->createComponent('VALARM'); - $valarm6->TRIGGER = '-P1D'; + $valarm6->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm6->TRIGGER['VALUE'] = 'DURATION'; - $valarm6->DURATION = 'P1D'; + $valarm6->DURATION = TestHelper::createDuration($calendar, 'P1D'); + /** @var VEvent $vevent6 */ $vevent6 = $calendar->createComponent('VEVENT'); - $vevent6->DTSTART = '20120313T130000Z'; + $vevent6->DTSTART = TestHelper::createDtStart($calendar, '20120313T130000Z'); $vevent6->add($valarm6); $tests[] = [$valarm6, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true]; $tests[] = [$valarm6, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-03-10 01:00:00'), false]; // Relation to end time of event (DURATION instead of DTEND) + /** @var VAlarm $valarm7 */ $valarm7 = $calendar->createComponent('VALARM'); - $valarm7->TRIGGER = '-P1D'; + $valarm7->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm7->TRIGGER['VALUE'] = 'DURATION'; $valarm7->TRIGGER['RELATED'] = 'END'; + /** @var VEvent $vevent7 */ $vevent7 = $calendar->createComponent('VEVENT'); - $vevent7->DTSTART = '20120301T130000Z'; - $vevent7->DURATION = 'P30D'; + $vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z'); + $vevent7->DURATION = TestHelper::createDuration($calendar, 'P30D'); $vevent7->add($valarm7); $tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; $tests[] = [$valarm7, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to end time of event (No DTEND or DURATION) + /** @var VAlarm $valarm7 */ $valarm7 = $calendar->createComponent('VALARM'); - $valarm7->TRIGGER = '-P1D'; + $valarm7->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm7->TRIGGER['VALUE'] = 'DURATION'; $valarm7->TRIGGER['RELATED'] = 'END'; + /** @var VEvent $vevent7 */ $vevent7 = $calendar->createComponent('VEVENT'); - $vevent7->DTSTART = '20120301T130000Z'; + $vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z'); $vevent7->add($valarm7); $tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), true]; @@ -130,8 +152,9 @@ public function testInTimeRangeInvalidComponent(): void { $this->expectException(InvalidDataException::class); $calendar = new VCalendar(); + /** @var VAlarm $valarm */ $valarm = $calendar->createComponent('VALARM'); - $valarm->TRIGGER = '-P1D'; + $valarm->TRIGGER = TestHelper::createTrigger($calendar, '-P1D'); $valarm->TRIGGER['RELATED'] = 'END'; $vjournal = $calendar->createComponent('VJOURNAL'); @@ -163,8 +186,13 @@ public function testInTimeRangeBuggy(): void END:VCALENDAR BLA; + /** @var VCalendar $vobj */ $vobj = Reader::read($input); + /** @var VTodo $vTodo */ + $vTodo = $vobj->VTODO; + /** @var VAlarm $vAlarm */ + $vAlarm = $vTodo->VALARM; - self::assertTrue($vobj->VTODO->VALARM->isInTimeRange(new \DateTime('2012-10-01 00:00:00'), new \DateTime('2012-11-01 00:00:00'))); + self::assertTrue($vAlarm->isInTimeRange(new \DateTime('2012-10-01 00:00:00'), new \DateTime('2012-11-01 00:00:00'))); } } diff --git a/tests/VObject/Component/VAvailabilityTest.php b/tests/VObject/Component/VAvailabilityTest.php index 263eeebd..b24492ab 100644 --- a/tests/VObject/Component/VAvailabilityTest.php +++ b/tests/VObject/Component/VAvailabilityTest.php @@ -36,14 +36,19 @@ public function testGetEffectiveStartEnd(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); $tz = new \DateTimeZone('UTC'); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; self::assertEquals( [ new \DateTimeImmutable('2015-07-17 16:22:00', $tz), new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], - $document->VAVAILABILITY->getEffectiveStartEnd() + $availability->getEffectiveStartEnd() ); } @@ -58,14 +63,19 @@ public function testGetEffectiveStartDuration(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); $tz = new \DateTimeZone('UTC'); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; self::assertEquals( [ new \DateTimeImmutable('2015-07-17 16:22:00', $tz), new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], - $document->VAVAILABILITY->getEffectiveStartEnd() + $availability->getEffectiveStartEnd() ); } @@ -78,13 +88,18 @@ public function testGetEffectiveStartEndUnbound(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; self::assertEquals( [ null, null, ], - $document->VAVAILABILITY->getEffectiveStartEnd() + $availability->getEffectiveStartEnd() ); } @@ -97,9 +112,14 @@ public function testIsInTimeRangeUnbound(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; self::assertTrue( - $document->VAVAILABILITY->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) + $availability->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) ); } @@ -114,9 +134,14 @@ public function testIsInTimeRangeOutside(): void END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; self::assertFalse( - $document->VAVAILABILITY->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) + $availability->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) ); } @@ -232,9 +257,14 @@ public function testAvailableSubComponent(): void END:VAVAILABILITY END:VCALENDAR VCAL; + /** @var VCalendar $document */ $document = Reader::read($vcal); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; - self::assertInstanceOf(Available::class, $document->VAVAILABILITY->AVAILABLE); + self::assertInstanceOf(Available::class, $availability->AVAILABLE); } public function testRFCxxxSection3Part1AvailablePropRequired(): void @@ -373,56 +403,77 @@ public function testRFCxxxSection3Part1AvailableOptionalOnce(): void public function testRFCxxxSection3Part2(): void { + /** @var VCalendar $document */ + $document = Reader::read($this->templateAvailable(['BUSYTYPE:BUSY'])); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; + /** + * @var Available $available + */ + $available = $availability->AVAILABLE; self::assertEquals( 'BUSY', - Reader::read($this->templateAvailable([ - 'BUSYTYPE:BUSY', - ])) - ->VAVAILABILITY - ->AVAILABLE - ->BUSYTYPE - ->getValue() + $available->BUSYTYPE->getValue() ); + /** @var VCalendar $document */ + $document = Reader::read($this->templateAvailable(['BUSYTYPE:BUSY-UNAVAILABLE'])); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; + /** + * @var Available $available + */ + $available = $availability->AVAILABLE; self::assertEquals( 'BUSY-UNAVAILABLE', - Reader::read($this->templateAvailable([ - 'BUSYTYPE:BUSY-UNAVAILABLE', - ])) - ->VAVAILABILITY - ->AVAILABLE - ->BUSYTYPE - ->getValue() + $available->BUSYTYPE->getValue() ); + /** @var VCalendar $document */ + $document = Reader::read($this->templateAvailable(['BUSYTYPE:BUSY-TENTATIVE'])); + /** + * @var VAvailability $availability + */ + $availability = $document->VAVAILABILITY; + /** + * @var Available $available + */ + $available = $availability->AVAILABLE; self::assertEquals( 'BUSY-TENTATIVE', - Reader::read($this->templateAvailable([ - 'BUSYTYPE:BUSY-TENTATIVE', - ])) - ->VAVAILABILITY - ->AVAILABLE - ->BUSYTYPE - ->getValue() + $available->BUSYTYPE->getValue() ); } - protected function assertIsValid(VObject\Document $document): void + /** + * @param VObject\Document $document + */ + protected static function assertIsValid(VObject\Document $document): void { $validationResult = $document->validate(); if ($validationResult) { $messages = array_map(function ($item) { return $item['message']; }, $validationResult); - $this->fail('Failed to assert that the supplied document is a valid document. Validation messages: '.implode(', ', $messages)); + self::fail('Failed to assert that the supplied document is a valid document. Validation messages: '.implode(', ', $messages)); } self::assertEmpty($document->validate()); } - protected function assertIsNotValid(VObject\Document $document): void + /** + * @param VObject\Document $document + */ + protected static function assertIsNotValid(VObject\Document $document): void { self::assertNotEmpty($document->validate()); } - protected function template(array $properties) + /** + * @param array $properties + */ + protected function template(array $properties): string { return $this->_template( << $properties + */ + protected function templateAvailable(array $properties): string { return $this->_template( << $properties + */ + protected function _template(string $template, array $properties): string { return str_replace('…', implode("\r\n", $properties), $template); } diff --git a/tests/VObject/Component/VCalendarTest.php b/tests/VObject/Component/VCalendarTest.php index 1893a9ac..7d8b0324 100644 --- a/tests/VObject/Component/VCalendarTest.php +++ b/tests/VObject/Component/VCalendarTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject; use Sabre\VObject\InvalidDataException; +use Sabre\VObject\Property\FlatText; class VCalendarTest extends TestCase { @@ -15,6 +16,7 @@ class VCalendarTest extends TestCase */ public function testExpand(string $input, string $output, string $timeZone = 'UTC', string $start = '2011-12-01', string $end = '2011-12-31'): void { + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); $timeZone = new \DateTimeZone($timeZone); @@ -31,6 +33,9 @@ public function testExpand(string $input, string $output, string $timeZone = 'UT self::assertVObjectEqualsVObject($output, $vcal->serialize()); } + /** + * @return array> + */ public function expandData(): array { $tests = []; @@ -342,6 +347,7 @@ public function testBrokenEventExpand(): void END:VEVENT END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); $vcal->expand( new \DateTime('2011-12-01'), @@ -367,6 +373,7 @@ public function testEventExpandYearly(): void END:VEVENT END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); $events = $vcal->expand( new \DateTime('2021-01-01'), @@ -379,7 +386,10 @@ public function testEventExpandYearly(): void public function testGetDocumentType(): void { $vcard = new VCalendar(); - $vcard->VERSION = '2.0'; + /** @var FlatText $property */ + $property = $vcard->createProperty('VERSION'); + $property->setValue('2.0'); + $vcard->VERSION = $property; self::assertEquals(VCalendar::ICALENDAR20, $vcard->getDocumentType()); } @@ -559,8 +569,10 @@ public function testGetBaseComponent(): void END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); + /** @var VEvent $result */ $result = $vcal->getBaseComponent(); self::assertEquals('test', $result->SUMMARY->getValue()); } @@ -587,6 +599,7 @@ public function testGetBaseComponentNoResult(): void END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); $result = $vcal->getBaseComponent(); @@ -614,8 +627,10 @@ public function testGetBaseComponentWithFilter(): void END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); + /** @var VEvent $result */ $result = $vcal->getBaseComponent('VEVENT'); self::assertEquals('test', $result->SUMMARY->getValue()); } @@ -634,8 +649,10 @@ public function testGetBaseComponentWithFilterNoResult(): void END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = VObject\Reader::read($input); + /** @var VEvent $result */ $result = $vcal->getBaseComponent('VEVENT'); self::assertNull($result); } @@ -756,7 +773,7 @@ public function testCalDAVMETHOD(): void ); } - public function assertValidate($ics, $options, $expectedLevel, string $expectedMessage = null): void + public static function assertValidate(string $ics, int $options, int $expectedLevel, string $expectedMessage = null): void { $vcal = VObject\Reader::read($ics); $result = $vcal->validate($options); @@ -764,7 +781,10 @@ public function assertValidate($ics, $options, $expectedLevel, string $expectedM self::assertValidateResult($result, $expectedLevel, $expectedMessage); } - public function assertValidateResult($input, $expectedLevel, string $expectedMessage = null): void + /** + * @param array> $input + */ + public static function assertValidateResult(array $input, int $expectedLevel, string $expectedMessage = null): void { $messages = []; foreach ($input as $warning) { diff --git a/tests/VObject/Component/VCardTest.php b/tests/VObject/Component/VCardTest.php index b71b3085..de00fded 100644 --- a/tests/VObject/Component/VCardTest.php +++ b/tests/VObject/Component/VCardTest.php @@ -4,10 +4,13 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject; +use Sabre\VObject\Property\FlatText; class VCardTest extends TestCase { /** + * @param array $expectedWarnings + * * @dataProvider validateData */ public function testValidate(string $input, array $expectedWarnings, string $expectedRepairedOutput): void @@ -31,6 +34,9 @@ public function testValidate(string $input, array $expectedWarnings, string $exp ); } + /** + * @return array> + */ public function validateData(): array { $tests = []; @@ -115,15 +121,24 @@ public function validateData(): array public function testGetDocumentType(): void { $vcard = new VCard([], false); - $vcard->VERSION = '2.1'; + /** @var FlatText $property2 */ + $property2 = $vcard->createProperty('VERSION'); + $property2->setValue('2.1'); + $vcard->VERSION = $property2; self::assertEquals(VCard::VCARD21, $vcard->getDocumentType()); $vcard = new VCard([], false); - $vcard->VERSION = '3.0'; + /** @var FlatText $property3 */ + $property3 = $vcard->createProperty('VERSION'); + $property3->setValue('3.0'); + $vcard->VERSION = $property3; self::assertEquals(VCard::VCARD30, $vcard->getDocumentType()); $vcard = new VCard([], false); - $vcard->VERSION = '4.0'; + /** @var FlatText $property4 */ + $property4 = $vcard->createProperty('VERSION'); + $property4->setValue('4.0'); + $vcard->VERSION = $property4; self::assertEquals(VCard::VCARD40, $vcard->getDocumentType()); $vcard = new VCard([], false); @@ -132,7 +147,7 @@ public function testGetDocumentType(): void public function testGetByType(): void { - $vcard = <<getByType('EMAIL', 'home')->getValue()); - self::assertEquals('2@example.org', $vcard->getByType('EMAIL', 'work')->getValue()); + /** @var VCard $vcard */ + $vcard = VObject\Reader::read($vcardText); + /** + * @var VObject\Property $homeEmail + */ + $homeEmail = $vcard->getByType('EMAIL', 'home'); + /** + * @var VObject\Property $workEmail + */ + $workEmail = $vcard->getByType('EMAIL', 'work'); + self::assertEquals('1@example.org', $homeEmail->getValue()); + self::assertEquals('2@example.org', $workEmail->getValue()); self::assertNull($vcard->getByType('EMAIL', 'non-existent')); self::assertNull($vcard->getByType('ADR', 'non-existent')); } public function testPreferredNoPref(): void { - $vcard = << $vcard */ + $vcard = VObject\Reader::read($vcardText); self::assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue()); } public function testPreferredWithPref(): void { - $vcard = << $vcard */ + $vcard = VObject\Reader::read($vcardText); self::assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue()); } public function testPreferredWith40Pref(): void { - $vcard = << $vcard */ + $vcard = VObject\Reader::read($vcardText); self::assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue()); } public function testPreferredNotFound(): void { - $vcard = << $vcard */ + $vcard = VObject\Reader::read($vcardText); self::assertNull($vcard->preferred('EMAIL')); } @@ -269,7 +297,7 @@ public function testVCard21CardDAV(): void public function testVCard21NoCardDAV(): void { - $vcard = <<validate($options); @@ -291,7 +319,10 @@ public function assertValidate($vcf, $options, int $expectedLevel, string $expec self::assertValidateResult($result, $expectedLevel, $expectedMessage); } - public function assertValidateResult($input, int $expectedLevel, string $expectedMessage = null): void + /** + * @param array> $input + */ + public static function assertValidateResult(array $input, int $expectedLevel, string $expectedMessage = null): void { $messages = []; foreach ($input as $warning) { diff --git a/tests/VObject/Component/VEventTest.php b/tests/VObject/Component/VEventTest.php index 50fa626c..ee37c63f 100644 --- a/tests/VObject/Component/VEventTest.php +++ b/tests/VObject/Component/VEventTest.php @@ -3,10 +3,13 @@ namespace Sabre\VObject\Component; use PHPUnit\Framework\TestCase; +use Sabre\VObject\TestHelper; class VEventTest extends TestCase { /** + * @param VEvent $vevent + * * @dataProvider timeRangeTestData */ public function testInTimeRange(VEvent $vevent, \DateTime $start, \DateTime $end, bool $outcome): void @@ -14,29 +17,33 @@ public function testInTimeRange(VEvent $vevent, \DateTime $start, \DateTime $end self::assertEquals($outcome, $vevent->isInTimeRange($start, $end)); } + /** + * @return array> + */ public function timeRangeTestData(): array { $tests = []; $calendar = new VCalendar(); + /** @var VEvent $vevent */ $vevent = $calendar->createComponent('VEVENT'); - $vevent->DTSTART = '20111223T120000Z'; + $vevent->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z'); $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent2 = clone $vevent; - $vevent2->DTEND = '20111225T120000Z'; + $vevent2->DTEND = TestHelper::createDtEnd($calendar, '20111225T120000Z'); $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent3 = clone $vevent; - $vevent3->DURATION = 'P1D'; + $vevent3->DURATION = TestHelper::createDuration($calendar, 'P1D'); $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent4 = clone $vevent; - $vevent4->DTSTART = '20111225'; + $vevent4->DTSTART = TestHelper::createDtStart($calendar, '20111225'); $vevent4->DTSTART['VALUE'] = 'DATE'; $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; @@ -48,16 +55,16 @@ public function timeRangeTestData(): array $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2011-12-26 17:00:00', new \DateTimeZone('Europe/Berlin')), false]; $vevent5 = clone $vevent; - $vevent5->DURATION = 'P1D'; - $vevent5->RRULE = 'FREQ=YEARLY'; + $vevent5->DURATION = TestHelper::createDuration($calendar, 'P1D'); + $vevent5->RRULE = TestHelper::createRRule($calendar, 'FREQ=YEARLY'); $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $tests[] = [$vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true]; $vevent6 = clone $vevent; - $vevent6->DTSTART = '20111225'; + $vevent6->DTSTART = TestHelper::createDtStart($calendar, '20111225'); $vevent6->DTSTART['VALUE'] = 'DATE'; - $vevent6->DTEND = '20111225'; + $vevent6->DTEND = TestHelper::createDtEnd($calendar, '20111225'); $vevent6->DTEND['VALUE'] = 'DATE'; $tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; @@ -66,27 +73,27 @@ public function timeRangeTestData(): array // Added this test to ensure that recurrence rules with no DTEND also // get checked for the entire day. $vevent7 = clone $vevent; - $vevent7->DTSTART = '20120101'; + $vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120101'); $vevent7->DTSTART['VALUE'] = 'DATE'; - $vevent7->RRULE = 'FREQ=MONTHLY'; + $vevent7->RRULE = TestHelper::createRRule($calendar, 'FREQ=MONTHLY'); $tests[] = [$vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true]; // The timezone of time range in question should also be considered. $tests[] = [$vevent7, new \DateTime('2012-02-02 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2012-02-03 00:00:00', new \DateTimeZone('Europe/Berlin')), false]; // Added this test to check recurring events that have no instances. $vevent8 = clone $vevent; - $vevent8->DTSTART = '20130329T140000'; - $vevent8->DTEND = '20130329T153000'; - $vevent8->RRULE = ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z']; + $vevent8->DTSTART = TestHelper::createDtStart($calendar, '20130329T140000'); + $vevent8->DTEND = TestHelper::createDtEnd($calendar, '20130329T153000'); + $vevent8->RRULE = TestHelper::createRRule($calendar, ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z']); $vevent8->add('EXDATE', '20130405T140000'); $vevent8->add('EXDATE', '20130329T140000'); $tests[] = [$vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false]; // Added this test to check recurring all day event that repeat every day $vevent9 = clone $vevent; - $vevent9->DTSTART = '20161027'; - $vevent9->DTEND = '20161028'; - $vevent9->RRULE = 'FREQ=DAILY'; + $vevent9->DTSTART = TestHelper::createDtStart($calendar, '20161027'); + $vevent9->DTEND = TestHelper::createDtEnd($calendar, '20161028'); + $vevent9->RRULE = TestHelper::createRRule($calendar, 'FREQ=DAILY'); $tests[] = [$vevent9, new \DateTime('2016-10-31'), new \DateTime('2016-12-12'), true]; return $tests; diff --git a/tests/VObject/Component/VFreeBusyTest.php b/tests/VObject/Component/VFreeBusyTest.php index f3a521f9..a101a845 100644 --- a/tests/VObject/Component/VFreeBusyTest.php +++ b/tests/VObject/Component/VFreeBusyTest.php @@ -24,6 +24,9 @@ public function testIsFree(): void BLA; $obj = VObject\Reader::read($input); + /** + * @var VFreeBusy $vfb + */ $vfb = $obj->VFREEBUSY; $tz = new \DateTimeZone('UTC'); diff --git a/tests/VObject/Component/VJournalTest.php b/tests/VObject/Component/VJournalTest.php index 98f47889..a0109763 100644 --- a/tests/VObject/Component/VJournalTest.php +++ b/tests/VObject/Component/VJournalTest.php @@ -4,10 +4,13 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Reader; +use Sabre\VObject\TestHelper; class VJournalTest extends TestCase { /** + * @param VJournal $vtodo + * * @dataProvider timeRangeTestData */ public function testInTimeRange(VJournal $vtodo, \DateTime $start, \DateTime $end, bool $outcome): void @@ -68,23 +71,35 @@ public function testValidateBroken(): void ); } + /** + * @return array> + */ public function timeRangeTestData(): array { $calendar = new VCalendar(); $tests = []; + /** + * @var VJournal $vjournal + */ $vjournal = $calendar->createComponent('VJOURNAL'); - $vjournal->DTSTART = '20111223T120000Z'; + $vjournal->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z'); $tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VJournal $vjournal2 + */ $vjournal2 = $calendar->createComponent('VJOURNAL'); - $vjournal2->DTSTART = '20111223'; + $vjournal2->DTSTART = TestHelper::createDtStart($calendar, '20111223'); $vjournal2->DTSTART['VALUE'] = 'DATE'; $tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VJournal $vjournal3 + */ $vjournal3 = $calendar->createComponent('VJOURNAL'); $tests[] = [$vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false]; $tests[] = [$vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; diff --git a/tests/VObject/Component/VTimeZoneTest.php b/tests/VObject/Component/VTimeZoneTest.php index 2928ecd0..da7e254d 100644 --- a/tests/VObject/Component/VTimeZoneTest.php +++ b/tests/VObject/Component/VTimeZoneTest.php @@ -42,13 +42,18 @@ public function testGetTimeZone(): void END:VCALENDAR HI; + /** @var VCalendar $obj */ $obj = Reader::read($input); - $tz = new \DateTimeZone('America/Toronto'); + $expectedTz = new \DateTimeZone('America/Toronto'); + /** + * @var VTimeZone $tzObject + */ + $tzObject = $obj->VTIMEZONE; self::assertEquals( - $tz, - $obj->VTIMEZONE->getTimeZone() + $expectedTz, + $tzObject->getTimeZone() ); } } diff --git a/tests/VObject/Component/VTodoTest.php b/tests/VObject/Component/VTodoTest.php index 808675b3..a9598e95 100644 --- a/tests/VObject/Component/VTodoTest.php +++ b/tests/VObject/Component/VTodoTest.php @@ -4,10 +4,13 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Reader; +use Sabre\VObject\TestHelper; class VTodoTest extends TestCase { /** + * @param VTodo $vtodo + * * @dataProvider timeRangeTestData */ public function testInTimeRange(VTodo $vtodo, \DateTime $start, \DateTime $end, bool $outcome): void @@ -15,45 +18,63 @@ public function testInTimeRange(VTodo $vtodo, \DateTime $start, \DateTime $end, self::assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); } + /** + * @return array> + */ public function timeRangeTestData(): array { $tests = []; $calendar = new VCalendar(); + /** + * @var VTodo $vtodo + */ $vtodo = $calendar->createComponent('VTODO'); - $vtodo->DTSTART = '20111223T120000Z'; + $vtodo->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z'); $tests[] = [$vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vtodo2 = clone $vtodo; - $vtodo2->DURATION = 'P1D'; + $vtodo2->DURATION = TestHelper::createDuration($calendar, 'P1D'); $tests[] = [$vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vtodo3 = clone $vtodo; - $vtodo3->DUE = '20111225'; + $vtodo3->DUE = TestHelper::createDateCreated($calendar, '20111225'); $tests[] = [$vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VTodo $vtodo4 + */ $vtodo4 = $calendar->createComponent('VTODO'); - $vtodo4->DUE = '20111225'; + $vtodo4->DUE = TestHelper::createDateCreated($calendar, '20111225'); $tests[] = [$vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VTodo $vtodo5 + */ $vtodo5 = $calendar->createComponent('VTODO'); - $vtodo5->COMPLETED = '20111225'; + $vtodo5->COMPLETED = TestHelper::createDateCompleted($calendar, '20111225'); $tests[] = [$vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VTodo $vtodo6 + */ $vtodo6 = $calendar->createComponent('VTODO'); - $vtodo6->CREATED = '20111225'; + $vtodo6->CREATED = TestHelper::createDateCreated($calendar, '20111225'); $tests[] = [$vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; + /** + * @var VTodo $vtodo7 + */ $vtodo7 = $calendar->createComponent('VTODO'); - $vtodo7->CREATED = '20111225'; - $vtodo7->COMPLETED = '20111226'; + $vtodo7->CREATED = TestHelper::createDateCreated($calendar, '20111225'); + $vtodo7->COMPLETED = TestHelper::createDateCompleted($calendar, '20111226'); $tests[] = [$vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; diff --git a/tests/VObject/ComponentTest.php b/tests/VObject/ComponentTest.php index 4a247d90..e82a5042 100644 --- a/tests/VObject/ComponentTest.php +++ b/tests/VObject/ComponentTest.php @@ -5,6 +5,8 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\Property\Text; class ComponentTest extends TestCase { @@ -145,10 +147,18 @@ public function testMagicSetScalarTwice(): void public function testMagicSetArray(): void { $comp = new VCalendar(); - $comp->ORG = ['Acme Inc', 'Section 9']; + /** @var Text $property */ + $property = $comp->createProperty('ORG'); + $property->setValue(['Acme Inc', 'Section 9']); + $comp->ORG = $property; - self::assertInstanceOf(Property::class, $comp->ORG); - self::assertEquals(['Acme Inc', 'Section 9'], $comp->ORG->getParts()); + /** + * @var Property $org + */ + $org = $comp->ORG; + + self::assertInstanceOf(Property::class, $org); + self::assertEquals(['Acme Inc', 'Section 9'], $org->getParts()); } public function testMagicSetComponent(): void @@ -167,8 +177,12 @@ public function testMagicSetTwice(): void { $comp = new VCalendar([], false); - $comp->VEVENT = $comp->createComponent('VEVENT'); - $comp->VEVENT = $comp->createComponent('VEVENT'); + /** @var VEvent $component1 */ + $component1 = $comp->createComponent('VEVENT'); + $comp->VEVENT = $component1; + /** @var VEvent $component2 */ + $component2 = $comp->createComponent('VEVENT'); + $comp->VEVENT = $component2; self::assertCount(1, $comp->children()); @@ -179,6 +193,7 @@ public function testArrayAccessGet(): void { $comp = new VCalendar([], false); + /** @var VEvent $event */ $event = $comp->createComponent('VEVENT'); $event->summary = 'Event 1'; @@ -190,7 +205,8 @@ public function testArrayAccessGet(): void $comp->add($event2); self::assertCount(2, $comp->children()); - self::assertTrue($comp->vevent[1] instanceof Component); + self::assertInstanceOf(Component::class, $comp->vevent[1]); + /* @phpstan-ignore-next-line Access to an undefined property Sabre\VObject\Component::$summary. */ self::assertEquals('Event 2', (string) $comp->vevent[1]->summary); } @@ -198,6 +214,7 @@ public function testArrayAccessExists(): void { $comp = new VCalendar(); + /** @var VEvent $event */ $event = $comp->createComponent('VEVENT'); $event->summary = 'Event 1'; @@ -216,6 +233,7 @@ public function testArrayAccessSet(): void { $this->expectException(\LogicException::class); $comp = new VCalendar(); + /* @phpstan-ignore-next-line */ $comp['hey'] = 'hi there'; } @@ -420,8 +438,10 @@ public function testInstantiateSubComponent(): void $comp->createProperty('UID', '12345'), ]); $comp->add($event); + /** @var VEvent $event1 */ + $event1 = $comp->VEVENT; - self::assertEquals('12345', $comp->VEVENT->UID->getValue()); + self::assertEquals('12345', $event1->UID->getValue()); } public function testRemoveByName(): void @@ -440,6 +460,9 @@ public function testRemoveByObj(): void { $comp = new VCalendar([], false); $comp->add('prop1', 'val1'); + /** + * @var Property $prop + */ $prop = $comp->add('prop2', 'val2'); $comp->remove($prop); @@ -459,6 +482,8 @@ public function testRemoveNotFound(): void } /** + * @param array>> $componentList + * * @dataProvider ruleData */ public function testValidateRules(array $componentList, int $errorCount): void @@ -504,8 +529,12 @@ public function testValidateRepairShouldNotDeduplicatePropertiesWhenParametersDi $component = new FakeComponent($vcard, 'WithDuplicateGIR', []); $component->add('BAZ', 'BAZ'); - $component->add('GIR', 'VALUE')->add('PARAM', '1'); - $component->add('GIR', 'VALUE')->add('PARAM', '2'); // Same value but different parameters + /** @var Component $girComponent1 */ + $girComponent1 = $component->add('GIR', 'VALUE'); + $girComponent1->add('PARAM', '1'); + /** @var Component $girComponent2 */ + $girComponent2 = $component->add('GIR', 'VALUE'); + $girComponent2->add('PARAM', '2'); // Same value but different parameters $messages = $component->validate(Component::REPAIR); @@ -520,8 +549,12 @@ public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAndParame $component = new FakeComponent($vcard, 'WithDuplicateGIR', []); $component->add('BAZ', 'BAZ'); - $component->add('GIR', 'VALUE')->add('PARAM', 'P'); - $component->add('GIR', 'VALUE')->add('PARAM', 'P'); + /** @var Component $girComponent1 */ + $girComponent1 = $component->add('GIR', 'VALUE'); + $girComponent1->add('PARAM', 'P'); + /** @var Component $girComponent2 */ + $girComponent2 = $component->add('GIR', 'VALUE'); + $girComponent2->add('PARAM', 'P'); $messages = $component->validate(Component::REPAIR); @@ -546,6 +579,9 @@ public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAreEqual( self::assertCount(1, $component->GIR); } + /** + * @return array>> + */ public function ruleData(): array { return [ @@ -563,6 +599,9 @@ public function ruleData(): array class FakeComponent extends Component { + /** + * @return string[] + */ public function getValidationRules(): array { return [ @@ -574,6 +613,9 @@ public function getValidationRules(): array ]; } + /** + * @return string[] + */ public function getDefaults(): array { return [ diff --git a/tests/VObject/DateTimeParserTest.php b/tests/VObject/DateTimeParserTest.php index b1e7f7cd..b1bf9c63 100644 --- a/tests/VObject/DateTimeParserTest.php +++ b/tests/VObject/DateTimeParserTest.php @@ -30,7 +30,9 @@ public function testParseICalendarDurationDateInterval(): void self::assertEquals($expected, DateTimeParser::parse('P1W')); $expected = new \DateInterval('PT3M'); - $expected->invert = true; + // https://www.php.net/manual/en/class.dateinterval.php#dateinterval.props.invert + // invert is 1 if the interval represents a negative time period and 0 otherwise. + $expected->invert = 1; self::assertEquals($expected, DateTimeParser::parseDuration('-PT3M')); } @@ -161,6 +163,8 @@ public function testParseICalendarDateInvalidDate(): void } /** + * @param array|string>> $output + * * @dataProvider vcardDates */ public function testVCardDate(string $input, array $output): void @@ -183,6 +187,9 @@ public function testBadVCardTime(): void DateTimeParser::parseVCardTime('23:12:166'); } + /** + * @return array|string>> + */ public function vcardDates(): array { return [ @@ -636,7 +643,12 @@ public function testDateAndOrTimeDateTimeWithDayHourTZ(): void ); } - protected function assertDateAndOrTimeEqualsTo(string $date, array $parts): void + /** + * @param array $parts + * + * @throws InvalidDataException + */ + protected static function assertDateAndOrTimeEqualsTo(string $date, array $parts): void { self::assertSame( DateTimeParser::parseVCardDateAndOrTime($date), diff --git a/tests/VObject/EmClientTest.php b/tests/VObject/EmClientTest.php index 0af6fdb2..fd7dbeea 100644 --- a/tests/VObject/EmClientTest.php +++ b/tests/VObject/EmClientTest.php @@ -3,6 +3,9 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\Property\ICalendar\DateTime; class EmClientTest extends TestCase { @@ -47,8 +50,14 @@ public function testParseTz(): void END:VEVENT END:VCALENDAR'; + /** @var VCalendar $vObject */ $vObject = Reader::read($str); - $dt = $vObject->VEVENT->DTSTART->getDateTime(); + + /** @var VEvent $event */ + $event = $vObject->VEVENT; + /** @var DateTime $dateTime */ + $dateTime = $event->DTSTART; + $dt = $dateTime->getDateTime(); self::assertEquals(new \DateTimeImmutable('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt); } } diff --git a/tests/VObject/EmptyParameterTest.php b/tests/VObject/EmptyParameterTest.php index ab197ab3..6f6c63b5 100644 --- a/tests/VObject/EmptyParameterTest.php +++ b/tests/VObject/EmptyParameterTest.php @@ -3,6 +3,8 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCard; +use Sabre\VObject\Property\FlatText; class EmptyParameterTest extends TestCase { @@ -18,15 +20,17 @@ public function testRead(): void END:VCARD VCF; + /** @var VCard $vcard */ $vcard = Reader::read($input); self::assertInstanceOf(Component\VCard::class, $vcard); $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30); - $vcard = $vcard->serialize(); + $serializedVcard = $vcard->serialize(); - $converted = Reader::read($vcard); + $converted = Reader::read($serializedVcard); $converted->validate(); + /* @phpstan-ignore-next-line Offset 'X-INTERN' in isset() does not exist. */ self::assertTrue(isset($converted->EMAIL['X-INTERN'])); $version = Version::VERSION; @@ -43,16 +47,20 @@ public function testRead(): void VCF; - self::assertEquals($expected, str_replace("\r", '', $vcard)); + self::assertEquals($expected, str_replace("\r", '', $serializedVcard)); } public function testVCard21Parameter(): void { $vcard = new Component\VCard([], false); - $vcard->VERSION = '2.1'; + /** @var FlatText $property */ + $property = $vcard->createProperty('VERSION'); + $property->setValue('2.1'); + $vcard->VERSION = $property; $vcard->PHOTO = 'random_stuff'; + /* @phpstan-ignore-next-line 'Cannot call method add() on string' */ $vcard->PHOTO->add(null, 'BASE64'); - $vcard->UID = 'foo-bar'; + $vcard->UID = TestHelper::createUid($vcard, 'foo-bar'); $result = $vcard->serialize(); $expected = [ diff --git a/tests/VObject/EmptyValueIssueTest.php b/tests/VObject/EmptyValueIssueTest.php index 533ac6ab..5ba5aa3f 100644 --- a/tests/VObject/EmptyValueIssueTest.php +++ b/tests/VObject/EmptyValueIssueTest.php @@ -3,6 +3,8 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; /** * This test is written for Issue 68:. @@ -22,9 +24,12 @@ public function testDecodeValue(): void END:VCALENDAR ICS; + /** @var VCalendar $vobj */ $vobj = Reader::read($input); + /** @var VEvent $event */ + $event = $vobj->VEVENT; // Before this bug was fixed, getValue() would return nothing. - self::assertEquals("This is a description\nwith a linebreak and a ; , and :", $vobj->VEVENT->DESCRIPTION->getValue()); + self::assertEquals("This is a description\nwith a linebreak and a ; , and :", $event->DESCRIPTION->getValue()); } } diff --git a/tests/VObject/FreeBusyGeneratorTest.php b/tests/VObject/FreeBusyGeneratorTest.php index 47283eaf..c481c473 100644 --- a/tests/VObject/FreeBusyGeneratorTest.php +++ b/tests/VObject/FreeBusyGeneratorTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Property\FlatText; class FreeBusyGeneratorTest extends TestCase { @@ -11,12 +12,16 @@ class FreeBusyGeneratorTest extends TestCase public function testGeneratorBaseObject(): void { $obj = new Component\VCalendar(); - $obj->METHOD = 'PUBLISH'; + /** @var FlatText $property */ + $property = $obj->createProperty('METHOD'); + $property->setValue('PUBLISH'); + $obj->METHOD = $property; $gen = new FreeBusyGenerator(); $gen->setObjects([]); $gen->setBaseObject($obj); + /** @var Component\VCalendar $result */ $result = $gen->getResult(); self::assertEquals('PUBLISH', $result->METHOD->getValue()); @@ -42,7 +47,7 @@ public function testInvalidArg(): void * It only generates the freebusy report for the following time-range: * 2011-01-01 11:00:00 until 2011-01-03 11:11:11 * - * @param array|string $input + * @param array|string|resource|Document $input * * @throws ParseException */ diff --git a/tests/VObject/ICalendar/AttachParseTest.php b/tests/VObject/ICalendar/AttachParseTest.php index cb54eb34..fa60dc5f 100644 --- a/tests/VObject/ICalendar/AttachParseTest.php +++ b/tests/VObject/ICalendar/AttachParseTest.php @@ -3,6 +3,9 @@ namespace Sabre\VObject\ICalendar; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\Property; use Sabre\VObject\Property\Uri; use Sabre\VObject\Reader; @@ -13,7 +16,7 @@ class AttachParseTest extends TestCase */ public function testParseAttach(): void { - $vcal = <<VEVENT->ATTACH; + /** @var VCalendar $vcal */ + $vcal = Reader::read($vcalString); + /** @var VEvent $event */ + $event = $vcal->VEVENT; + /** + * @var Property $prop + */ + $prop = $event->ATTACH; self::assertInstanceOf(Uri::class, $prop); self::assertEquals('ftp://example.com/pub/reports/r-960812.ps', $prop->getValue()); diff --git a/tests/VObject/ITip/BrokerTester.php b/tests/VObject/ITip/BrokerTester.php index cc01ed3f..5d390493 100644 --- a/tests/VObject/ITip/BrokerTester.php +++ b/tests/VObject/ITip/BrokerTester.php @@ -3,10 +3,12 @@ namespace Sabre\VObject\ITip; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VEvent; use Sabre\VObject\InvalidDataException; use Sabre\VObject\ParseException; use Sabre\VObject\PHPUnitAssertions; +use Sabre\VObject\Property; use Sabre\VObject\Reader; use Sabre\VObject\Recur\MaxInstancesExceededException; use Sabre\VObject\Recur\NoInstancesException; @@ -23,6 +25,16 @@ abstract class BrokerTester extends TestCase { use PHPUnitAssertions; + /** + * @param VCalendar|string|null $oldMessage + * @param VCalendar|string|null $newMessage + * @param array> $expected + * + * @throws ITipException + * @throws InvalidDataException + * @throws ParseException + * @throws SameOrganizerForAllComponentsException + */ public function parse($oldMessage, $newMessage, array $expected = [], string $currentUser = 'mailto:one@example.org'): void { $broker = new Broker(); @@ -52,10 +64,11 @@ public function parse($oldMessage, $newMessage, array $expected = [], string $cu * @throws NoInstancesException * @throws InvalidDataException */ - public function process($input, $existingObject = null, $expected = false): void + public function process(string $input, string $old = null, string $expected = null): void { $version = Version::VERSION; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); $mainComponent = new VEvent($vcal, 'VEVENT'); @@ -70,24 +83,34 @@ public function process($input, $existingObject = null, $expected = false): void $message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null; $message->component = $mainComponent->name; $message->uid = $mainComponent->UID->getValue(); - $message->sequence = isset($vcal->VEVENT[0]) ? (string) $vcal->VEVENT[0]->SEQUENCE : null; + $message->sequence = isset($vcal->VEVENT[0]) ? $vcal->VEVENT[0]->SEQUENCE->getValue() : null; if ('REPLY' === $message->method) { - $message->sender = $mainComponent->ATTENDEE->getValue(); - $message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null; - $message->recipient = $mainComponent->ORGANIZER->getValue(); - $message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null; + /** + * @var Property $attendee + */ + $attendee = $mainComponent->ATTENDEE; + $message->sender = $attendee->getValue(); + /* @phpstan-ignore-next-line Offset 'CN' in isset() does not exist. Call to an undefined method getValue(). */ + $message->senderName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null; + $organizer = $mainComponent->ORGANIZER; + $message->recipient = $organizer->getValue(); + /* @phpstan-ignore-next-line Offset 'CN' in isset() does not exist. */ + $message->recipientName = isset($organizer['CN']) ? $organizer['CN'] : null; } $broker = new Broker(); - if (is_string($existingObject)) { + if (is_string($old)) { $existingObject = str_replace( '%foo%', "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject $version//EN\nCALSCALE:GREGORIAN", - $existingObject + $old ); - $existingObject = Reader::read($existingObject); + /** @var VCalendar $existingObject */ + $existingObject = Reader::read($old); + } else { + $existingObject = $old; } $result = $broker->processMessage($message, $existingObject); diff --git a/tests/VObject/Issue64Test.php b/tests/VObject/Issue64Test.php index 110f91fa..01d3a33b 100644 --- a/tests/VObject/Issue64Test.php +++ b/tests/VObject/Issue64Test.php @@ -3,11 +3,13 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCard; class Issue64Test extends TestCase { public function testRead(): void { + /** @var VCard $vcard */ $vcard = Reader::read(file_get_contents(dirname(__FILE__).'/issue64.vcf')); $vcard = $vcard->convert(Document::VCARD30); $vcard = $vcard->serialize(); diff --git a/tests/VObject/JCalTest.php b/tests/VObject/JCalTest.php index fa347966..76f9082e 100644 --- a/tests/VObject/JCalTest.php +++ b/tests/VObject/JCalTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VEvent; class JCalTest extends TestCase { @@ -10,6 +11,7 @@ public function testToJCal(): void { $cal = new Component\VCalendar(); + /** @var VEvent $event */ $event = $cal->add('VEVENT', [ 'UID' => 'foo', 'DTSTART' => new \DateTime('2013-05-26 18:10:00Z'), diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php index 24656f88..902a312d 100644 --- a/tests/VObject/Parser/MimeDirTest.php +++ b/tests/VObject/Parser/MimeDirTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\ParseException; /** @@ -163,8 +164,10 @@ public function testParsingTwiceSameContent(): void $mimeDir = new MimeDir(); $vcard = $mimeDir->parse($card); + /** @var VEvent $event */ + $event = $vcard->VEVENT; // we can do a simple assertion here. As long as we don't get an exception, everything is fine - self::assertEquals('20220612', $vcard->VEVENT->DTSTART->getValue()); + self::assertEquals('20220612', $event->DTSTART->getValue()); } /** @@ -193,6 +196,9 @@ public function testBrokenMultilineContentDoesBreakImport($vcalendar): void $mimeDir->parse($vcalendar); } + /** + * @return string[][] + */ public function provideBrokenVCalendar(): array { return [[<<ADR->getParts()); } - private function getPropertyValue(Property $property): string + /** + * @param Property|null $property + */ + private function getPropertyValue(?Property $property): string { + $this->assertNotNull($property, __METHOD__.' called with property set to null'); + return (string) $property; /* diff --git a/tests/VObject/Property/ICalendar/CalAddressTest.php b/tests/VObject/Property/ICalendar/CalAddressTest.php index b774f4fb..d4b15cdb 100644 --- a/tests/VObject/Property/ICalendar/CalAddressTest.php +++ b/tests/VObject/Property/ICalendar/CalAddressTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Property\ICalendar; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; class CalAddressTest extends TestCase { @@ -11,7 +12,10 @@ class CalAddressTest extends TestCase */ public function testGetNormalizedValue(string $expected, string $input): void { - $vobj = new \Sabre\VObject\Component\VCalendar(); + $vobj = new VCalendar(); + /** + * @var CalAddress $property + */ $property = $vobj->add('ATTENDEE', $input); self::assertEquals( @@ -20,6 +24,9 @@ public function testGetNormalizedValue(string $expected, string $input): void ); } + /** + * @return string[][] + */ public function values(): array { return [ diff --git a/tests/VObject/Property/ICalendar/DateTimeTest.php b/tests/VObject/Property/ICalendar/DateTimeTest.php index 00c8be1b..103202ea 100644 --- a/tests/VObject/Property/ICalendar/DateTimeTest.php +++ b/tests/VObject/Property/ICalendar/DateTimeTest.php @@ -4,11 +4,17 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\Component\VTimeZone; use Sabre\VObject\InvalidDataException; +use Sabre\VObject\Property\FlatText; class DateTimeTest extends TestCase { - protected $vcal; + /** + * @var VCalendar + */ + protected VCalendar $vcal; public function setUp(): void { @@ -21,11 +27,14 @@ public function testSetDateTime(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); self::assertEquals('19850704T013000', (string) $elem); - self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('Europe/Amsterdam', $elem['TZID']); self::assertNull($elem['VALUE']); self::assertTrue($elem->hasTime()); @@ -37,6 +46,9 @@ public function testSetDateTimeLOCAL(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt, true); @@ -52,6 +64,9 @@ public function testSetDateTimeUTC(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); @@ -66,6 +81,9 @@ public function testSetDateTimeFromUnixTimestamp(): void // When initialized from a Unix timestamp, the timezone is set to "+00:00". $dt = new \DateTime('@489288600'); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); @@ -81,11 +99,14 @@ public function testSetDateTimeLOCALTZ(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); self::assertEquals('19850704T013000', (string) $elem); - self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('Europe/Amsterdam', $elem['TZID']); self::assertTrue($elem->hasTime()); } @@ -96,13 +117,16 @@ public function testSetDateTimeDATE(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem['VALUE'] = 'DATE'; $elem->setDateTime($dt); self::assertEquals('19850704', (string) $elem); self::assertNull($elem['TZID']); - self::assertEquals('DATE', (string) $elem['VALUE']); + self::assertEquals('DATE', $elem['VALUE']); self::assertFalse($elem->hasTime()); } @@ -113,11 +137,14 @@ public function testSetValue(): void $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setValue($dt); self::assertEquals('19850704T013000', (string) $elem); - self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('Europe/Amsterdam', $elem['TZID']); self::assertNull($elem['VALUE']); self::assertTrue($elem->hasTime()); @@ -131,11 +158,14 @@ public function testSetValueArray(): void $dt1->setTimeZone($tz); $dt2->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setValue([$dt1, $dt2]); self::assertEquals('19850704T013000,19850704T023000', (string) $elem); - self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('Europe/Amsterdam', $elem['TZID']); self::assertNull($elem['VALUE']); self::assertTrue($elem->hasTime()); @@ -149,11 +179,14 @@ public function testSetParts(): void $dt1->setTimeZone($tz); $dt2->setTimeZone($tz); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setParts([$dt1, $dt2]); self::assertEquals('19850704T013000,19850704T023000', (string) $elem); - self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('Europe/Amsterdam', $elem['TZID']); self::assertNull($elem['VALUE']); self::assertTrue($elem->hasTime()); @@ -164,6 +197,9 @@ public function testSetPartsStrings(): void $dt1 = '19850704T013000Z'; $dt2 = '19850704T023000Z'; + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setParts([$dt1, $dt2]); @@ -177,8 +213,11 @@ public function testGetDateTimeCached(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTimeImmutable('1985-07-04 01:30:00', $tz); - $dt->setTimeZone($tz); + $dt->setTimeZone($tz); /* @phpstan-ignore-line */ + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); @@ -187,6 +226,9 @@ public function testGetDateTimeCached(): void public function testGetDateTimeDateNULL(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART'); $dt = $elem->getDateTime(); @@ -195,6 +237,9 @@ public function testGetDateTimeDateNULL(): void public function testGetDateTimeDateDATE(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704'); $dt = $elem->getDateTime(); @@ -204,6 +249,9 @@ public function testGetDateTimeDateDATE(): void public function testGetDateTimeDateDATEReferenceTimeZone(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704'); $tz = new \DateTimeZone('America/Toronto'); @@ -216,6 +264,9 @@ public function testGetDateTimeDateDATEReferenceTimeZone(): void public function testGetDateTimeDateFloating(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $dt = $elem->getDateTime(); @@ -225,6 +276,9 @@ public function testGetDateTimeDateFloating(): void public function testGetDateTimeDateFloatingReferenceTimeZone(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $tz = new \DateTimeZone('America/Toronto'); @@ -237,6 +291,9 @@ public function testGetDateTimeDateFloatingReferenceTimeZone(): void public function testGetDateTimeDateUTC(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000Z'); $dt = $elem->getDateTime(); @@ -247,6 +304,9 @@ public function testGetDateTimeDateUTC(): void public function testGetDateTimeDateLOCALTZ(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $elem['TZID'] = 'Europe/Amsterdam'; @@ -260,20 +320,32 @@ public function testGetDateTimeDateLOCALTZ(): void public function testGetDateTimeDateInvalid(): void { $this->expectException(InvalidDataException::class); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', 'bla'); $elem->getDateTime(); } public function testGetDateTimeWeirdTZ(): void { + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $elem['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'; $event = $this->vcal->createComponent('VEVENT'); $event->add($elem); + /** + * @var VTimeZone $timezone + */ $timezone = $this->vcal->createComponent('VTIMEZONE'); - $timezone->TZID = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'; + /** @var FlatText $property */ + $property = $this->vcal->createProperty('TZID'); + $property->setValue('/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'); + $timezone->TZID = $property; $timezone->{'X-LIC-LOCATION'} = 'Europe/Amsterdam'; $this->vcal->add($event); @@ -291,14 +363,23 @@ public function testGetDateTimeBadTimeZone(): void $default = date_default_timezone_get(); date_default_timezone_set('Canada/Eastern'); + /** + * @var DateTime $elem + */ $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $elem['TZID'] = 'Moon'; $event = $this->vcal->createComponent('VEVENT'); $event->add($elem); + /** + * @var VTimeZone $timezone + */ $timezone = $this->vcal->createComponent('VTIMEZONE'); - $timezone->TZID = 'Moon'; + /** @var FlatText $property */ + $property = $this->vcal->createProperty('TZID'); + $property->setValue('Moon'); + $timezone->TZID = $property; $timezone->{'X-LIC-LOCATION'} = 'Moon'; $this->vcal->add($event); @@ -334,6 +415,7 @@ public function testValidate(): void public function testCreateDatePropertyThroughAdd(): void { $vcal = new VCalendar(); + /** @var VEvent $vevent */ $vevent = $vcal->add('VEVENT'); $dtstart = $vevent->add( diff --git a/tests/VObject/Property/ICalendar/DurationTest.php b/tests/VObject/Property/ICalendar/DurationTest.php index 044f8627..742e618b 100644 --- a/tests/VObject/Property/ICalendar/DurationTest.php +++ b/tests/VObject/Property/ICalendar/DurationTest.php @@ -4,12 +4,14 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; class DurationTest extends TestCase { public function testGetDateInterval(): void { $vcal = new VCalendar(); + /** @var VEvent $event */ $event = $vcal->add('VEVENT', ['DURATION' => ['PT1H']]); self::assertEquals( diff --git a/tests/VObject/Property/ICalendar/RecurTest.php b/tests/VObject/Property/ICalendar/RecurTest.php index b2750f03..8894c20b 100644 --- a/tests/VObject/Property/ICalendar/RecurTest.php +++ b/tests/VObject/Property/ICalendar/RecurTest.php @@ -4,7 +4,9 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\Node; +use Sabre\VObject\Property; use Sabre\VObject\Reader; class RecurTest extends TestCase @@ -14,6 +16,9 @@ class RecurTest extends TestCase public function testParts(): void { $vcal = new VCalendar(); + /** + * @var Property $recur + */ $recur = $vcal->add('RRULE', 'FREQ=Daily'); self::assertInstanceOf(Recur::class, $recur); @@ -28,6 +33,9 @@ public function testSetValueBadVal(): void { $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); + /** + * @var Property $recur + */ $recur = $vcal->add('RRULE', 'FREQ=Daily'); $recur->setValue(new \Exception()); } @@ -35,6 +43,9 @@ public function testSetValueBadVal(): void public function testSetValueWithCount(): void { $vcal = new VCalendar(); + /** + * @var Property $recur + */ $recur = $vcal->add('RRULE', 'FREQ=Daily'); $recur->setValue(['COUNT' => 3]); self::assertEquals(3, $recur->getParts()['COUNT']); @@ -56,7 +67,9 @@ public function testGetJSONWithCount(): void '; $vcal = Reader::read($input); - $rrule = $vcal->VEVENT->RRULE; + /** @var VEvent $ev */ + $ev = $vcal->VEVENT; + $rrule = $ev->RRULE; $count = $rrule->getJsonValue()[0]['count']; self::assertTrue(is_int($count)); self::assertEquals(3, $count); @@ -65,6 +78,9 @@ public function testGetJSONWithCount(): void public function testSetSubParts(): void { $vcal = new VCalendar(); + /** + * @var Property $recur + */ $recur = $vcal->add('RRULE', ['FREQ' => 'DAILY', 'BYDAY' => 'mo,tu', 'BYMONTH' => [0, 1]]); self::assertEquals([ @@ -89,8 +105,11 @@ public function testGetJSONWithUntil(): void END:VCALENDAR '; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); - $rrule = $vcal->VEVENT->RRULE; + /** @var VEvent $ev */ + $ev = $vcal->VEVENT; + $rrule = $ev->RRULE; $untilJsonString = $rrule->getJsonValue()[0]['until']; self::assertEquals('2016-03-05T23:00:00Z', $untilJsonString); } diff --git a/tests/VObject/Property/TextTest.php b/tests/VObject/Property/TextTest.php index 0fa320bf..d8ef7b38 100644 --- a/tests/VObject/Property/TextTest.php +++ b/tests/VObject/Property/TextTest.php @@ -7,6 +7,9 @@ class TextTest extends TestCase { + /** + * @param string|array $propValue + */ public function assertVCard21Serialization($propValue, string $expected): void { $doc = new VCard([ diff --git a/tests/VObject/Property/VCard/DateAndOrTimeTest.php b/tests/VObject/Property/VCard/DateAndOrTimeTest.php index 8e2cb320..e62edef0 100644 --- a/tests/VObject/Property/VCard/DateAndOrTimeTest.php +++ b/tests/VObject/Property/VCard/DateAndOrTimeTest.php @@ -3,7 +3,7 @@ namespace Sabre\VObject\Property\VCard; use PHPUnit\Framework\TestCase; -use Sabre\VObject; +use Sabre\VObject\Component\VCard; use Sabre\VObject\Reader; class DateAndOrTimeTest extends TestCase @@ -13,12 +13,15 @@ class DateAndOrTimeTest extends TestCase */ public function testGetJsonValue(string $input, string $output): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY', $input); self::assertEquals([$output], $prop->getJsonValue()); } + /** + * @return string[][] + */ public function dates(): array { return [ @@ -83,7 +86,7 @@ public function dates(): array public function testSetParts(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY'); $prop->setParts([ @@ -95,7 +98,7 @@ public function testSetParts(): void public function testSetPartsDateTimeImmutable(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY'); $prop->setParts([ @@ -108,7 +111,7 @@ public function testSetPartsDateTimeImmutable(): void public function testSetPartsTooMany(): void { $this->expectException(\InvalidArgumentException::class); - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY'); $prop->setParts([ @@ -119,7 +122,7 @@ public function testSetPartsTooMany(): void public function testSetPartsString(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY'); $prop->setParts([ @@ -131,8 +134,11 @@ public function testSetPartsString(): void public function testSetValueDateTime(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->createProperty('BDAY'); $prop->setValue( new \DateTime('2014-04-02 18:37:00') @@ -143,8 +149,11 @@ public function testSetValueDateTime(): void public function testSetValueDateTimeImmutable(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->createProperty('BDAY'); $prop->setValue( new \DateTimeImmutable('2014-04-02 18:37:00') @@ -155,8 +164,11 @@ public function testSetValueDateTimeImmutable(): void public function testSetDateTimeOffset(): void { - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->createProperty('BDAY'); $prop->setValue( new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto')) @@ -169,7 +181,10 @@ public function testGetDateTime(): void { $datetime = new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto')); - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->createProperty('BDAY', $datetime); $dt = $prop->getDateTime(); @@ -180,7 +195,7 @@ public function testGetDate(): void { $datetime = new \DateTime('2014-04-02'); - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->createProperty('BDAY', $datetime, null, 'DATE'); self::assertEquals('DATE', $prop->getValueType()); @@ -191,7 +206,10 @@ public function testGetDateIncomplete(): void { $datetime = '--0407'; - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->add('BDAY', $datetime); $dt = $prop->getDateTime(); @@ -207,13 +225,17 @@ public function testGetDateIncomplete(): void public function testGetDateIncompleteFromVCard(): void { - $vcard = << $vcard */ + $vcard = Reader::read($input); + /** + * @var DateAndOrTime $prop + */ $prop = $vcard->BDAY; $dt = $prop->getDateTime(); @@ -231,7 +253,7 @@ public function testValidate(): void { $datetime = '--0407'; - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->add('BDAY', $datetime); self::assertEquals([], $prop->validate()); @@ -241,7 +263,7 @@ public function testValidateBroken(): void { $datetime = '123'; - $vcard = new VObject\Component\VCard(); + $vcard = new VCard(); $prop = $vcard->add('BDAY', $datetime); self::assertEquals([[ diff --git a/tests/VObject/PropertyTest.php b/tests/VObject/PropertyTest.php index b15e06b2..676c05bd 100644 --- a/tests/VObject/PropertyTest.php +++ b/tests/VObject/PropertyTest.php @@ -29,9 +29,17 @@ public function testCreate(): void ]; $property = $cal->createProperty('propname', 'propvalue', $params); - - self::assertEquals('value1', $property['param1']->getValue()); - self::assertEquals('value2', $property['param2']->getValue()); + /** + * @var Parameter $param1 + */ + $param1 = $property['param1']; + /** + * @var Parameter $param2 + */ + $param2 = $property['param2']; + + self::assertEquals('value1', $param1->getValue()); + self::assertEquals('value2', $param2->getValue()); } public function testSetValue(): void @@ -80,9 +88,13 @@ public function testParameterMultiple(): void $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; $property->add('paramname', 'paramvalue'); + /** + * @var Parameter $param + */ + $param = $property['paramname']; - self::assertInstanceOf(Parameter::class, $property['paramname']); - self::assertCount(2, $property['paramname']->getParts()); + self::assertInstanceOf(Parameter::class, $param); + self::assertCount(2, $param->getParts()); } public function testSetParameterAsString(): void @@ -186,7 +198,7 @@ public function testAddScalar(): void self::assertCount(1, $property->parameters()); - self::assertTrue($property->parameters['MYPARAM'] instanceof Parameter); + self::assertInstanceOf(Parameter::class, $property->parameters['MYPARAM']); self::assertEquals('MYPARAM', $property->parameters['MYPARAM']->name); self::assertEquals('value', $property->parameters['MYPARAM']->getValue()); } @@ -197,9 +209,13 @@ public function testAddParameter(): void $prop = $cal->createProperty('EMAIL'); $prop->add('MYPARAM', 'value'); + /** + * @var Parameter $param + */ + $param = $prop['myparam']; self::assertCount(1, $prop->parameters()); - self::assertEquals('MYPARAM', $prop['myparam']->name); + self::assertEquals('MYPARAM', $param->name); } public function testAddParameterTwice(): void @@ -212,8 +228,12 @@ public function testAddParameterTwice(): void self::assertCount(1, $prop->parameters); self::assertCount(2, $prop->parameters['MYPARAM']->getParts()); + /** + * @var Parameter $param + */ + $param = $prop->parameters['MYPARAM']; - self::assertEquals('MYPARAM', $prop['MYPARAM']->name); + self::assertEquals('MYPARAM', $param->name); } public function testClone(): void @@ -225,7 +245,7 @@ public function testClone(): void $property2 = clone $property; $property['FOO'] = 'BAZ'; - self::assertEquals('BAR', (string) $property2['FOO']); + self::assertEquals('BAR', $property2['FOO']); } public function testCreateParams(): void @@ -236,8 +256,18 @@ public function testCreateParams(): void 'param2' => ['value2', 'value3'], ]); - self::assertCount(1, $property['PARAM1']->getParts()); - self::assertCount(2, $property['PARAM2']->getParts()); + /** + * @var Parameter $param1 + */ + $param1 = $property['PARAM1']; + + /** + * @var Parameter $param2 + */ + $param2 = $property['PARAM2']; + + self::assertCount(1, $param1->getParts()); + self::assertCount(2, $param2->getParts()); } public function testValidateNonUTF8(): void @@ -385,7 +415,6 @@ public function testValidateBadEncodingVCard21(): void $document = new VCard(['VERSION' => '2.1']); $property = $document->add('X-FOO', 'value'); $property['ENCODING'] = 'B'; - $result = $property->validate(); self::assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']); diff --git a/tests/VObject/ReaderTest.php b/tests/VObject/ReaderTest.php index 645ed181..afcb4de8 100644 --- a/tests/VObject/ReaderTest.php +++ b/tests/VObject/ReaderTest.php @@ -405,7 +405,7 @@ public function testReadIncompleteFile(): void public function testReadBrokenInput(): void { $this->expectException(\InvalidArgumentException::class); - Reader::read(false); + Reader::read(false); /* @phpstan-ignore-line */ } public function testReadBOM(): void diff --git a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php index 9b6b20df..c5b3d959 100644 --- a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php +++ b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\Reader; class ByMonthInDailyTest extends TestCase @@ -35,13 +36,16 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($ics); self::assertInstanceOf(VCalendar::class, $vcal); $vcal = $vcal->expand(new \DateTime('2013-09-28'), new \DateTime('2014-09-11')); $dates = []; - foreach ($vcal->VEVENT as $event) { + /** @var array $events */ + $events = iterator_to_array($vcal->VEVENT); + foreach ($events as $event) { $dates[] = $event->DTSTART->getValue(); } diff --git a/tests/VObject/Recur/EventIterator/BySetPosHangTest.php b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php index f5132e1d..9df25a7c 100644 --- a/tests/VObject/Recur/EventIterator/BySetPosHangTest.php +++ b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\Reader; class BySetPosHangTest extends TestCase @@ -30,13 +31,17 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($ics); self::assertInstanceOf(VCalendar::class, $vcal); $vcal = $vcal->expand(new \DateTime('2015-01-01'), new \DateTime('2016-01-01')); $dates = []; - foreach ($vcal->VEVENT as $event) { + /** @var array $events */ + $events = iterator_to_array($vcal->VEVENT); + + foreach ($events as $event) { $dates[] = $event->DTSTART->getValue(); } diff --git a/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php b/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php index a7a39d1d..47663131 100644 --- a/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php +++ b/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php @@ -24,6 +24,7 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); self::assertInstanceOf(VCalendar::class, $vcal); @@ -75,6 +76,7 @@ public function testExpandWithReferenceTimezone(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); self::assertInstanceOf(VCalendar::class, $vcal); diff --git a/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php b/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php index 8391a232..fa856df2 100644 --- a/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php +++ b/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Recur\EventIterator; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; use Sabre\VObject\Recur; @@ -38,8 +39,9 @@ public function testGetDTEnd(): void END:VCALENDAR ICS; + /** @var VCalendar $vObject */ $vObject = Reader::read($ics); - $it = new Recur\EventIterator($vObject, (string) $vObject->VEVENT->UID); + $it = new Recur\EventIterator($vObject, 'uuid'); while ($it->valid()) { $it->next(); diff --git a/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php b/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php index 4f434dd2..efc498e5 100644 --- a/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php +++ b/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\Reader; /** @@ -33,11 +34,13 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); self::assertInstanceOf(VCalendar::class, $vcal); $vcal = $vcal->expand(new \DateTime('2015-01-01'), new \DateTime('2015-12-01')); + /** @var array $result */ $result = iterator_to_array($vcal->VEVENT); self::assertCount(5, $result); diff --git a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php index b0ecbbdb..13051ba9 100644 --- a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php +++ b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php @@ -33,6 +33,7 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); self::assertInstanceOf(VCalendar::class, $vcal); diff --git a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php index 591140e6..20722921 100644 --- a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php +++ b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php @@ -4,11 +4,14 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\InvalidDataException; use Sabre\VObject\Recur; +use Sabre\VObject\TestHelper; class InfiniteLoopProblemTest extends TestCase { + /** @var VCalendar */ private VCalendar $vcal; public function setUp(): void @@ -22,10 +25,11 @@ public function setUp(): void */ public function testFastForwardTooFar(): void { + /** @var VEvent $ev */ $ev = $this->vcal->createComponent('VEVENT'); - $ev->UID = 'foobar'; - $ev->DTSTART = '20090420T180000Z'; - $ev->RRULE = 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1'; + $ev->UID = TestHelper::createUid($this->vcal, 'foobar'); + $ev->DTSTART = TestHelper::createDtStart($this->vcal, '20090420T180000Z'); + $ev->RRULE = TestHelper::createRRule($this->vcal, 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1'); self::assertFalse($ev->isInTimeRange(new \DateTimeImmutable('2012-01-01 12:00:00'), new \DateTimeImmutable('3000-01-01 00:00:00'))); } @@ -35,13 +39,12 @@ public function testFastForwardTooFar(): void */ public function testYearlyByMonthLoop(): void { + /** @var VEvent $ev */ $ev = $this->vcal->createComponent('VEVENT'); - $ev->UID = 'uuid'; - $ev->DTSTART = '20120101T154500'; - $ev->DTSTART['TZID'] = 'Europe/Berlin'; - $ev->RRULE = 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA'; - $ev->DTEND = '20120101T164500'; - $ev->DTEND['TZID'] = 'Europe/Berlin'; + $ev->UID = TestHelper::createUid($this->vcal, 'uuid'); + $ev->DTSTART = TestHelper::createDtStart($this->vcal, '2012-01-01 15:45:00', 'Europe/Berlin'); + $ev->RRULE = TestHelper::createRRule($this->vcal, 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA'); + $ev->DTEND = TestHelper::createDtEnd($this->vcal, '2012-01-01 16:45:00', 'Europe/Berlin'); // This recurrence rule by itself is a yearly rule that should happen // every february. @@ -78,10 +81,11 @@ public function testYearlyByMonthLoop(): void public function testZeroInterval(): void { $this->expectException(InvalidDataException::class); + /** @var VEvent $ev */ $ev = $this->vcal->createComponent('VEVENT'); - $ev->UID = 'uuid'; - $ev->DTSTART = '20120824T145700Z'; - $ev->RRULE = 'FREQ=YEARLY;INTERVAL=0'; + $ev->UID = TestHelper::createUid($this->vcal, 'uuid'); + $ev->DTSTART = TestHelper::createDtStart($this->vcal, '20120824T145700Z'); + $ev->RRULE = TestHelper::createRRule($this->vcal, 'FREQ=YEARLY;INTERVAL=0'); $this->vcal->add($ev); $it = new Recur\EventIterator($this->vcal, 'uuid'); diff --git a/tests/VObject/Recur/EventIterator/MainTest.php b/tests/VObject/Recur/EventIterator/MainTest.php index bce4bcd9..2bc4b76c 100644 --- a/tests/VObject/Recur/EventIterator/MainTest.php +++ b/tests/VObject/Recur/EventIterator/MainTest.php @@ -10,6 +10,7 @@ use Sabre\VObject\Recur\EventIterator; use Sabre\VObject\Recur\MaxInstancesExceededException; use Sabre\VObject\Recur\NoInstancesException; +use Sabre\VObject\TestHelper; class MainTest extends TestCase { @@ -21,11 +22,11 @@ class MainTest extends TestCase public function testValues(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07')); @@ -47,11 +48,11 @@ public function testInvalidFreq(): void { $this->expectException(InvalidDataException::class); $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z'; - $ev->UID = 'foo'; - /** @var DateTime $dtStart */ + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z'); + $ev->UID = TestHelper::createUid($vcal, 'foo'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -94,12 +95,12 @@ public function testVCalendarInvalidUID(): void public function testHourly(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=HOURLY;INTERVAL=3;UNTIL=20111025T000000Z'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=HOURLY;INTERVAL=3;UNTIL=20111025T000000Z'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 12:00:00', new \DateTimeZone('UTC'))); @@ -152,12 +153,12 @@ public function testHourly(): void public function testDaily(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -201,9 +202,11 @@ public function testDaily(): void public function testNoRRULE(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -241,10 +244,12 @@ public function testNoRRULE(): void public function testDailyByDayByHour(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-08 06:00:00', new \DateTimeZone('UTC'))); @@ -293,10 +298,12 @@ public function testDailyByDayByHour(): void public function testDailyByHour(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2012-10-11 12:00:00', new \DateTimeZone('UTC'))); @@ -345,10 +352,12 @@ public function testDailyByHour(): void public function testDailyByDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -397,10 +406,12 @@ public function testDailyByDay(): void public function testWeekly(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;INTERVAL=2;COUNT=10'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -447,10 +458,12 @@ public function testWeekly(): void public function testWeeklyByDayByHour(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 08:00:00', new \DateTimeZone('UTC'))); @@ -502,10 +515,12 @@ public function testWeeklyByDayByHour(): void public function testWeeklyByDaySpecificHour(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 18:00:00', new \DateTimeZone('UTC'))); @@ -554,10 +569,12 @@ public function testWeeklyByDaySpecificHour(): void public function testWeeklyByDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -606,10 +623,12 @@ public function testWeeklyByDay(): void public function testMonthly(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;INTERVAL=3;COUNT=5'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-12-05', new \DateTimeZone('UTC'))); @@ -650,10 +669,12 @@ public function testMonthly(): void public function testMonthlyEndOfMonth(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;INTERVAL=2;COUNT=12'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-12-31', new \DateTimeZone('UTC'))); @@ -706,12 +727,12 @@ public function testMonthlyEndOfMonth(): void public function testMonthlyByMonthDay(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01', new \DateTimeZone('UTC'))); @@ -761,10 +782,12 @@ public function testMonthlyByMonthDay(): void public function testMonthlyByDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-01-03', new \DateTimeZone('UTC'))); @@ -816,10 +839,12 @@ public function testMonthlyByDay(): void public function testMonthlyByDayByMonthDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-08-01', new \DateTimeZone('UTC'))); @@ -865,10 +890,12 @@ public function testMonthlyByDayByMonthDay(): void public function testMonthlyByDayBySetPos(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-01-03', new \DateTimeZone('UTC'))); @@ -917,12 +944,12 @@ public function testMonthlyByDayBySetPos(): void public function testYearly(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=10;INTERVAL=3'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01', new \DateTimeZone('UTC'))); @@ -968,10 +995,12 @@ public function testYearly(): void public function testYearlyLeapYear(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=3'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=3'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2012-02-29', new \DateTimeZone('UTC'))); @@ -1010,10 +1039,12 @@ public function testYearlyLeapYear(): void public function testYearlyByMonth(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-04-07', new \DateTimeZone('UTC'))); @@ -1057,10 +1088,12 @@ public function testYearlyByMonth(): void public function testYearlyByMonthByDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); @@ -1104,10 +1137,12 @@ public function testYearlyByMonthByDay(): void public function testFastForward(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); @@ -1142,15 +1177,18 @@ public function testFastForward(): void public function testFastForwardAllDayEventThatStopAtTheStartTime(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=DAILY'; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); $ev->add($dtStart); + /** @var DateTime $dtEnd */ $dtEnd = $vcal->createProperty('DTSTART'); $dtEnd->setDateTime(new \DateTimeImmutable('2011-04-05', new \DateTimeZone('UTC'))); $ev->add($dtEnd); @@ -1175,21 +1213,21 @@ public function testFastForwardAllDayEventThatStopAtTheStartTime(): void public function testComplexExclusions(): void { $vcal = new VCalendar(); - /** @var VEvent $ev */ + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RRULE = 'FREQ=YEARLY;COUNT=10'; - /** @var DateTime $dtStart */ + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RRULE = TestHelper::createRRule($vcal, 'FREQ=YEARLY;COUNT=10'); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $tz = new \DateTimeZone('Canada/Eastern'); $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01 13:50:20', $tz)); - /** @var DateTime $exDate1 */ + /** @var DateTime $exDate1 */ $exDate1 = $vcal->createProperty('EXDATE'); $exDate1->setDateTimes([new \DateTimeImmutable('2012-01-01 13:50:20', $tz), new \DateTimeImmutable('2014-01-01 13:50:20', $tz)]); - /** @var DateTime $exDate2 */ + /** @var DateTime $exDate2 */ $exDate2 = $vcal->createProperty('EXDATE'); $exDate2->setDateTimes([new \DateTimeImmutable('2016-01-01 13:50:20', $tz)]); @@ -1233,28 +1271,31 @@ public function testOverriddenEvent(): void { $vcal = new VCalendar(); + /** @var VEvent $ev1 */ $ev1 = $vcal->createComponent('VEVENT'); - $ev1->UID = 'overridden'; - $ev1->RRULE = 'FREQ=DAILY;COUNT=10'; - $ev1->DTSTART = '20120107T120000Z'; + $ev1->UID = TestHelper::createUid($vcal, 'overridden'); + $ev1->RRULE = TestHelper::createRRule($vcal, 'FREQ=DAILY;COUNT=10'); + $ev1->DTSTART = TestHelper::createDtStart($vcal, '20120107T120000Z'); $ev1->SUMMARY = 'baseEvent'; $vcal->add($ev1); // ev2 overrides an event, and puts it on 2pm instead. + /** @var VEvent $ev2 */ $ev2 = $vcal->createComponent('VEVENT'); - $ev2->UID = 'overridden'; + $ev2->UID = TestHelper::createUid($vcal, 'overridden'); $ev2->{'RECURRENCE-ID'} = '20120110T120000Z'; - $ev2->DTSTART = '20120110T140000Z'; + $ev2->DTSTART = TestHelper::createDtStart($vcal, '20120110T140000Z'); $ev2->SUMMARY = 'Event 2'; $vcal->add($ev2); // ev3 overrides an event, and puts it 2 days and 2 hours later + /** @var VEvent $ev3 */ $ev3 = $vcal->createComponent('VEVENT'); - $ev3->UID = 'overridden'; + $ev3->UID = TestHelper::createUid($vcal, 'overridden'); $ev3->{'RECURRENCE-ID'} = '20120113T120000Z'; - $ev3->DTSTART = '20120115T140000Z'; + $ev3->DTSTART = TestHelper::createDtStart($vcal, '20120115T140000Z'); $ev3->SUMMARY = 'Event 3'; $vcal->add($ev3); @@ -1304,19 +1345,21 @@ public function testOverriddenEvent2(): void { $vcal = new VCalendar(); + /** @var VEvent $ev1 */ $ev1 = $vcal->createComponent('VEVENT'); - $ev1->UID = 'overridden'; - $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3'; - $ev1->DTSTART = '20120112T120000Z'; + $ev1->UID = TestHelper::createUid($vcal, 'overridden'); + $ev1->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;COUNT=3'); + $ev1->DTSTART = TestHelper::createDtStart($vcal, '20120112T120000Z'); $ev1->SUMMARY = 'baseEvent'; $vcal->add($ev1); // ev2 overrides an event, and puts it 6 days earlier instead. + /** @var VEvent $ev2 */ $ev2 = $vcal->createComponent('VEVENT'); - $ev2->UID = 'overridden'; + $ev2->UID = TestHelper::createUid($vcal, 'overridden'); $ev2->{'RECURRENCE-ID'} = '20120119T120000Z'; - $ev2->DTSTART = '20120113T120000Z'; + $ev2->DTSTART = TestHelper::createDtStart($vcal, '20120113T120000Z'); $ev2->SUMMARY = 'Override!'; $vcal->add($ev2); @@ -1351,20 +1394,22 @@ public function testOverriddenEvent2(): void public function testOverriddenEventNoValuesExpected(): void { $vcal = new VCalendar(); + /** @var VEvent $ev1 */ $ev1 = $vcal->createComponent('VEVENT'); - $ev1->UID = 'overridden'; - $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3'; - $ev1->DTSTART = '20120124T120000Z'; + $ev1->UID = TestHelper::createUid($vcal, 'overridden'); + $ev1->RRULE = TestHelper::createRRule($vcal, 'FREQ=WEEKLY;COUNT=3'); + $ev1->DTSTART = TestHelper::createDtStart($vcal, '20120124T120000Z'); $ev1->SUMMARY = 'baseEvent'; $vcal->add($ev1); // ev2 overrides an event, and puts it 6 days earlier instead. + /** @var VEvent $ev2 */ $ev2 = $vcal->createComponent('VEVENT'); - $ev2->UID = 'overridden'; + $ev2->UID = TestHelper::createUid($vcal, 'overridden'); $ev2->{'RECURRENCE-ID'} = '20120131T120000Z'; - $ev2->DTSTART = '20120125T120000Z'; + $ev2->DTSTART = TestHelper::createDtStart($vcal, '20120125T120000Z'); $ev2->SUMMARY = 'Override!'; $vcal->add($ev2); @@ -1398,13 +1443,18 @@ public function testOverriddenEventNoValuesExpected(): void public function testRDATE(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); - $ev->UID = 'bla'; - $ev->RDATE = [ - new \DateTimeImmutable('2014-08-07', new \DateTimeZone('UTC')), - new \DateTimeImmutable('2014-08-08', new \DateTimeZone('UTC')), - ]; + $ev->UID = TestHelper::createUid($vcal, 'bla'); + $ev->RDATE = TestHelper::createRDate( + $vcal, + [ + new \DateTimeImmutable('2014-08-07', new \DateTimeZone('UTC')), + new \DateTimeImmutable('2014-08-08', new \DateTimeZone('UTC')), + ] + ); + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); @@ -1446,19 +1496,22 @@ public function testNoMasterBadUID(): void $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); // ev2 overrides an event, and puts it on 2pm instead. + /** @var VEvent $ev2 */ $ev2 = $vcal->createComponent('VEVENT'); - $ev2->UID = 'overridden'; + $ev2->UID = TestHelper::createUid($vcal, 'overridden'); $ev2->{'RECURRENCE-ID'} = '20120110T120000Z'; - $ev2->DTSTART = '20120110T140000Z'; + $ev2->DTSTART = TestHelper::createDtStart($vcal, '20120110T140000Z'); $ev2->SUMMARY = 'Event 2'; $vcal->add($ev2); // ev3 overrides an event, and puts it 2 days and 2 hours later + /** @var VEvent $ev3 */ $ev3 = $vcal->createComponent('VEVENT'); - $ev3->UID = 'overridden'; + $ev3->UID = TestHelper::createUid($vcal, 'overridden'); $ev3->{'RECURRENCE-ID'} = '20120113T120000Z'; - $ev3->DTSTART = '20120115T140000Z'; + $ev3->DTSTART = TestHelper::createDtStart($vcal, '20120115T140000Z'); + $ev3->DTSTART = TestHelper::createDtStart($vcal, '20120115T140000Z'); $ev3->SUMMARY = 'Event 3'; $vcal->add($ev3); diff --git a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php index 19dca97a..53749379 100644 --- a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php +++ b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Recur\EventIterator; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; use Sabre\VObject\Recur\MaxInstancesExceededException; use Sabre\VObject\Settings; @@ -27,6 +28,7 @@ public function testExceedMaxRecurrences(): void $temp = Settings::$maxRecurrences; Settings::$maxRecurrences = 4; try { + /** @var VCalendar $vcal */ $vcal = Reader::read($input); $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-09-01')); } finally { diff --git a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php index 2b1656ec..9c140e3d 100644 --- a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php +++ b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php @@ -32,6 +32,7 @@ public function testExpand(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); self::assertInstanceOf(VCalendar::class, $vcal); diff --git a/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php b/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php index 15c92f04..ee7d3634 100644 --- a/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php +++ b/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Recur\EventIterator; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; class OverrideFirstEventTest extends TestCase @@ -29,6 +30,7 @@ public function testOverrideFirstEvent(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); $vcal = $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-09-01')); @@ -89,6 +91,7 @@ public function testRemoveFirstEvent(): void END:VCALENDAR ICS; + /** @var VCalendar $vcal */ $vcal = Reader::read($input); $vcal = $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-08-19')); diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index 2814df66..ddd0785e 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -1072,6 +1072,12 @@ public function testIteratorFunctions(): void ); } + /** + * @param string|array $rule + * @param array $expected + * + * @throws InvalidDataException + */ public function parse($rule, string $start, array $expected, string $fastForward = null, string $tz = 'UTC', bool $runTillTheEnd = false): void { $dt = new \DateTime($start, new \DateTimeZone($tz)); diff --git a/tests/VObject/Splitter/ICalendarTest.php b/tests/VObject/Splitter/ICalendarTest.php index f5428e93..4d425446 100644 --- a/tests/VObject/Splitter/ICalendarTest.php +++ b/tests/VObject/Splitter/ICalendarTest.php @@ -15,6 +15,9 @@ public function setUp(): void $this->version = VObject\Version::VERSION; } + /** + * @return false|resource + */ public function createStream(string $data) { $stream = fopen('php://memory', 'r+'); diff --git a/tests/VObject/Splitter/VCardTest.php b/tests/VObject/Splitter/VCardTest.php index 7ebb07b9..9ab475c6 100644 --- a/tests/VObject/Splitter/VCardTest.php +++ b/tests/VObject/Splitter/VCardTest.php @@ -7,6 +7,11 @@ class VCardTest extends TestCase { + /** + * @param string $data + * + * @return false|resource + */ public function createStream($data) { $stream = fopen('php://memory', 'r+'); diff --git a/tests/VObject/TestHelper.php b/tests/VObject/TestHelper.php new file mode 100644 index 00000000..ed15adaa --- /dev/null +++ b/tests/VObject/TestHelper.php @@ -0,0 +1,180 @@ + $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDateCreated(VCalendar $vcal, string $dateTime, string $timezone = null): DateTime + { + return self::createDt($vcal, 'CREATED', $dateTime, $timezone); + } + + /** + * @param VCalendar $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDateCompleted(VCalendar $vcal, string $dateTime, string $timezone = null): DateTime + { + return self::createDt($vcal, 'COMPLETED', $dateTime, $timezone); + } + + /** + * @param VCalendar $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDateDue(VCalendar $vcal, string $dateTime, string $timezone = null): DateTime + { + return self::createDt($vcal, 'DUE', $dateTime, $timezone); + } + + /** + * @param VCalendar $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDtStart(VCalendar $vcal, string $dateTime, string $timezone = null): DateTime + { + return self::createDt($vcal, 'DTSTART', $dateTime, $timezone); + } + + /** + * @param VCalendar $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDtEnd(VCalendar $vcal, string $dateTime, string $timezone = null): DateTime + { + return self::createDt($vcal, 'DTEND', $dateTime, $timezone); + } + + /** + * @param VCalendar $vcal + * + * @return DateTime + * + * @throws InvalidDataException + * @throws \Exception + */ + public static function createDt(VCalendar $vcal, string $propertyName, string $dateTime, string $timezone = null): DateTime + { + /** @var DateTime $property */ + $property = $vcal->createProperty($propertyName); + if (null !== $timezone) { + $timezone = new \DateTimeZone($timezone); + } + $property->setDateTime(new \DateTimeImmutable($dateTime, $timezone)); + + return $property; + } + + /** + * @param VCalendar|VCard $vcalOrCard + * + * @return FlatText + * + * @throws InvalidDataException + */ + public static function createUid($vcalOrCard, string $uidString): FlatText + { + /** @var FlatText $property */ + $property = $vcalOrCard->createProperty('UID'); + $property->setValue($uidString); + + return $property; + } + + /** + * @param VCalendar $vcal + * + * @return Duration + * + * @throws InvalidDataException + */ + public static function createDuration(VCalendar $vcal, string $duration): Duration + { + /** @var Duration $property */ + $property = $vcal->createProperty('DURATION'); + $property->setValue($duration); + + return $property; + } + + /** + * @param VCalendar $vcal + * + * @return Duration + * + * @throws InvalidDataException + */ + public static function createTrigger(VCalendar $vcal, string $duration): Duration + { + /** @var Duration $property */ + $property = $vcal->createProperty('TRIGGER'); + $property->setValue($duration); + + return $property; + } + + /** + * @param VCalendar $vcal + * @param array $dateTimes + * + * @return DateTime + * + * @throws InvalidDataException + */ + public static function createRDate(VCalendar $vcal, array $dateTimes): DateTime + { + /** @var DateTime $property */ + $property = $vcal->createProperty('RDATE'); + $property->setValue($dateTimes); + + return $property; + } + + /** + * @param VCalendar $vcal + * @param array|string $rule + * + * @return Recur + * + * @throws InvalidDataException + */ + public static function createRRule(VCalendar $vcal, $rule): Recur + { + /** @var Recur $property */ + $property = $vcal->createProperty('RRULE'); + $property->setValue($rule); + + return $property; + } +} diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php index 462218e9..150180f7 100644 --- a/tests/VObject/TimeZoneUtilTest.php +++ b/tests/VObject/TimeZoneUtilTest.php @@ -28,6 +28,9 @@ public function testCorrectTZ(string $timezoneName): void } } + /** + * @return array> + */ public function getMapping(): array { $map = array_merge( @@ -198,6 +201,9 @@ public function testTimeZoneBCIdentifiers(string $tzid): void self::assertEquals($ex->getName(), $tz->getName()); } + /** + * @return array> + */ public function getPHPTimeZoneIdentifiers(): array { // PHPUNit requires an array of arrays @@ -209,9 +215,12 @@ function ($value) { ); } + /** + * @return array> + */ public function getPHPTimeZoneBCIdentifiers(): array { - // PHPUNit requires an array of arrays + // PHPUnit requires an array of arrays return array_map( function ($value) { return [$value]; diff --git a/tests/VObject/VCardConverterTest.php b/tests/VObject/VCardConverterTest.php index 9db0ad56..fddffd6d 100644 --- a/tests/VObject/VCardConverterTest.php +++ b/tests/VObject/VCardConverterTest.php @@ -45,7 +45,7 @@ public function testConvert30to40(): void END:VCARD OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -86,7 +86,7 @@ public function testConvert40to40(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -128,7 +128,7 @@ public function testConvert21to40(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -171,7 +171,7 @@ public function testConvert30to30(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -215,7 +215,7 @@ public function testConvert40to30(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -251,7 +251,7 @@ public function testConvertGroupCard(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -271,7 +271,7 @@ public function testConvertGroupCard(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -284,7 +284,7 @@ public function testConvertGroupCard(): void /** * @throws InvalidDataException */ - public function testBDAYConversion() + public function testBDAYConversion(): void { $input = << $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -321,7 +321,7 @@ public function testBDAYConversion() OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -354,7 +354,7 @@ public function testUnknownSourceVCardVersion(): void IN; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard->convert(Document::VCARD40); } @@ -362,7 +362,7 @@ public function testUnknownSourceVCardVersion(): void /** * @throws InvalidDataException */ - public function testUnknownTargetVCardVersion() + public function testUnknownTargetVCardVersion(): void { $this->expectException(\InvalidArgumentException::class); $input = << $vcard */ $vcard = Reader::read($input); $vcard->convert(Document::VCARD21); } @@ -399,7 +399,7 @@ public function testConvertIndividualCard(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -416,7 +416,7 @@ public function testConvertIndividualCard(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -449,7 +449,7 @@ public function testAnniversary(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -467,7 +467,7 @@ public function testAnniversary(): void $input, ]; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -508,7 +508,7 @@ public function testMultipleAnniversaries(): void OUT; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); @@ -526,7 +526,7 @@ public function testMultipleAnniversaries(): void $input, ]; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); @@ -552,14 +552,14 @@ public function testNoLabel(): void VCF; + /** @var VCard $vcard */ $vcard = Reader::read($input); self::assertInstanceOf(Component\VCard::class, $vcard); - /** @var VCard $vcard */ $vcard = $vcard->convert(Document::VCARD40); $vcard = $vcard->serialize(); - /** @var VCard $converted */ + /** @var VCard $converted */ $converted = Reader::read($vcard); $converted->validate(); @@ -604,7 +604,7 @@ public function testPhoneNumberValueTypeGetsRemoved(): void END:VCARD VCF; - /** @var VCard $vcard */ + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); diff --git a/tests/VObject/WriterTest.php b/tests/VObject/WriterTest.php index f5cd7a69..d9f32ab9 100644 --- a/tests/VObject/WriterTest.php +++ b/tests/VObject/WriterTest.php @@ -6,6 +6,9 @@ class WriterTest extends TestCase { + /** + * @return Document|null + */ public function getComponent(): ?Document { $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";