diff --git a/apps/dav/tests/unit/CalDAV/Integration/ExternalCalendarTest.php b/apps/dav/tests/unit/CalDAV/Integration/ExternalCalendarTest.php index b2f479ac0e371..9bb761350a482 100644 --- a/apps/dav/tests/unit/CalDAV/Integration/ExternalCalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/Integration/ExternalCalendarTest.php @@ -18,7 +18,9 @@ protected function setUp(): void { parent::setUp(); $this->abstractExternalCalendar - = $this->getMockForAbstractClass(ExternalCalendar::class, ['example-app-id', 'calendar-uri-in-backend']); + = $this->getMockBuilder(ExternalCalendar::class) + ->setConstructorArgs(['example-app-id', 'calendar-uri-in-backend']) + ->getMock(); } public function testGetName():void { diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index 17af5dc52b4b1..8d8bc9867cae5 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -103,10 +103,10 @@ protected function setUp(): void { $this->user2 = $this->createMock(IUser::class); $this->user2->method('getUID')->willReturn('user2'); - $this->userManager->expects($this->any())->method('getSeenUsers')->will($this->returnCallback(function () { + $this->userManager->expects($this->any())->method('getSeenUsers')->willReturnCallback(function () { yield $this->user1; yield $this->user2; - })); + }); $this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->disableOriginalConstructor()->getMock(); $this->secureRandom->expects($this->any())->method('generate')->willReturn('12345678'); diff --git a/apps/files_external/tests/FrontendDefinitionTraitTest.php b/apps/files_external/tests/FrontendDefinitionTraitTest.php index e0bf066e70a17..afab9aa46e855 100644 --- a/apps/files_external/tests/FrontendDefinitionTraitTest.php +++ b/apps/files_external/tests/FrontendDefinitionTraitTest.php @@ -11,6 +11,10 @@ use OCA\Files_External\Lib\FrontendDefinitionTrait; use OCA\Files_External\Lib\StorageConfig; +class MockFrontendDefinitionTraitClass { + use FrontendDefinitionTrait; +} + class FrontendDefinitionTraitTest extends \Test\TestCase { public function testJsonSerialization(): void { $param = $this->getMockBuilder(DefinitionParameter::class) @@ -18,7 +22,7 @@ public function testJsonSerialization(): void { ->getMock(); $param->method('getName')->willReturn('foo'); - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); + $trait = new MockFrontendDefinitionTraitClass(); $trait->setText('test'); $trait->addParameters([$param]); $trait->addCustomJs('foo/bar.js'); @@ -67,7 +71,7 @@ public function testValidateStorage(bool $expectedSuccess, array $params): void $storageConfig->expects($this->any()) ->method('setBackendOption'); - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); + $trait = new MockFrontendDefinitionTraitClass(); $trait->setText('test'); $trait->addParameters($backendParams); @@ -98,7 +102,7 @@ public function testValidateStorageSet(): void { ->method('setBackendOption') ->with('param', 'foobar'); - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); + $trait = new MockFrontendDefinitionTraitClass(); $trait->setText('test'); $trait->addParameter($param); diff --git a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php index d26aa752ea123..3edefe5188bc1 100644 --- a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php +++ b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php @@ -11,6 +11,14 @@ use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; use OCA\Files_External\Lib\MissingDependency; +class MockLegacyDependencyCheckPolyfillClass { + use LegacyDependencyCheckPolyfill; + + public function getStorageClass(): string { + return LegacyDependencyCheckPolyfillTest::class; + } +} + class LegacyDependencyCheckPolyfillTest extends \Test\TestCase { /** @@ -24,10 +32,7 @@ public static function checkDependencies(): array { } public function testCheckDependencies(): void { - $trait = $this->getMockForTrait(LegacyDependencyCheckPolyfill::class); - $trait->expects($this->once()) - ->method('getStorageClass') - ->willReturn(self::class); + $trait = new MockLegacyDependencyCheckPolyfillClass(); $dependencies = $trait->checkDependencies(); $this->assertCount(2, $dependencies); diff --git a/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php index c20c78c6e1630..cdf69ae612d3e 100644 --- a/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php +++ b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php @@ -66,7 +66,7 @@ public function testStatusCode(array $status, string $expected, bool $hasBody): $this->setupcheck ->expects($this->once()) ->method('runRequest') - ->will($this->generate($responses)); + ->willReturn($this->generate($responses)); $this->config ->expects($this->once()) @@ -94,7 +94,7 @@ public function testNoResponse(): void { $this->setupcheck ->expects($this->once()) ->method('runRequest') - ->will($this->generate([])); + ->willReturn($this->generate([])); $this->config ->expects($this->once()) @@ -110,8 +110,6 @@ public function testNoResponse(): void { * Helper function creates a nicer interface for mocking Generator behavior */ protected function generate(array $yield_values) { - return $this->returnCallback(function () use ($yield_values) { - yield from $yield_values; - }); + yield from $yield_values; } } diff --git a/apps/settings/tests/SetupChecks/OcxProvicersTest.php b/apps/settings/tests/SetupChecks/OcxProvicersTest.php index 8e5a2c1b88b2e..65afa1813079d 100644 --- a/apps/settings/tests/SetupChecks/OcxProvicersTest.php +++ b/apps/settings/tests/SetupChecks/OcxProvicersTest.php @@ -144,8 +144,6 @@ public function testPartialInvalidResponse(): void { * Helper function creates a nicer interface for mocking Generator behavior */ protected function generate(array $yield_values) { - return $this->returnCallback(function () use ($yield_values) { - yield from $yield_values; - }); + yield from $yield_values; } } diff --git a/apps/settings/tests/SetupChecks/SecurityHeadersTest.php b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php index 1f75907d42712..e5d32ef7ecfc0 100644 --- a/apps/settings/tests/SetupChecks/SecurityHeadersTest.php +++ b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php @@ -182,15 +182,13 @@ protected function setupResponse(int $statuscode, array $headers): void { $this->setupcheck ->expects($this->atLeastOnce()) ->method('runRequest') - ->willReturnOnConsecutiveCalls($this->generate([$response])); + ->willReturn($this->generate([$response])); } /** * Helper function creates a nicer interface for mocking Generator behavior */ protected function generate(array $yield_values) { - return $this->returnCallback(function () use ($yield_values) { - yield from $yield_values; - }); + yield from $yield_values; } } diff --git a/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php index 06675f658c8bf..c3311200303dc 100644 --- a/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php +++ b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php @@ -87,7 +87,7 @@ public function testNoResponse(): void { $this->setupcheck ->expects($this->once()) ->method('runRequest') - ->will($this->generate([])); + ->willReturn($this->generate([])); $result = $this->setupcheck->run(); $this->assertEquals(SetupResult::INFO, $result->getSeverity()); @@ -219,8 +219,6 @@ public static function dataTestResponses(): array { * Helper function creates a nicer interface for mocking Generator behavior */ protected function generate(array $yield_values) { - return $this->returnCallback(function () use ($yield_values) { - yield from $yield_values; - }); + yield from $yield_values; } }