Skip to content

Commit 18a7369

Browse files
Merge pull request #57020 from abhinavohri/fix_warnings
fix: Reduce deprecation warnings in phpunit_nodb CI jobs
2 parents 3e9d2fe + f89613b commit 18a7369

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

apps/dav/tests/unit/CalDAV/Integration/ExternalCalendarTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ protected function setUp(): void {
1818
parent::setUp();
1919

2020
$this->abstractExternalCalendar
21-
= $this->getMockForAbstractClass(ExternalCalendar::class, ['example-app-id', 'calendar-uri-in-backend']);
21+
= $this->getMockBuilder(ExternalCalendar::class)
22+
->setConstructorArgs(['example-app-id', 'calendar-uri-in-backend'])
23+
->getMock();
2224
}
2325

2426
public function testGetName():void {

apps/encryption/tests/Crypto/EncryptAllTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ protected function setUp(): void {
103103
$this->user2 = $this->createMock(IUser::class);
104104
$this->user2->method('getUID')->willReturn('user2');
105105

106-
$this->userManager->expects($this->any())->method('getSeenUsers')->will($this->returnCallback(function () {
106+
$this->userManager->expects($this->any())->method('getSeenUsers')->willReturnCallback(function () {
107107
yield $this->user1;
108108
yield $this->user2;
109-
}));
109+
});
110110
$this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->disableOriginalConstructor()->getMock();
111111
$this->secureRandom->expects($this->any())->method('generate')->willReturn('12345678');
112112

apps/files_external/tests/FrontendDefinitionTraitTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
use OCA\Files_External\Lib\FrontendDefinitionTrait;
1212
use OCA\Files_External\Lib\StorageConfig;
1313

14+
class MockFrontendDefinitionTraitClass {
15+
use FrontendDefinitionTrait;
16+
}
17+
1418
class FrontendDefinitionTraitTest extends \Test\TestCase {
1519
public function testJsonSerialization(): void {
1620
$param = $this->getMockBuilder(DefinitionParameter::class)
1721
->disableOriginalConstructor()
1822
->getMock();
1923
$param->method('getName')->willReturn('foo');
2024

21-
$trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
25+
$trait = new MockFrontendDefinitionTraitClass();
2226
$trait->setText('test');
2327
$trait->addParameters([$param]);
2428
$trait->addCustomJs('foo/bar.js');
@@ -67,7 +71,7 @@ public function testValidateStorage(bool $expectedSuccess, array $params): void
6771
$storageConfig->expects($this->any())
6872
->method('setBackendOption');
6973

70-
$trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
74+
$trait = new MockFrontendDefinitionTraitClass();
7175
$trait->setText('test');
7276
$trait->addParameters($backendParams);
7377

@@ -98,7 +102,7 @@ public function testValidateStorageSet(): void {
98102
->method('setBackendOption')
99103
->with('param', 'foobar');
100104

101-
$trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
105+
$trait = new MockFrontendDefinitionTraitClass();
102106
$trait->setText('test');
103107
$trait->addParameter($param);
104108

apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
1212
use OCA\Files_External\Lib\MissingDependency;
1313

14+
class MockLegacyDependencyCheckPolyfillClass {
15+
use LegacyDependencyCheckPolyfill;
16+
17+
public function getStorageClass(): string {
18+
return LegacyDependencyCheckPolyfillTest::class;
19+
}
20+
}
21+
1422
class LegacyDependencyCheckPolyfillTest extends \Test\TestCase {
1523

1624
/**
@@ -24,10 +32,7 @@ public static function checkDependencies(): array {
2432
}
2533

2634
public function testCheckDependencies(): void {
27-
$trait = $this->getMockForTrait(LegacyDependencyCheckPolyfill::class);
28-
$trait->expects($this->once())
29-
->method('getStorageClass')
30-
->willReturn(self::class);
35+
$trait = new MockLegacyDependencyCheckPolyfillClass();
3136

3237
$dependencies = $trait->checkDependencies();
3338
$this->assertCount(2, $dependencies);

apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testStatusCode(array $status, string $expected, bool $hasBody):
6666
$this->setupcheck
6767
->expects($this->once())
6868
->method('runRequest')
69-
->will($this->generate($responses));
69+
->willReturn($this->generate($responses));
7070

7171
$this->config
7272
->expects($this->once())
@@ -94,7 +94,7 @@ public function testNoResponse(): void {
9494
$this->setupcheck
9595
->expects($this->once())
9696
->method('runRequest')
97-
->will($this->generate([]));
97+
->willReturn($this->generate([]));
9898

9999
$this->config
100100
->expects($this->once())
@@ -110,8 +110,6 @@ public function testNoResponse(): void {
110110
* Helper function creates a nicer interface for mocking Generator behavior
111111
*/
112112
protected function generate(array $yield_values) {
113-
return $this->returnCallback(function () use ($yield_values) {
114-
yield from $yield_values;
115-
});
113+
yield from $yield_values;
116114
}
117115
}

apps/settings/tests/SetupChecks/OcxProvicersTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ public function testPartialInvalidResponse(): void {
144144
* Helper function creates a nicer interface for mocking Generator behavior
145145
*/
146146
protected function generate(array $yield_values) {
147-
return $this->returnCallback(function () use ($yield_values) {
148-
yield from $yield_values;
149-
});
147+
yield from $yield_values;
150148
}
151149
}

apps/settings/tests/SetupChecks/SecurityHeadersTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,13 @@ protected function setupResponse(int $statuscode, array $headers): void {
182182
$this->setupcheck
183183
->expects($this->atLeastOnce())
184184
->method('runRequest')
185-
->willReturnOnConsecutiveCalls($this->generate([$response]));
185+
->willReturn($this->generate([$response]));
186186
}
187187

188188
/**
189189
* Helper function creates a nicer interface for mocking Generator behavior
190190
*/
191191
protected function generate(array $yield_values) {
192-
return $this->returnCallback(function () use ($yield_values) {
193-
yield from $yield_values;
194-
});
192+
yield from $yield_values;
195193
}
196194
}

apps/settings/tests/SetupChecks/WellKnownUrlsTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testNoResponse(): void {
8787
$this->setupcheck
8888
->expects($this->once())
8989
->method('runRequest')
90-
->will($this->generate([]));
90+
->willReturn($this->generate([]));
9191

9292
$result = $this->setupcheck->run();
9393
$this->assertEquals(SetupResult::INFO, $result->getSeverity());
@@ -219,8 +219,6 @@ public static function dataTestResponses(): array {
219219
* Helper function creates a nicer interface for mocking Generator behavior
220220
*/
221221
protected function generate(array $yield_values) {
222-
return $this->returnCallback(function () use ($yield_values) {
223-
yield from $yield_values;
224-
});
222+
yield from $yield_values;
225223
}
226224
}

0 commit comments

Comments
 (0)