1212use OCA \DAV \CardDAV \CardDavBackend ;
1313use OCA \DAV \Db \PropertyMapper ;
1414use OCP \IURLGenerator ;
15+ use PHPUnit \Framework \MockObject \MockObject ;
1516use Sabre \VObject \Component \VCard ;
1617use Sabre \VObject \Property \Text ;
1718//use Sabre\VObject\Property\;
1819use Test \TestCase ;
1920
2021class AddressBookImplTest extends TestCase {
21- /** @var AddressBookImpl */
22- private $ addressBookImpl ;
23-
24- /** @var array */
25- private $ addressBookInfo ;
26-
27- /** @var AddressBook | \PHPUnit\Framework\MockObject\MockObject */
28- private $ addressBook ;
29-
30- /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
31- private $ urlGenerator ;
32-
33- /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject */
34- private $ backend ;
35-
36- /** @var PropertyMapper | \PHPUnit\Framework\MockObject\MockObject */
37- private $ propertyMapper ;
38-
39- /** @var VCard | \PHPUnit\Framework\MockObject\MockObject */
40- private $ vCard ;
22+ private array $ addressBookInfo ;
23+ private AddressBook &MockObject $ addressBook ;
24+ private IURLGenerator &MockObject $ urlGenerator ;
25+ private CardDavBackend &MockObject $ backend ;
26+ private PropertyMapper &MockObject $ propertyMapper ;
27+ private VCard &MockObject $ vCard ;
28+ private AddressBookImpl $ addressBookImpl ;
4129
4230 protected function setUp (): void {
4331 parent ::setUp ();
@@ -48,10 +36,8 @@ protected function setUp(): void {
4836 'principaluri ' => 'principals/system/system ' ,
4937 '{DAV:}displayname ' => 'display name ' ,
5038 ];
51- $ this ->addressBook = $ this ->getMockBuilder (AddressBook::class)
52- ->disableOriginalConstructor ()->getMock ();
53- $ this ->backend = $ this ->getMockBuilder (CardDavBackend::class)
54- ->disableOriginalConstructor ()->getMock ();
39+ $ this ->addressBook = $ this ->createMock (AddressBook::class);
40+ $ this ->backend = $ this ->createMock (CardDavBackend::class);
5541 $ this ->vCard = $ this ->createMock (VCard::class);
5642 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
5743 $ this ->propertyMapper = $ this ->createMock (PropertyMapper::class);
@@ -77,7 +63,7 @@ public function testGetDisplayName(): void {
7763 }
7864
7965 public function testSearch (): void {
80- /** @var \PHPUnit\Framework\ MockObject\MockObject | AddressBookImpl $addressBookImpl */
66+ /** @var MockObject& AddressBookImpl $addressBookImpl */
8167 $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
8268 ->setConstructorArgs (
8369 [
@@ -89,7 +75,7 @@ public function testSearch(): void {
8975 null
9076 ]
9177 )
92- ->setMethods (['vCard2Array ' , 'readCard ' ])
78+ ->onlyMethods (['vCard2Array ' , 'readCard ' ])
9379 ->getMock ();
9480
9581 $ pattern = 'pattern ' ;
@@ -107,10 +93,10 @@ public function testSearch(): void {
10793 $ addressBookImpl ->expects ($ this ->exactly (2 ))->method ('readCard ' )
10894 ->willReturn ($ this ->vCard );
10995 $ addressBookImpl ->expects ($ this ->exactly (2 ))->method ('vCard2Array ' )
110- ->withConsecutive (
111- ['foo.vcf ' , $ this ->vCard ],
112- ['bar.vcf ' , $ this ->vCard ]
113- )-> willReturn ( ' vCard ' );
96+ ->willReturnMap ([
97+ ['foo.vcf ' , $ this ->vCard , ' vCard ' ],
98+ ['bar.vcf ' , $ this ->vCard , ' vCard ' ],
99+ ] );
114100
115101 $ result = $ addressBookImpl ->search ($ pattern , $ searchProperties , []);
116102 $ this ->assertTrue ((is_array ($ result )));
@@ -119,13 +105,11 @@ public function testSearch(): void {
119105
120106 /**
121107 * @dataProvider dataTestCreate
122- *
123- * @param array $properties
124108 */
125- public function testCreate ($ properties ): void {
109+ public function testCreate (array $ properties ): void {
126110 $ uid = 'uid ' ;
127111
128- /** @var \PHPUnit\Framework\ MockObject\MockObject | AddressBookImpl $addressBookImpl */
112+ /** @var MockObject& AddressBookImpl $addressBookImpl */
129113 $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
130114 ->setConstructorArgs (
131115 [
@@ -137,7 +121,7 @@ public function testCreate($properties): void {
137121 null
138122 ]
139123 )
140- ->setMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' ])
124+ ->onlyMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' ])
141125 ->getMock ();
142126
143127 $ expectedProperties = 0 ;
@@ -164,7 +148,7 @@ public function testCreate($properties): void {
164148 $ this ->assertTrue ($ addressBookImpl ->createOrUpdate ($ properties ));
165149 }
166150
167- public function dataTestCreate () {
151+ public static function dataTestCreate (): array {
168152 return [
169153 [[]],
170154 [['FN ' => 'John Doe ' ]],
@@ -177,7 +161,7 @@ public function testUpdate(): void {
177161 $ uri = 'bla.vcf ' ;
178162 $ properties = ['URI ' => $ uri , 'UID ' => $ uid , 'FN ' => 'John Doe ' ];
179163
180- /** @var \PHPUnit\Framework\ MockObject\MockObject | AddressBookImpl $addressBookImpl */
164+ /** @var MockObject& AddressBookImpl $addressBookImpl */
181165 $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
182166 ->setConstructorArgs (
183167 [
@@ -189,7 +173,7 @@ public function testUpdate(): void {
189173 null
190174 ]
191175 )
192- ->setMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' , 'readCard ' ])
176+ ->onlyMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' , 'readCard ' ])
193177 ->getMock ();
194178
195179 $ addressBookImpl ->expects ($ this ->never ())->method ('createUid ' );
@@ -216,7 +200,7 @@ public function testUpdateWithTypes(): void {
216200 $ vCard = new vCard ;
217201 $ textProperty = $ vCard ->createProperty ('KEY ' , 'value ' );
218202
219- /** @var \PHPUnit\Framework\ MockObject\MockObject | AddressBookImpl $addressBookImpl */
203+ /** @var MockObject& AddressBookImpl $addressBookImpl */
220204 $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
221205 ->setConstructorArgs (
222206 [
@@ -228,7 +212,7 @@ public function testUpdateWithTypes(): void {
228212 null
229213 ]
230214 )
231- ->setMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' , 'readCard ' ])
215+ ->onlyMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' , 'readCard ' ])
232216 ->getMock ();
233217
234218 $ this ->backend ->expects ($ this ->once ())->method ('getCard ' )
@@ -248,11 +232,8 @@ public function testUpdateWithTypes(): void {
248232
249233 /**
250234 * @dataProvider dataTestGetPermissions
251- *
252- * @param array $permissions
253- * @param int $expected
254235 */
255- public function testGetPermissions ($ permissions , $ expected ): void {
236+ public function testGetPermissions (array $ permissions , int $ expected ): void {
256237 $ this ->addressBook ->expects ($ this ->once ())->method ('getACL ' )
257238 ->willReturn ($ permissions );
258239
@@ -261,7 +242,7 @@ public function testGetPermissions($permissions, $expected): void {
261242 );
262243 }
263244
264- public function dataTestGetPermissions () {
245+ public static function dataTestGetPermissions (): array {
265246 return [
266247 [[], 0 ],
267248 [[['privilege ' => '{DAV:}read ' ]], 1 ],
@@ -299,7 +280,7 @@ public function testReadCard(): void {
299280 }
300281
301282 public function testCreateUid (): void {
302- /** @var \PHPUnit\Framework\ MockObject\MockObject | AddressBookImpl $addressBookImpl */
283+ /** @var MockObject& AddressBookImpl $addressBookImpl */
303284 $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
304285 ->setConstructorArgs (
305286 [
@@ -311,7 +292,7 @@ public function testCreateUid(): void {
311292 null
312293 ]
313294 )
314- ->setMethods (['getUid ' ])
295+ ->onlyMethods (['getUid ' ])
315296 ->getMock ();
316297
317298 $ addressBookImpl ->expects ($ this ->exactly (2 ))
0 commit comments