Skip to content

Commit 0a65cf7

Browse files
committed
Fix things reported by phpstan in tests
1 parent 8b724d2 commit 0a65cf7

File tree

13 files changed

+359
-214
lines changed

13 files changed

+359
-214
lines changed

tests/VObject/Component/VAlarmTest.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject\InvalidDataException;
7+
use Sabre\VObject\Property\IntegerValue;
78
use Sabre\VObject\Reader;
9+
use Sabre\VObject\TestHelper;
810

911
class VAlarmTest extends TestCase
1012
{
@@ -44,7 +46,7 @@ public function timeRangeTestData(): array
4446

4547
/** @var VEvent<int, mixed> $vevent2 */
4648
$vevent2 = $calendar->createComponent('VEVENT');
47-
$vevent2->DTSTART = '20120313T130000Z';
49+
$vevent2->DTSTART = TestHelper::createDtStart($calendar, '20120313T130000Z');
4850
$vevent2->add($valarm2);
4951

5052
$tests[] = [$valarm2, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true];
@@ -56,8 +58,8 @@ public function timeRangeTestData(): array
5658

5759
/** @var VEvent<int, mixed> $vevent3 */
5860
$vevent3 = $calendar->createComponent('VEVENT');
59-
$vevent3->DTSTART = '20120301T130000Z';
60-
$vevent3->DTEND = '20120401T130000Z';
61+
$vevent3->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z');
62+
$vevent3->DTEND = TestHelper::createDtEnd($calendar, '20120401T130000Z');
6163
$vevent3->add($valarm3);
6264

6365
$tests[] = [$valarm3, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false];
@@ -66,15 +68,14 @@ public function timeRangeTestData(): array
6668
// Relation to end time of todo
6769
/** @var VAlarm<int, mixed> $valarm4 */
6870
$valarm4 = $calendar->createComponent('VALARM');
69-
$valarm4->TRIGGER = '-P1D';
70-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
71+
$valarm4->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
7172
$valarm4->TRIGGER['VALUE'] = 'DURATION';
7273
$valarm4->TRIGGER['RELATED'] = 'END';
7374

7475
/** @var VTodo<int, mixed> $vtodo4 */
7576
$vtodo4 = $calendar->createComponent('VTODO');
76-
$vtodo4->DTSTART = '20120301T130000Z';
77-
$vtodo4->DUE = '20120401T130000Z';
77+
$vtodo4->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z');
78+
$vtodo4->DUE = TestHelper::createDateDue($calendar, '20120401T130000Z');
7879
$vtodo4->add($valarm4);
7980

8081
$tests[] = [$valarm4, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false];
@@ -83,30 +84,31 @@ public function timeRangeTestData(): array
8384
// Relation to start time of event + repeat
8485
/** @var VAlarm<int, mixed> $valarm5 */
8586
$valarm5 = $calendar->createComponent('VALARM');
86-
$valarm5->TRIGGER = '-P1D';
87-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
87+
$valarm5->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
8888
$valarm5->TRIGGER['VALUE'] = 'DURATION';
89-
$valarm5->REPEAT = 10;
90-
$valarm5->DURATION = 'P1D';
89+
/** @var IntegerValue<mixed, mixed> $property */
90+
$property = $calendar->createProperty('REPEAT');
91+
$property->setValue([10]);
92+
$valarm5->REPEAT = $property;
93+
$valarm5->DURATION = TestHelper::createDuration($calendar, 'P1D');
9194

9295
/** @var VEvent<int, mixed> $vevent5 */
9396
$vevent5 = $calendar->createComponent('VEVENT');
94-
$vevent5->DTSTART = '20120301T130000Z';
97+
$vevent5->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z');
9598
$vevent5->add($valarm5);
9699

97100
$tests[] = [$valarm5, new \DateTime('2012-03-09 01:00:00'), new \DateTime('2012-03-10 01:00:00'), true];
98101

99102
// Relation to start time of event + duration, but no repeat
100103
/** @var VAlarm<int, mixed> $valarm6 */
101104
$valarm6 = $calendar->createComponent('VALARM');
102-
$valarm6->TRIGGER = '-P1D';
103-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
105+
$valarm6->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
104106
$valarm6->TRIGGER['VALUE'] = 'DURATION';
105-
$valarm6->DURATION = 'P1D';
107+
$valarm6->DURATION = TestHelper::createDuration($calendar, 'P1D');
106108

107109
/** @var VEvent<int, mixed> $vevent6 */
108110
$vevent6 = $calendar->createComponent('VEVENT');
109-
$vevent6->DTSTART = '20120313T130000Z';
111+
$vevent6->DTSTART = TestHelper::createDtStart($calendar, '20120313T130000Z');
110112
$vevent6->add($valarm6);
111113

112114
$tests[] = [$valarm6, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true];
@@ -115,15 +117,14 @@ public function timeRangeTestData(): array
115117
// Relation to end time of event (DURATION instead of DTEND)
116118
/** @var VAlarm<int, mixed> $valarm7 */
117119
$valarm7 = $calendar->createComponent('VALARM');
118-
$valarm7->TRIGGER = '-P1D';
119-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
120+
$valarm7->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
120121
$valarm7->TRIGGER['VALUE'] = 'DURATION';
121122
$valarm7->TRIGGER['RELATED'] = 'END';
122123

123124
/** @var VEvent<int, mixed> $vevent7 */
124125
$vevent7 = $calendar->createComponent('VEVENT');
125-
$vevent7->DTSTART = '20120301T130000Z';
126-
$vevent7->DURATION = 'P30D';
126+
$vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z');
127+
$vevent7->DURATION = TestHelper::createDuration($calendar, 'P30D');
127128
$vevent7->add($valarm7);
128129

129130
$tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false];
@@ -132,14 +133,13 @@ public function timeRangeTestData(): array
132133
// Relation to end time of event (No DTEND or DURATION)
133134
/** @var VAlarm<int, mixed> $valarm7 */
134135
$valarm7 = $calendar->createComponent('VALARM');
135-
$valarm7->TRIGGER = '-P1D';
136-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
136+
$valarm7->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
137137
$valarm7->TRIGGER['VALUE'] = 'DURATION';
138138
$valarm7->TRIGGER['RELATED'] = 'END';
139139

140140
/** @var VEvent<int, mixed> $vevent7 */
141141
$vevent7 = $calendar->createComponent('VEVENT');
142-
$vevent7->DTSTART = '20120301T130000Z';
142+
$vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120301T130000Z');
143143
$vevent7->add($valarm7);
144144

145145
$tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), true];
@@ -154,8 +154,7 @@ public function testInTimeRangeInvalidComponent(): void
154154
$calendar = new VCalendar();
155155
/** @var VAlarm<int, mixed> $valarm */
156156
$valarm = $calendar->createComponent('VALARM');
157-
$valarm->TRIGGER = '-P1D';
158-
/* @phpstan-ignore-next-line Cannot assign offset 'RELATED' to string. Magic is here. */
157+
$valarm->TRIGGER = TestHelper::createTrigger($calendar, '-P1D');
159158
$valarm->TRIGGER['RELATED'] = 'END';
160159

161160
$vjournal = $calendar->createComponent('VJOURNAL');

tests/VObject/Component/VCalendarTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject;
77
use Sabre\VObject\InvalidDataException;
8+
use Sabre\VObject\Property\FlatText;
89

910
class VCalendarTest extends TestCase
1011
{
@@ -385,7 +386,10 @@ public function testEventExpandYearly(): void
385386
public function testGetDocumentType(): void
386387
{
387388
$vcard = new VCalendar();
388-
$vcard->VERSION = '2.0';
389+
/** @var FlatText<mixed, mixed> $property */
390+
$property = $vcard->createProperty('VERSION');
391+
$property->setValue('2.0');
392+
$vcard->VERSION = $property;
389393
$this->assertEquals(VCalendar::ICALENDAR20, $vcard->getDocumentType());
390394
}
391395

tests/VObject/Component/VCardTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject;
7+
use Sabre\VObject\Property\FlatText;
78

89
class VCardTest extends TestCase
910
{
@@ -120,15 +121,24 @@ public function validateData(): array
120121
public function testGetDocumentType(): void
121122
{
122123
$vcard = new VCard([], false);
123-
$vcard->VERSION = '2.1';
124+
/** @var FlatText<mixed, mixed> $property2 */
125+
$property2 = $vcard->createProperty('VERSION');
126+
$property2->setValue('2.1');
127+
$vcard->VERSION = $property2;
124128
$this->assertEquals(VCard::VCARD21, $vcard->getDocumentType());
125129

126130
$vcard = new VCard([], false);
127-
$vcard->VERSION = '3.0';
131+
/** @var FlatText<mixed, mixed> $property3 */
132+
$property3 = $vcard->createProperty('VERSION');
133+
$property3->setValue('3.0');
134+
$vcard->VERSION = $property3;
128135
$this->assertEquals(VCard::VCARD30, $vcard->getDocumentType());
129136

130137
$vcard = new VCard([], false);
131-
$vcard->VERSION = '4.0';
138+
/** @var FlatText<mixed, mixed> $property4 */
139+
$property4 = $vcard->createProperty('VERSION');
140+
$property4->setValue('4.0');
141+
$vcard->VERSION = $property4;
132142
$this->assertEquals(VCard::VCARD40, $vcard->getDocumentType());
133143

134144
$vcard = new VCard([], false);

tests/VObject/Component/VEventTest.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Sabre\VObject\Component;
44

55
use PHPUnit\Framework\TestCase;
6+
use Sabre\VObject\TestHelper;
67

78
class VEventTest extends TestCase
89
{
@@ -27,23 +28,22 @@ public function timeRangeTestData(): array
2728

2829
/** @var VEvent<int, mixed> $vevent */
2930
$vevent = $calendar->createComponent('VEVENT');
30-
$vevent->DTSTART = '20111223T120000Z';
31+
$vevent->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z');
3132
$tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
3233
$tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
3334

3435
$vevent2 = clone $vevent;
35-
$vevent2->DTEND = '20111225T120000Z';
36+
$vevent2->DTEND = TestHelper::createDtEnd($calendar, '20111225T120000Z');
3637
$tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
3738
$tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
3839

3940
$vevent3 = clone $vevent;
40-
$vevent3->DURATION = 'P1D';
41+
$vevent3->DURATION = TestHelper::createDuration($calendar, 'P1D');
4142
$tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
4243
$tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
4344

4445
$vevent4 = clone $vevent;
45-
$vevent4->DTSTART = '20111225';
46-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
46+
$vevent4->DTSTART = TestHelper::createDtStart($calendar, '20111225');
4747
$vevent4->DTSTART['VALUE'] = 'DATE';
4848
$tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
4949
$tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
@@ -55,18 +55,16 @@ public function timeRangeTestData(): array
5555
$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];
5656

5757
$vevent5 = clone $vevent;
58-
$vevent5->DURATION = 'P1D';
59-
$vevent5->RRULE = 'FREQ=YEARLY';
58+
$vevent5->DURATION = TestHelper::createDuration($calendar, 'P1D');
59+
$vevent5->RRULE = TestHelper::createRRule($calendar, 'FREQ=YEARLY');
6060
$tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
6161
$tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
6262
$tests[] = [$vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true];
6363

6464
$vevent6 = clone $vevent;
65-
$vevent6->DTSTART = '20111225';
66-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
65+
$vevent6->DTSTART = TestHelper::createDtStart($calendar, '20111225');
6766
$vevent6->DTSTART['VALUE'] = 'DATE';
68-
$vevent6->DTEND = '20111225';
69-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
67+
$vevent6->DTEND = TestHelper::createDtEnd($calendar, '20111225');
7068
$vevent6->DTEND['VALUE'] = 'DATE';
7169

7270
$tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
@@ -75,28 +73,27 @@ public function timeRangeTestData(): array
7573
// Added this test to ensure that recurrence rules with no DTEND also
7674
// get checked for the entire day.
7775
$vevent7 = clone $vevent;
78-
$vevent7->DTSTART = '20120101';
79-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
76+
$vevent7->DTSTART = TestHelper::createDtStart($calendar, '20120101');
8077
$vevent7->DTSTART['VALUE'] = 'DATE';
81-
$vevent7->RRULE = 'FREQ=MONTHLY';
78+
$vevent7->RRULE = TestHelper::createRRule($calendar, 'FREQ=MONTHLY');
8279
$tests[] = [$vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true];
8380
// The timezone of time range in question should also be considered.
8481
$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];
8582

8683
// Added this test to check recurring events that have no instances.
8784
$vevent8 = clone $vevent;
88-
$vevent8->DTSTART = '20130329T140000';
89-
$vevent8->DTEND = '20130329T153000';
90-
$vevent8->RRULE = ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z'];
85+
$vevent8->DTSTART = TestHelper::createDtStart($calendar, '20130329T140000');
86+
$vevent8->DTEND = TestHelper::createDtEnd($calendar, '20130329T153000');
87+
$vevent8->RRULE = TestHelper::createRRule($calendar, ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z']);
9188
$vevent8->add('EXDATE', '20130405T140000');
9289
$vevent8->add('EXDATE', '20130329T140000');
9390
$tests[] = [$vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false];
9491

9592
// Added this test to check recurring all day event that repeat every day
9693
$vevent9 = clone $vevent;
97-
$vevent9->DTSTART = '20161027';
98-
$vevent9->DTEND = '20161028';
99-
$vevent9->RRULE = 'FREQ=DAILY';
94+
$vevent9->DTSTART = TestHelper::createDtStart($calendar, '20161027');
95+
$vevent9->DTEND = TestHelper::createDtEnd($calendar, '20161028');
96+
$vevent9->RRULE = TestHelper::createRRule($calendar, 'FREQ=DAILY');
10097
$tests[] = [$vevent9, new \DateTime('2016-10-31'), new \DateTime('2016-12-12'), true];
10198

10299
return $tests;

tests/VObject/Component/VJournalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject\Reader;
7+
use Sabre\VObject\TestHelper;
78

89
class VJournalTest extends TestCase
910
{
@@ -83,16 +84,15 @@ public function timeRangeTestData(): array
8384
* @var VJournal<int, mixed> $vjournal
8485
*/
8586
$vjournal = $calendar->createComponent('VJOURNAL');
86-
$vjournal->DTSTART = '20111223T120000Z';
87+
$vjournal->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z');
8788
$tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
8889
$tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
8990

9091
/**
9192
* @var VJournal<int, mixed> $vjournal2
9293
*/
9394
$vjournal2 = $calendar->createComponent('VJOURNAL');
94-
$vjournal2->DTSTART = '20111223';
95-
/* @phpstan-ignore-next-line Cannot assign offset 'VALUE' to string. Magic is here. */
95+
$vjournal2->DTSTART = TestHelper::createDtStart($calendar, '20111223');
9696
$vjournal2->DTSTART['VALUE'] = 'DATE';
9797
$tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
9898
$tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];

tests/VObject/Component/VTodoTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject\Reader;
7+
use Sabre\VObject\TestHelper;
78

89
class VTodoTest extends TestCase
910
{
@@ -30,50 +31,50 @@ public function timeRangeTestData(): array
3031
* @var VTodo<int, mixed> $vtodo
3132
*/
3233
$vtodo = $calendar->createComponent('VTODO');
33-
$vtodo->DTSTART = '20111223T120000Z';
34+
$vtodo->DTSTART = TestHelper::createDtStart($calendar, '20111223T120000Z');
3435
$tests[] = [$vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
3536
$tests[] = [$vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
3637

3738
$vtodo2 = clone $vtodo;
38-
$vtodo2->DURATION = 'P1D';
39+
$vtodo2->DURATION = TestHelper::createDuration($calendar, 'P1D');
3940
$tests[] = [$vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
4041
$tests[] = [$vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
4142

4243
$vtodo3 = clone $vtodo;
43-
$vtodo3->DUE = '20111225';
44+
$vtodo3->DUE = TestHelper::createDateCreated($calendar, '20111225');
4445
$tests[] = [$vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
4546
$tests[] = [$vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
4647

4748
/**
4849
* @var VTodo<int, mixed> $vtodo4
4950
*/
5051
$vtodo4 = $calendar->createComponent('VTODO');
51-
$vtodo4->DUE = '20111225';
52+
$vtodo4->DUE = TestHelper::createDateCreated($calendar, '20111225');
5253
$tests[] = [$vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
5354
$tests[] = [$vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
5455

5556
/**
5657
* @var VTodo<int, mixed> $vtodo5
5758
*/
5859
$vtodo5 = $calendar->createComponent('VTODO');
59-
$vtodo5->COMPLETED = '20111225';
60+
$vtodo5->COMPLETED = TestHelper::createDateCompleted($calendar, '20111225');
6061
$tests[] = [$vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
6162
$tests[] = [$vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
6263

6364
/**
6465
* @var VTodo<int, mixed> $vtodo6
6566
*/
6667
$vtodo6 = $calendar->createComponent('VTODO');
67-
$vtodo6->CREATED = '20111225';
68+
$vtodo6->CREATED = TestHelper::createDateCreated($calendar, '20111225');
6869
$tests[] = [$vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
6970
$tests[] = [$vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
7071

7172
/**
7273
* @var VTodo<int, mixed> $vtodo7
7374
*/
7475
$vtodo7 = $calendar->createComponent('VTODO');
75-
$vtodo7->CREATED = '20111225';
76-
$vtodo7->COMPLETED = '20111226';
76+
$vtodo7->CREATED = TestHelper::createDateCreated($calendar, '20111225');
77+
$vtodo7->COMPLETED = TestHelper::createDateCompleted($calendar, '20111226');
7778
$tests[] = [$vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
7879
$tests[] = [$vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
7980

0 commit comments

Comments
 (0)