11<?php
22
3+ declare (strict_types=1 );
34/**
45 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
56 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
2425use Test \TestCase ;
2526
2627class RequestSharedSecretTest extends TestCase {
27- /** @var MockObject|IClientService */
28- private $ httpClientService ;
29-
30- /** @var MockObject|IClient */
31- private $ httpClient ;
32-
33- /** @var MockObject|IJobList */
34- private $ jobList ;
35-
36- /** @var MockObject|IURLGenerator */
37- private $ urlGenerator ;
38-
39- /** @var MockObject|TrustedServers */
40- private $ trustedServers ;
41-
42- /** @var MockObject|IResponse */
43- private $ response ;
44-
45- /** @var MockObject|IDiscoveryService */
46- private $ discoveryService ;
47-
48- /** @var MockObject|LoggerInterface */
49- private $ logger ;
50-
51- /** @var MockObject|ITimeFactory */
52- private $ timeFactory ;
53-
54- /** @var MockObject|IConfig */
55- private $ config ;
56-
57- /** @var RequestSharedSecret */
58- private $ requestSharedSecret ;
28+ private IClientService &MockObject $ httpClientService ;
29+ private IClient &MockObject $ httpClient ;
30+ private IJobList &MockObject $ jobList ;
31+ private IURLGenerator &MockObject $ urlGenerator ;
32+ private TrustedServers &MockObject $ trustedServers ;
33+ private IResponse &MockObject $ response ;
34+ private IDiscoveryService &MockObject $ discoveryService ;
35+ private LoggerInterface &MockObject $ logger ;
36+ private ITimeFactory &MockObject $ timeFactory ;
37+ private IConfig &MockObject $ config ;
38+ private RequestSharedSecret $ requestSharedSecret ;
5939
6040 protected function setUp (): void {
6141 parent ::setUp ();
6242
6343 $ this ->httpClientService = $ this ->createMock (IClientService::class);
64- $ this ->httpClient = $ this ->getMockBuilder (IClient::class)->getMock ();
65- $ this ->jobList = $ this ->getMockBuilder (IJobList::class)->getMock ();
66- $ this ->urlGenerator = $ this ->getMockBuilder (IURLGenerator::class)->getMock ();
67- $ this ->trustedServers = $ this ->getMockBuilder (TrustedServers::class)
68- ->disableOriginalConstructor ()->getMock ();
69- $ this ->response = $ this ->getMockBuilder (IResponse::class)->getMock ();
70- $ this ->discoveryService = $ this ->getMockBuilder (IDiscoveryService::class)->getMock ();
44+ $ this ->httpClient = $ this ->createMock (IClient::class);
45+ $ this ->jobList = $ this ->createMock (IJobList::class);
46+ $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
47+ $ this ->trustedServers = $ this ->createMock (TrustedServers::class);
48+ $ this ->response = $ this ->createMock (IResponse::class);
49+ $ this ->discoveryService = $ this ->createMock (IDiscoveryService::class);
7150 $ this ->logger = $ this ->createMock (LoggerInterface::class);
7251 $ this ->timeFactory = $ this ->createMock (ITimeFactory::class);
7352 $ this ->config = $ this ->createMock (IConfig::class);
@@ -89,13 +68,10 @@ protected function setUp(): void {
8968
9069 /**
9170 * @dataProvider dataTestStart
92- *
93- * @param bool $isTrustedServer
94- * @param bool $retainBackgroundJob
9571 */
96- public function testStart ($ isTrustedServer , $ retainBackgroundJob ): void {
97- /** @var RequestSharedSecret | MockObject $requestSharedSecret */
98- $ requestSharedSecret = $ this ->getMockBuilder (' OCA\Federation\BackgroundJob\ RequestSharedSecret' )
72+ public function testStart (bool $ isTrustedServer , bool $ retainBackgroundJob ): void {
73+ /** @var RequestSharedSecret& MockObject $requestSharedSecret */
74+ $ requestSharedSecret = $ this ->getMockBuilder (RequestSharedSecret::class )
9975 ->setConstructorArgs (
10076 [
10177 $ this ->httpClientService ,
@@ -107,8 +83,10 @@ public function testStart($isTrustedServer, $retainBackgroundJob): void {
10783 $ this ->timeFactory ,
10884 $ this ->config ,
10985 ]
110- )->setMethods (['parentStart ' ])->getMock ();
111- $ this ->invokePrivate ($ requestSharedSecret , 'argument ' , [['url ' => 'url ' , 'token ' => 'token ' ]]);
86+ )
87+ ->onlyMethods (['parentStart ' ])
88+ ->getMock ();
89+ self ::invokePrivate ($ requestSharedSecret , 'argument ' , [['url ' => 'url ' , 'token ' => 'token ' ]]);
11290
11391 $ this ->trustedServers ->expects ($ this ->once ())->method ('isTrustedServer ' )
11492 ->with ('url ' )->willReturn ($ isTrustedServer );
@@ -117,7 +95,7 @@ public function testStart($isTrustedServer, $retainBackgroundJob): void {
11795 } else {
11896 $ requestSharedSecret ->expects ($ this ->never ())->method ('parentStart ' );
11997 }
120- $ this -> invokePrivate ($ requestSharedSecret , 'retainJob ' , [$ retainBackgroundJob ]);
98+ self :: invokePrivate ($ requestSharedSecret , 'retainJob ' , [$ retainBackgroundJob ]);
12199 $ this ->jobList ->expects ($ this ->once ())->method ('remove ' );
122100
123101 $ this ->timeFactory ->method ('getTime ' )->willReturn (42 );
@@ -141,7 +119,7 @@ public function testStart($isTrustedServer, $retainBackgroundJob): void {
141119 $ requestSharedSecret ->start ($ this ->jobList );
142120 }
143121
144- public function dataTestStart () {
122+ public static function dataTestStart (): array {
145123 return [
146124 [true , true ],
147125 [true , false ],
@@ -151,8 +129,6 @@ public function dataTestStart() {
151129
152130 /**
153131 * @dataProvider dataTestRun
154- *
155- * @param int $statusCode
156132 */
157133 public function testRun (int $ statusCode , int $ attempt = 0 ): void {
158134 $ target = 'targetURL ' ;
@@ -184,18 +160,18 @@ public function testRun(int $statusCode, int $attempt = 0): void {
184160 $ this ->response ->expects ($ this ->once ())->method ('getStatusCode ' )
185161 ->willReturn ($ statusCode );
186162
187- $ this -> invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
163+ self :: invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
188164 if (
189165 $ statusCode !== Http::STATUS_OK
190166 && ($ statusCode !== Http::STATUS_FORBIDDEN || $ attempt < 5 )
191167 ) {
192- $ this ->assertTrue ($ this -> invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
168+ $ this ->assertTrue (self :: invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
193169 } else {
194- $ this ->assertFalse ($ this -> invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
170+ $ this ->assertFalse (self :: invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
195171 }
196172 }
197173
198- public function dataTestRun () {
174+ public static function dataTestRun (): array {
199175 return [
200176 [Http::STATUS_OK ],
201177 [Http::STATUS_FORBIDDEN , 5 ],
@@ -231,7 +207,7 @@ public function testRunExpired(): void {
231207 TrustedServers::STATUS_FAILURE
232208 );
233209
234- $ this -> invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
210+ self :: invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
235211 }
236212
237213 public function testRunConnectionError (): void {
@@ -267,7 +243,7 @@ public function testRunConnectionError(): void {
267243 ]
268244 )->willThrowException ($ this ->createMock (ConnectException::class));
269245
270- $ this -> invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
271- $ this ->assertTrue ($ this -> invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
246+ self :: invokePrivate ($ this ->requestSharedSecret , 'run ' , [$ argument ]);
247+ $ this ->assertTrue (self :: invokePrivate ($ this ->requestSharedSecret , 'retainJob ' ));
272248 }
273249}
0 commit comments