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.
1415use OCP \Share \Exceptions \ShareNotFound ;
1516use OCP \Share \IManager ;
1617use OCP \Share \IShare ;
18+ use PHPUnit \Framework \MockObject \MockObject ;
1719
1820/**
1921 * Class LegacyPublicAuthTest
2325 * @package OCA\DAV\Tests\unit\Connector
2426 */
2527class LegacyPublicAuthTest extends \Test \TestCase {
26-
27- /** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
28- private $ session ;
29- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
30- private $ request ;
31- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
32- private $ shareManager ;
33- /** @var LegacyPublicAuth */
34- private $ auth ;
35- /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
36- private $ throttler ;
37-
38- /** @var string */
39- private $ oldUser ;
28+ private ISession &MockObject $ session ;
29+ private IRequest &MockObject $ request ;
30+ private IManager &MockObject $ shareManager ;
31+ private IThrottler &MockObject $ throttler ;
32+ private LegacyPublicAuth $ auth ;
33+ private string |false $ oldUser ;
4034
4135 protected function setUp (): void {
4236 parent ::setUp ();
4337
44- $ this ->session = $ this ->getMockBuilder (ISession::class)
45- ->disableOriginalConstructor ()
46- ->getMock ();
47- $ this ->request = $ this ->getMockBuilder (IRequest::class)
48- ->disableOriginalConstructor ()
49- ->getMock ();
50- $ this ->shareManager = $ this ->getMockBuilder (IManager::class)
51- ->disableOriginalConstructor ()
52- ->getMock ();
53- $ this ->throttler = $ this ->getMockBuilder (IThrottler::class)
54- ->disableOriginalConstructor ()
55- ->getMock ();
38+ $ this ->session = $ this ->createMock (ISession::class);
39+ $ this ->request = $ this ->createMock (IRequest::class);
40+ $ this ->shareManager = $ this ->createMock (IManager::class);
41+ $ this ->throttler = $ this ->createMock (IThrottler::class);
5642
5743 $ this ->auth = new LegacyPublicAuth (
5844 $ this ->request ,
@@ -70,7 +56,9 @@ protected function tearDown(): void {
7056
7157 // Set old user
7258 \OC_User::setUserId ($ this ->oldUser );
73- \OC_Util::setupFS ($ this ->oldUser );
59+ if ($ this ->oldUser !== false ) {
60+ \OC_Util::setupFS ($ this ->oldUser );
61+ }
7462
7563 parent ::tearDown ();
7664 }
@@ -86,9 +74,7 @@ public function testNoShare(): void {
8674 }
8775
8876 public function testShareNoPassword (): void {
89- $ share = $ this ->getMockBuilder (IShare::class)
90- ->disableOriginalConstructor ()
91- ->getMock ();
77+ $ share = $ this ->createMock (IShare::class);
9278 $ share ->method ('getPassword ' )->willReturn (null );
9379
9480 $ this ->shareManager ->expects ($ this ->once ())
@@ -101,9 +87,7 @@ public function testShareNoPassword(): void {
10187 }
10288
10389 public function testSharePasswordFancyShareType (): void {
104- $ share = $ this ->getMockBuilder (IShare::class)
105- ->disableOriginalConstructor ()
106- ->getMock ();
90+ $ share = $ this ->createMock (IShare::class);
10791 $ share ->method ('getPassword ' )->willReturn ('password ' );
10892 $ share ->method ('getShareType ' )->willReturn (42 );
10993
@@ -118,9 +102,7 @@ public function testSharePasswordFancyShareType(): void {
118102
119103
120104 public function testSharePasswordRemote (): void {
121- $ share = $ this ->getMockBuilder (IShare::class)
122- ->disableOriginalConstructor ()
123- ->getMock ();
105+ $ share = $ this ->createMock (IShare::class);
124106 $ share ->method ('getPassword ' )->willReturn ('password ' );
125107 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_REMOTE );
126108
@@ -134,9 +116,7 @@ public function testSharePasswordRemote(): void {
134116 }
135117
136118 public function testSharePasswordLinkValidPassword (): void {
137- $ share = $ this ->getMockBuilder (IShare::class)
138- ->disableOriginalConstructor ()
139- ->getMock ();
119+ $ share = $ this ->createMock (IShare::class);
140120 $ share ->method ('getPassword ' )->willReturn ('password ' );
141121 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_LINK );
142122
@@ -156,9 +136,7 @@ public function testSharePasswordLinkValidPassword(): void {
156136 }
157137
158138 public function testSharePasswordMailValidPassword (): void {
159- $ share = $ this ->getMockBuilder (IShare::class)
160- ->disableOriginalConstructor ()
161- ->getMock ();
139+ $ share = $ this ->createMock (IShare::class);
162140 $ share ->method ('getPassword ' )->willReturn ('password ' );
163141 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_EMAIL );
164142
@@ -178,9 +156,7 @@ public function testSharePasswordMailValidPassword(): void {
178156 }
179157
180158 public function testInvalidSharePasswordLinkValidSession (): void {
181- $ share = $ this ->getMockBuilder (IShare::class)
182- ->disableOriginalConstructor ()
183- ->getMock ();
159+ $ share = $ this ->createMock (IShare::class);
184160 $ share ->method ('getPassword ' )->willReturn ('password ' );
185161 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_LINK );
186162 $ share ->method ('getId ' )->willReturn ('42 ' );
@@ -204,9 +180,7 @@ public function testInvalidSharePasswordLinkValidSession(): void {
204180 }
205181
206182 public function testSharePasswordLinkInvalidSession (): void {
207- $ share = $ this ->getMockBuilder (IShare::class)
208- ->disableOriginalConstructor ()
209- ->getMock ();
183+ $ share = $ this ->createMock (IShare::class);
210184 $ share ->method ('getPassword ' )->willReturn ('password ' );
211185 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_LINK );
212186 $ share ->method ('getId ' )->willReturn ('42 ' );
@@ -231,9 +205,7 @@ public function testSharePasswordLinkInvalidSession(): void {
231205
232206
233207 public function testSharePasswordMailInvalidSession (): void {
234- $ share = $ this ->getMockBuilder (IShare::class)
235- ->disableOriginalConstructor ()
236- ->getMock ();
208+ $ share = $ this ->createMock (IShare::class);
237209 $ share ->method ('getPassword ' )->willReturn ('password ' );
238210 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_EMAIL );
239211 $ share ->method ('getId ' )->willReturn ('42 ' );
0 commit comments