Skip to content

Commit

Permalink
fix(files_sharing): phpunit fixes
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jul 9, 2024
1 parent b0406a7 commit 3eb2316
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\Mail\IMailer;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -97,6 +99,8 @@ private function createOCS($userId) {
$previewManager = $this->createMock(IPreview::class);
$dateTimeZone = $this->createMock(IDateTimeZone::class);
$logger = $this->createMock(LoggerInterface::class);
$providerFactory = $this->createMock(IProviderFactory::class);
$mailer = $this->createMock(IMailer::class);
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));

return new ShareAPIController(
Expand All @@ -115,6 +119,8 @@ private function createOCS($userId) {
$previewManager,
$dateTimeZone,
$logger,
$providerFactory,
$mailer,
$userId,
);
}
Expand Down
26 changes: 25 additions & 1 deletion apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\Lock\LockedException;
use OCP\Mail\IMailer;
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\IAttributes as IShareAttributes;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -62,6 +64,8 @@ class ShareAPIControllerTest extends TestCase {
private IPreview|\PHPUnit\Framework\MockObject\MockObject $previewManager;
private IDateTimeZone|\PHPUnit\Framework\MockObject\MockObject $dateTimeZone;
private LoggerInterface $logger;
private IProviderFactory|\PHPUnit\Framework\MockObject\MockObject $factory;
private IMailer|\PHPUnit\Framework\MockObject\MockObject $mailer;

protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
Expand Down Expand Up @@ -95,6 +99,8 @@ protected function setUp(): void {
});
$this->dateTimeZone = $this->createMock(IDateTimeZone::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->factory = $this->createMock(IProviderFactory::class);
$this->mailer = $this->createMock(IMailer::class);

$this->ocs = new ShareAPIController(
$this->appName,
Expand All @@ -112,6 +118,8 @@ protected function setUp(): void {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
);
}
Expand All @@ -137,6 +145,8 @@ private function mockFormatShare() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand All @@ -152,7 +162,7 @@ private function mockShareAttributes() {
[
'scope' => 'permissions',
'key' => 'download',
'enabled' => true
'value' => true
]
];

Expand Down Expand Up @@ -739,6 +749,8 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,

])->setMethods(['canAccessShare'])
Expand Down Expand Up @@ -1371,6 +1383,8 @@ public function testGetShares(array $getSharesParameters, array $shares, array $
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down Expand Up @@ -1712,6 +1726,8 @@ public function testCreateShareUser() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down Expand Up @@ -1808,6 +1824,8 @@ public function testCreateShareGroup() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down Expand Up @@ -2228,6 +2246,8 @@ public function testCreateShareRemote() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down Expand Up @@ -2296,6 +2316,8 @@ public function testCreateShareRemoteGroup() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down Expand Up @@ -2537,6 +2559,8 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$this->previewManager,
$this->dateTimeZone,
$this->logger,
$this->factory,
$this->mailer,
$this->currentUser,
])->setMethods(['formatShare'])
->getMock();
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

/**
* Class DefaultShareProviderTest
Expand Down Expand Up @@ -68,6 +69,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var ITimeFactory|MockObject */
protected $timeFactory;

/** @var LoggerInterface|MockObject */
protected $logger;

protected function setUp(): void {
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->userManager = $this->createMock(IUserManager::class);
Expand All @@ -79,6 +83,7 @@ protected function setUp(): void {
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable("2023-05-04 00:00 Europe/Berlin"));
Expand All @@ -95,7 +100,8 @@ protected function setUp(): void {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory
$this->timeFactory,
$this->logger
);
}

Expand Down

0 comments on commit 3eb2316

Please sign in to comment.