Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions apps/encryption/tests/Crypto/EncryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
10 changes: 7 additions & 3 deletions apps/files_external/tests/FrontendDefinitionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
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)
->disableOriginalConstructor()
->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');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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;
}
}
4 changes: 1 addition & 3 deletions apps/settings/tests/SetupChecks/OcxProvicersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 2 additions & 4 deletions apps/settings/tests/SetupChecks/SecurityHeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 2 additions & 4 deletions apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
Loading