diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-08-29 16:36:40 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-08-29 16:36:40 +0200 |
commit | 6f80fe6ada68cee35e714568afeb614238fbc241 (patch) | |
tree | eec7e8eb3742ec0e6b0463c290cb0cf146affca7 /tests/lib/Share20 | |
parent | 791e0214556c353d9c3ac9b2c54e465588c6af67 (diff) | |
download | nextcloud-server-6f80fe6ada68cee35e714568afeb614238fbc241.tar.gz nextcloud-server-6f80fe6ada68cee35e714568afeb614238fbc241.zip |
Remove deprecated at matcher from tests/lib
Only 15 warnings left in there
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 253 |
1 files changed, 111 insertions, 142 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 4e613d1cf5c..a7bb6cbcefc 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -248,22 +248,18 @@ class ManagerTest extends \Test\TestCase { ->method('delete') ->with($share); - $this->eventDispatcher->expects($this->at(0)) + $this->eventDispatcher->expects($this->exactly(2)) ->method('dispatch') - ->with( - 'OCP\Share::preUnshare', - $this->callBack(function (GenericEvent $e) use ($share) { - return $e->getSubject() === $share; - }) - ); - $this->eventDispatcher->expects($this->at(1)) - ->method('dispatch') - ->with( - 'OCP\Share::postUnshare', - $this->callBack(function (GenericEvent $e) use ($share) { - return $e->getSubject() === $share && - $e->getArgument('deletedShares') === [$share]; - }) + ->withConsecutive( + ['OCP\Share::preUnshare', + $this->callBack(function (GenericEvent $e) use ($share) { + return $e->getSubject() === $share; + })], + ['OCP\Share::postUnshare', + $this->callBack(function (GenericEvent $e) use ($share) { + return $e->getSubject() === $share && + $e->getArgument('deletedShares') === [$share]; + })] ); $manager->deleteShare($share); @@ -296,22 +292,18 @@ class ManagerTest extends \Test\TestCase { ->method('delete') ->with($share); - $this->eventDispatcher->expects($this->at(0)) - ->method('dispatch') - ->with( - 'OCP\Share::preUnshare', - $this->callBack(function (GenericEvent $e) use ($share) { - return $e->getSubject() === $share; - }) - ); - $this->eventDispatcher->expects($this->at(1)) + $this->eventDispatcher->expects($this->exactly(2)) ->method('dispatch') - ->with( - 'OCP\Share::postUnshare', - $this->callBack(function (GenericEvent $e) use ($share) { - return $e->getSubject() === $share && - $e->getArgument('deletedShares') === [$share]; - }) + ->withConsecutive( + ['OCP\Share::preUnshare', + $this->callBack(function (GenericEvent $e) use ($share) { + return $e->getSubject() === $share; + })], + ['OCP\Share::postUnshare', + $this->callBack(function (GenericEvent $e) use ($share) { + return $e->getSubject() === $share && + $e->getArgument('deletedShares') === [$share]; + })] ); $manager->deleteShare($share); @@ -365,22 +357,18 @@ class ManagerTest extends \Test\TestCase { ->method('delete') ->withConsecutive([$share3], [$share2], [$share1]); - $this->eventDispatcher->expects($this->at(0)) - ->method('dispatch') - ->with( - 'OCP\Share::preUnshare', - $this->callBack(function (GenericEvent $e) use ($share1) { - return $e->getSubject() === $share1; - }) - ); - $this->eventDispatcher->expects($this->at(1)) + $this->eventDispatcher->expects($this->exactly(2)) ->method('dispatch') - ->with( - 'OCP\Share::postUnshare', - $this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) { - return $e->getSubject() === $share1 && - $e->getArgument('deletedShares') === [$share3, $share2, $share1]; - }) + ->withConsecutive( + ['OCP\Share::preUnshare', + $this->callBack(function (GenericEvent $e) use ($share1) { + return $e->getSubject() === $share1; + })], + ['OCP\Share::postUnshare', + $this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) { + return $e->getSubject() === $share1 && + $e->getArgument('deletedShares') === [$share3, $share2, $share1]; + })] ); $manager->deleteShare($share1); @@ -408,7 +396,7 @@ class ManagerTest extends \Test\TestCase { ->method('deleteFromSelf') ->with($share, $recipientId); - $this->eventDispatcher->expects($this->at(0)) + $this->eventDispatcher->expects($this->once()) ->method('dispatch') ->with( 'OCP\Share::postUnshareFromSelf', @@ -2330,44 +2318,39 @@ class ManagerTest extends \Test\TestCase { return $share->setId(42); }); - // Pre share - $this->eventDispatcher->expects($this->at(0)) + $this->eventDispatcher->expects($this->exactly(2)) ->method('dispatch') - ->with( - $this->equalTo('OCP\Share::preShare'), - $this->callback(function (GenericEvent $e) use ($path, $date) { - /** @var IShare $share */ - $share = $e->getSubject(); - - return $share->getShareType() === IShare::TYPE_LINK && - $share->getNode() === $path && - $share->getSharedBy() === 'sharedBy' && - $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && - $share->getExpirationDate() === $date && - $share->getPassword() === 'hashed' && - $share->getToken() === 'token'; - }) - ); - - // Post share - $this->eventDispatcher->expects($this->at(1)) - ->method('dispatch') - ->with( - $this->equalTo('OCP\Share::postShare'), - $this->callback(function (GenericEvent $e) use ($path, $date) { - /** @var IShare $share */ - $share = $e->getSubject(); - - return $share->getShareType() === IShare::TYPE_LINK && - $share->getNode() === $path && - $share->getSharedBy() === 'sharedBy' && - $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && - $share->getExpirationDate() === $date && - $share->getPassword() === 'hashed' && - $share->getToken() === 'token' && - $share->getId() === '42' && - $share->getTarget() === '/target'; - }) + ->withConsecutive( + // Pre share + [$this->equalTo('OCP\Share::preShare'), + $this->callback(function (GenericEvent $e) use ($path, $date) { + /** @var IShare $share */ + $share = $e->getSubject(); + + return $share->getShareType() === IShare::TYPE_LINK && + $share->getNode() === $path && + $share->getSharedBy() === 'sharedBy' && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getExpirationDate() === $date && + $share->getPassword() === 'hashed' && + $share->getToken() === 'token'; + })], + // Post share + [$this->equalTo('OCP\Share::postShare'), + $this->callback(function (GenericEvent $e) use ($path, $date) { + /** @var IShare $share */ + $share = $e->getSubject(); + + return $share->getShareType() === IShare::TYPE_LINK && + $share->getNode() === $path && + $share->getSharedBy() === 'sharedBy' && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getExpirationDate() === $date && + $share->getPassword() === 'hashed' && + $share->getToken() === 'token' && + $share->getId() === '42' && + $share->getTarget() === '/target'; + })] ); /** @var IShare $share */ @@ -2442,44 +2425,37 @@ class ManagerTest extends \Test\TestCase { return $share->setId(42); }); - // Pre share - $this->eventDispatcher->expects($this->at(0)) - ->method('dispatch') - ->with( - $this->equalTo('OCP\Share::preShare'), - $this->callback(function (GenericEvent $e) use ($path) { - /** @var IShare $share */ - $share = $e->getSubject(); - - return $share->getShareType() === IShare::TYPE_EMAIL && - $share->getNode() === $path && - $share->getSharedBy() === 'sharedBy' && - $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && - $share->getExpirationDate() === null && - $share->getPassword() === null && - $share->getToken() === 'token'; - }) - ); - - // Post share - $this->eventDispatcher->expects($this->at(1)) + $this->eventDispatcher->expects($this->exactly(2)) ->method('dispatch') - ->with( - $this->equalTo('OCP\Share::postShare'), - $this->callback(function (GenericEvent $e) use ($path) { - /** @var IShare $share */ - $share = $e->getSubject(); - - return $share->getShareType() === IShare::TYPE_EMAIL && - $share->getNode() === $path && - $share->getSharedBy() === 'sharedBy' && - $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && - $share->getExpirationDate() === null && - $share->getPassword() === null && - $share->getToken() === 'token' && - $share->getId() === '42' && - $share->getTarget() === '/target'; - }) + ->withConsecutive( + [$this->equalTo('OCP\Share::preShare'), + $this->callback(function (GenericEvent $e) use ($path) { + /** @var IShare $share */ + $share = $e->getSubject(); + + return $share->getShareType() === IShare::TYPE_EMAIL && + $share->getNode() === $path && + $share->getSharedBy() === 'sharedBy' && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getExpirationDate() === null && + $share->getPassword() === null && + $share->getToken() === 'token'; + })], + [$this->equalTo('OCP\Share::postShare'), + $this->callback(function (GenericEvent $e) use ($path) { + /** @var IShare $share */ + $share = $e->getSubject(); + + return $share->getShareType() === IShare::TYPE_EMAIL && + $share->getNode() === $path && + $share->getSharedBy() === 'sharedBy' && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getExpirationDate() === null && + $share->getPassword() === null && + $share->getToken() === 'token' && + $share->getId() === '42' && + $share->getTarget() === '/target'; + })], ); /** @var IShare $share */ @@ -2868,23 +2844,21 @@ class ManagerTest extends \Test\TestCase { $share = $this->createMock(IShare::class); - $factory->expects($this->at(0)) - ->method('getProviderForType') - ->with(IShare::TYPE_LINK) - ->willReturn($this->defaultProvider); - $factory->expects($this->at(1)) + $factory->expects($this->exactly(2)) ->method('getProviderForType') - ->with(IShare::TYPE_REMOTE) + ->withConsecutive( + [IShare::TYPE_LINK], + [IShare::TYPE_REMOTE] + ) ->willReturn($this->defaultProvider); - $this->defaultProvider->expects($this->at(0)) + $this->defaultProvider->expects($this->exactly(2)) ->method('getShareByToken') ->with('token') - ->will($this->throwException(new ShareNotFound())); - $this->defaultProvider->expects($this->at(1)) - ->method('getShareByToken') - ->with('token') - ->willReturn($share); + ->willReturnOnConsecutiveCalls( + $this->throwException(new ShareNotFound()), + $share + ); $ret = $manager->getShareByToken('token'); $this->assertSame($share, $ret); @@ -2963,10 +2937,12 @@ class ManagerTest extends \Test\TestCase { public function testGetShareByTokenPublicUploadDisabled() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('core', 'shareapi_allow_links', 'yes') - ->willReturn('yes'); + ->willReturnMap([ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_allow_public_upload', 'yes', 'no'], + ]); $share = $this->manager->newShare(); $share->setShareType(IShare::TYPE_LINK) @@ -2975,13 +2951,6 @@ class ManagerTest extends \Test\TestCase { $folder = $this->createMock(\OC\Files\Node\Folder::class); $share->setNode($folder); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->willReturnMap([ - ['core', 'shareapi_allow_public_upload', 'yes', 'no'], - ]); - $this->defaultProvider->expects($this->once()) ->method('getShareByToken') ->willReturn('validToken') |