Skip to content
Merged
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
38 changes: 16 additions & 22 deletions apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Federation\ICloudIdManager;
use OCP\IDBConnection;
use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
Expand All @@ -24,20 +25,9 @@
*/
class CleanupRemoteStoragesTest extends TestCase {

/**
* @var CleanupRemoteStorages
*/
private $command;

/**
* @var IDBConnection
*/
private $connection;

/**
* @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject
*/
private $cloudIdManager;
protected IDBConnection $connection;
protected CleanupRemoteStorages $command;
private ICloudIdManager&MockObject $cloudIdManager;

private $storages = [
['id' => 'shared::7b4a322b22f9d0047c38d77d471ce3cf', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e1', 'remote' => 'https://hostname.tld/owncloud1', 'user' => 'user1'],
Expand Down Expand Up @@ -77,7 +67,7 @@ protected function setUp(): void {
foreach ($this->storages as &$storage) {
if (isset($storage['id'])) {
$storageQuery->setParameter('id', $storage['id']);
$storageQuery->execute();
$storageQuery->executeStatement();
$storage['numeric_id'] = $storageQuery->getLastInsertId();
}

Expand Down Expand Up @@ -121,13 +111,13 @@ protected function tearDown(): void {
foreach ($this->storages as $storage) {
if (isset($storage['id'])) {
$storageQuery->setParameter('id', $storage['id']);
$storageQuery->execute();
$storageQuery->executeStatement();
}

if (isset($storage['share_token'])) {
$shareExternalQuery->setParameter('share_token', $storage['share_token']);
$shareExternalQuery->setParameter('remote', $storage['remote']);
$shareExternalQuery->execute();
$shareExternalQuery->executeStatement();
}
}

Expand Down Expand Up @@ -174,14 +164,13 @@ public function testCleanup(): void {
->getMock();

// parent folder, `files`, ´test` and `welcome.txt` => 4 elements

$outputCalls = [];
$output
->expects($this->any())
->method('writeln')
->withConsecutive(
['5 remote storage(s) need(s) to be checked'],
['5 remote share(s) exist'],
);
->willReturnCallback(function (string $text) use (&$outputCalls) {
$outputCalls[] = $text;
});

$this->cloudIdManager
->expects($this->any())
Expand All @@ -206,5 +195,10 @@ public function testCleanup(): void {
$this->assertFalse($this->doesStorageExist($this->storages[3]['numeric_id']));
$this->assertTrue($this->doesStorageExist($this->storages[4]['numeric_id']));
$this->assertFalse($this->doesStorageExist($this->storages[5]['numeric_id']));

$this->assertEquals([
'5 remote storage(s) need(s) to be checked',
'5 remote share(s) exist',
], array_slice($outputCalls, 0, 2));
}
}
26 changes: 19 additions & 7 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1675,8 +1675,11 @@ public function testCanAccessRoomShare(bool $expected, IShare $share, bool $help
->with('spreed')
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
->setMethods(['canAccessShare'])
// This is not possible anymore with PHPUnit 10+
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
$helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['canAccessShare'])
->getMock();
$helper->method('canAccessShare')
->with($share, $this->currentUser)
Expand Down Expand Up @@ -2492,8 +2495,11 @@ public function testCreateShareRoom(): void {
->with('spreed')
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
->setMethods(['createShare'])
// This is not possible anymore with PHPUnit 10+
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
$helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
->with(
Expand Down Expand Up @@ -2598,7 +2604,10 @@ public function testCreateShareRoomHelperThrowException(): void {
->with('spreed')
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
// This is not possible anymore with PHPUnit 10+
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
$helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
Expand Down Expand Up @@ -5093,8 +5102,11 @@ public function testFormatRoomShare(array $expects, IShare $share, bool $helperA
->with('spreed')
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
->setMethods(['formatShare', 'canAccessShare'])
// This is not possible anymore with PHPUnit 10+
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
$helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['formatShare', 'canAccessShare'])
->getMock();
$helper->method('formatShare')
->with($share)
Expand Down
21 changes: 8 additions & 13 deletions apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,25 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class ShareInfoControllerTest extends TestCase {

/** @var ShareInfoController */
private $controller;

/** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
private $shareManager;
protected ShareInfoController $controller;
protected ShareManager&MockObject $shareManager;


protected function setUp(): void {
parent::setUp();

$this->shareManager = $this->createMock(ShareManager::class);

$this->controller = $this->getMockBuilder(ShareInfoController::class)
->setConstructorArgs([
'files_sharing',
$this->createMock(IRequest::class),
$this->shareManager
])
->setMethods(['addROWrapper'])
->getMock();
$this->controller = new ShareInfoController(
'files_sharing',
$this->createMock(IRequest::class),
$this->shareManager
);
}

public function testNoShare(): void {
Expand Down
66 changes: 21 additions & 45 deletions apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\OCS\IDiscoveryService;
use OCP\Server;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;

Expand All @@ -46,42 +47,19 @@
class ManagerTest extends TestCase {
use UserTrait;

/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $contactsManager;

/** @var Manager|\PHPUnit\Framework\MockObject\MockObject * */
private $manager;

/** @var \OC\Files\Mount\Manager */
private $mountManager;

/** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
private $clientService;

/** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
private $cloudFederationProviderManager;

/** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
private $cloudFederationFactory;

/** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
private $groupManager;

/** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
private $userManager;

/** @var LoggerInterface */
private $logger;

private $uid;

/**
* @var IUser
*/
private $user;
private $testMountProvider;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
protected string $uid;
protected IUser $user;
protected MountProvider $testMountProvider;
protected IEventDispatcher&MockObject $eventDispatcher;
protected LoggerInterface&MockObject $logger;
protected \OC\Files\Mount\Manager $mountManager;
protected IManager&MockObject $contactsManager;
protected Manager&MockObject $manager;
protected IClientService&MockObject $clientService;
protected ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
protected ICloudFederationFactory&MockObject $cloudFederationFactory;
protected IGroupManager&MockObject $groupManager;
protected IUserManager&MockObject $userManager;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -169,7 +147,7 @@ private function createManagerForUser($userId) {
$this->eventDispatcher,
$this->logger,
]
)->setMethods(['tryOCMEndPoint'])->getMock();
)->onlyMethods(['tryOCMEndPoint'])->getMock();
}

private function setupMounts() {
Expand Down Expand Up @@ -222,14 +200,12 @@ public function doTestAddShare($shareData1, $isGroup = false) {
if ($isGroup) {
$this->manager->expects($this->never())->method('tryOCMEndPoint');
} else {
$this->manager->method('tryOCMEndPoint')
->withConsecutive(
['http://localhost', 'token1', '2342', 'accept'],
['http://localhost', 'token3', '2342', 'decline'],
)->willReturnOnConsecutiveCalls(
false,
false,
);
$this->manager->expects(self::atLeast(2))
->method('tryOCMEndPoint')
->willReturnMap([
['http://localhost', 'token1', '2342', 'accept', false],
['http://localhost', 'token3', '2342', 'decline', false],
]);
}

// Add a share for "user"
Expand Down
Loading
Loading