diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Command/Log/FileTest.php | 16 | ||||
-rw-r--r-- | tests/lib/Collaboration/Resources/ProviderManagerTest.php | 15 | ||||
-rw-r--r-- | tests/lib/DB/MigrationsTest.php | 39 | ||||
-rw-r--r-- | tests/lib/L10N/FactoryTest.php | 68 | ||||
-rw-r--r-- | tests/lib/Log/LogFactoryTest.php | 18 | ||||
-rw-r--r-- | tests/lib/OCS/ProviderTest.php | 49 | ||||
-rw-r--r-- | tests/lib/Security/IdentityProof/ManagerTest.php | 28 | ||||
-rw-r--r-- | tests/lib/Settings/ManagerTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Updater/ChangesCheckTest.php | 22 | ||||
-rw-r--r-- | tests/lib/User/AvailabilityCoordinatorTest.php | 11 |
10 files changed, 135 insertions, 135 deletions
diff --git a/tests/Core/Command/Log/FileTest.php b/tests/Core/Command/Log/FileTest.php index 9c7e0297d53..1286fca35a3 100644 --- a/tests/Core/Command/Log/FileTest.php +++ b/tests/Core/Command/Log/FileTest.php @@ -62,7 +62,7 @@ class FileTest extends TestCase { self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } - public function changeRotateSizeProvider() { + public static function changeRotateSizeProvider(): array { return [ ['42', 42], ['0', 0], @@ -96,13 +96,17 @@ class FileTest extends TestCase { ['log_rotate_size', 100 * 1024 * 1024, 5 * 1024 * 1024], ]); + $calls = [ + ['Log backend file: disabled'], + ['Log file: /var/log/nextcloud.log'], + ['Rotate at: 5 MB'], + ]; $this->consoleOutput->expects($this->exactly(3)) ->method('writeln') - ->withConsecutive( - ['Log backend file: disabled'], - ['Log file: /var/log/nextcloud.log'], - ['Rotate at: 5 MB'], - ); + ->willReturnCallback(function (string $message) use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected[0], $message); + }); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 01c201e0a4e..b063d89f06e 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -77,13 +77,14 @@ class ProviderManagerTest extends TestCase { public function testGetResourceProvidersValidAndInvalidProvider(): void { $this->serverContainer->expects($this->exactly(2)) ->method('query') - ->withConsecutive( - [$this->equalTo('InvalidResourceProvider')], - [$this->equalTo(ResourceProvider::class)], - )->willReturnOnConsecutiveCalls( - $this->throwException(new QueryException('A meaningful error message')), - $this->createMock(ResourceProvider::class), - ); + ->willReturnCallback(function (string $service) { + if ($service === 'InvalidResourceProvider') { + throw new QueryException('A meaningful error message'); + } + if ($service === ResourceProvider::class) { + return $this->createMock(ResourceProvider::class); + } + }); $this->logger->expects($this->once()) ->method('error'); diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 531e0a3805a..57ffb91e37e 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -93,7 +93,7 @@ class MigrationsTest extends \Test\TestCase { $this->expectExceptionMessage('Migration step \'X\' is unknown'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['findMigrations']) + ->onlyMethods(['findMigrations']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); $this->migrationService->expects($this->any())->method('findMigrations')->willReturn( @@ -134,7 +134,7 @@ class MigrationsTest extends \Test\TestCase { ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['createInstance']) + ->onlyMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); @@ -164,7 +164,7 @@ class MigrationsTest extends \Test\TestCase { ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['createInstance']) + ->onlyMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); @@ -191,7 +191,7 @@ class MigrationsTest extends \Test\TestCase { */ public function testGetMigration($alias, $expected): void { $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['getMigratedVersions', 'findMigrations']) + ->onlyMethods(['getMigratedVersions', 'findMigrations']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( @@ -211,22 +211,33 @@ class MigrationsTest extends \Test\TestCase { public function testMigrate(): void { $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['getMigratedVersions', 'findMigrations', 'executeStep']) + ->onlyMethods(['getMigratedVersions', 'findMigrations', 'executeStep']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); - $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( - ['20170130180000', '20170130180001'] - ); - $this->migrationService->expects($this->any())->method('findMigrations')->willReturn( - ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] - ); + $this->migrationService->method('getMigratedVersions') + ->willReturn( + ['20170130180000', '20170130180001'] + ); + $this->migrationService->method('findMigrations') + ->willReturn( + ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] + ); $this->assertEquals( ['20170130180000', '20170130180001', '20170130180002', '20170130180003'], - $this->migrationService->getAvailableVersions()); + $this->migrationService->getAvailableVersions() + ); - $this->migrationService->expects($this->exactly(2))->method('executeStep') - ->withConsecutive(['20170130180002'], ['20170130180003']); + $calls = [ + ['20170130180002', false], + ['20170130180003', false], + ]; + $this->migrationService->expects($this->exactly(2)) + ->method('executeStep') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $this->migrationService->migrate(); } diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index c29c31bf650..cd66217c49d 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -83,14 +83,14 @@ class FactoryTest extends TestCase { $this->serverRoot, $this->appManager, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); } return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot, $this->appManager); } - public function dataFindAvailableLanguages(): array { + public static function dataFindAvailableLanguages(): array { return [ [null], ['files'], @@ -124,24 +124,17 @@ class FactoryTest extends TestCase { $this->invokePrivate($factory, 'requestLanguage', ['de']); $factory->expects($this->exactly(2)) ->method('languageExists') - ->withConsecutive( - ['MyApp', 'de'], - ['MyApp', 'jp'], - ) - ->willReturnOnConsecutiveCalls( - false, - true, - ); + ->willReturnMap([ + ['MyApp', 'de', false], + ['MyApp', 'jp', true], + ]); $this->config ->expects($this->exactly(1)) ->method('getSystemValue') - ->withConsecutive( - ['force_language', false], - )->willReturnOnConsecutiveCalls( - false, - ); - $user = $this->getMockBuilder(IUser::class) - ->getMock(); + ->willReturnMap([ + ['force_language', false, false], + ]); + $user = $this->createMock(IUser::class); $user->expects(self::once()) ->method('getUID') ->willReturn('MyUserUid'); @@ -175,8 +168,7 @@ class FactoryTest extends TestCase { ['force_language', false, false], ['default_language', false, 'es'] ]); - $user = $this->getMockBuilder(IUser::class) - ->getMock(); + $user = $this->createMock(IUser::class); $user->expects(self::once()) ->method('getUID') ->willReturn('MyUserUid'); @@ -210,8 +202,7 @@ class FactoryTest extends TestCase { ['force_language', false, false], ['default_language', false, 'es'] ]); - $user = $this->getMockBuilder(IUser::class) - ->getMock(); + $user = $this->createMock(IUser::class); $user->expects(self::once()) ->method('getUID') ->willReturn('MyUserUid'); @@ -248,8 +239,7 @@ class FactoryTest extends TestCase { ['force_language', false, false], ['default_language', false, 'es'] ]); - $user = $this->getMockBuilder(IUser::class) - ->getMock(); + $user = $this->createMock(IUser::class); $user->expects(self::once()) ->method('getUID') ->willReturn('MyUserUid'); @@ -302,7 +292,7 @@ class FactoryTest extends TestCase { self::assertEqualsCanonicalizing(['cs', 'de', 'en', 'ru'], $factory->findAvailableLanguages($app)); } - public function dataLanguageExists(): array { + public static function dataLanguageExists(): array { return [ [null, 'en', [], true], [null, 'de', [], false], @@ -351,7 +341,7 @@ class FactoryTest extends TestCase { self::assertSame($expected, $factory->languageExists($app, $lang)); } - public function dataSetLanguageFromRequest(): array { + public static function dataSetLanguageFromRequest(): array { return [ // Language is available [null, 'de', ['de'], 'de'], @@ -406,7 +396,7 @@ class FactoryTest extends TestCase { } } - public function dataGetL10nFilesForApp(): array { + public static function dataGetL10nFilesForApp(): array { return [ ['', 'de', [\OC::$SERVERROOT . '/core/l10n/de.json']], ['core', 'ru', [\OC::$SERVERROOT . '/core/l10n/ru.json']], @@ -440,7 +430,7 @@ class FactoryTest extends TestCase { self::assertSame($expected, $this->invokePrivate($factory, 'getL10nFilesForApp', [$app, $lang])); } - public function dataFindL10NDir(): array { + public static function dataFindL10NDir(): array { return [ ['', \OC::$SERVERROOT . '/core/l10n/'], ['core', \OC::$SERVERROOT . '/core/l10n/'], @@ -473,7 +463,7 @@ class FactoryTest extends TestCase { self::assertSame($expected, $this->invokePrivate($factory, 'findL10nDir', [$app])); } - public function dataFindLanguage(): array { + public static function dataFindLanguage(): array { return [ // Not logged in [false, [], 'en'], @@ -511,8 +501,7 @@ class FactoryTest extends TestCase { }); if ($loggedIn) { - $user = $this->getMockBuilder(IUser::class) - ->getMock(); + $user = $this->createMock(IUser::class); $user->expects(self::any()) ->method('getUID') ->willReturn('MyUserUid'); @@ -670,7 +659,7 @@ class FactoryTest extends TestCase { self::assertSame('en', $lang); } - public function dataTestRespectDefaultLanguage(): array { + public static function dataTestRespectDefaultLanguage(): array { return [ ['de', 'de_DE', true, 'de_DE'], ['de', 'de', true, 'de'], @@ -747,21 +736,22 @@ class FactoryTest extends TestCase { self::assertEqualsCanonicalizing($expected, $commonLanguagesCodes); } - public function languageIteratorRequestProvider():array { + public static function languageIteratorRequestProvider(): array { return [ - [ true, $this->createMock(IUser::class)], - [ false, $this->createMock(IUser::class)], - [ false, null] + [ true, true], + [ false, true], + [ false, false], ]; } /** * @dataProvider languageIteratorRequestProvider */ - public function testGetLanguageIterator(bool $hasSession, ?IUser $iUserMock = null): void { + public function testGetLanguageIterator(bool $hasSession, bool $mockUser): void { $factory = $this->getFactory(); + $user = null; - if ($iUserMock === null) { + if (!$mockUser) { $matcher = $this->userSession->expects(self::once()) ->method('getUser'); @@ -770,9 +760,11 @@ class FactoryTest extends TestCase { } else { $this->expectException(\RuntimeException::class); } + } else { + $user = $this->createMock(IUser::class); } - $iterator = $factory->getLanguageIterator($iUserMock); + $iterator = $factory->getLanguageIterator($user); self::assertInstanceOf(ILanguageIterator::class, $iterator); } diff --git a/tests/lib/Log/LogFactoryTest.php b/tests/lib/Log/LogFactoryTest.php index 6219fd438f7..1d87c856061 100644 --- a/tests/lib/Log/LogFactoryTest.php +++ b/tests/lib/Log/LogFactoryTest.php @@ -39,7 +39,7 @@ class LogFactoryTest extends TestCase { $this->factory = new LogFactory($this->c, $this->systemConfig); } - public function fileTypeProvider(): array { + public static function fileTypeProvider(): array { return [ [ 'file' @@ -67,14 +67,17 @@ class LogFactoryTest extends TestCase { $this->systemConfig->expects($this->exactly(3)) ->method('getValue') - ->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640]) - ->willReturnOnConsecutiveCalls($datadir, $defaultLog, 0640); + ->willReturnMap([ + ['datadirectory', $datadir, $datadir], + ['logfile', $defaultLog, $defaultLog], + ['logfilemode', 0640, 0640], + ]); $log = $this->factory->get($type); $this->assertInstanceOf(File::class, $log); } - public function logFilePathProvider():array { + public static function logFilePathProvider():array { return [ [ '/dev/null', @@ -97,8 +100,11 @@ class LogFactoryTest extends TestCase { $this->systemConfig->expects($this->exactly(3)) ->method('getValue') - ->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640]) - ->willReturnOnConsecutiveCalls($datadir, $path, 0640); + ->willReturnMap([ + ['datadirectory', $datadir, $datadir], + ['logfile', $defaultLog, $path], + ['logfilemode', 0640, 0640], + ]); $log = $this->factory->get('file'); $this->assertInstanceOf(File::class, $log); diff --git a/tests/lib/OCS/ProviderTest.php b/tests/lib/OCS/ProviderTest.php index 3834c1d613e..ce028ce764a 100644 --- a/tests/lib/OCS/ProviderTest.php +++ b/tests/lib/OCS/ProviderTest.php @@ -29,13 +29,12 @@ class ProviderTest extends \Test\TestCase { $this->appManager ->expects($this->exactly(4)) ->method('isEnabledForUser') - ->withConsecutive( - ['files_sharing'], - ['federation'], - ['activity'], - ['provisioning_api'] - ) - ->willReturn(false); + ->willReturnMap([ + ['files_sharing', null, false], + ['federation', null, false], + ['activity', null, false], + ['provisioning_api', null, false], + ]); $expected = new \OCP\AppFramework\Http\JSONResponse( [ @@ -60,18 +59,12 @@ class ProviderTest extends \Test\TestCase { $this->appManager ->expects($this->exactly(4)) ->method('isEnabledForUser') - ->withConsecutive( - ['files_sharing'], - ['federation'], - ['activity'], - ['provisioning_api'] - ) - ->willReturnOnConsecutiveCalls( - true, - false, - false, - false - ); + ->willReturnMap([ + ['files_sharing', null, true], + ['federation', null, false], + ['activity', null, false], + ['provisioning_api', null, false], + ]); $expected = new \OCP\AppFramework\Http\JSONResponse( [ @@ -109,18 +102,12 @@ class ProviderTest extends \Test\TestCase { $this->appManager ->expects($this->exactly(4)) ->method('isEnabledForUser') - ->withConsecutive( - ['files_sharing'], - ['federation'], - ['activity'], - ['provisioning_api'] - ) - ->willReturnOnConsecutiveCalls( - false, - true, - false, - false - ); + ->willReturnMap([ + ['files_sharing', null, false], + ['federation', null, true], + ['activity', null, false], + ['provisioning_api', null, false], + ]); $expected = new \OCP\AppFramework\Http\JSONResponse( [ diff --git a/tests/lib/Security/IdentityProof/ManagerTest.php b/tests/lib/Security/IdentityProof/ManagerTest.php index 722555efe01..445158e8a23 100644 --- a/tests/lib/Security/IdentityProof/ManagerTest.php +++ b/tests/lib/Security/IdentityProof/ManagerTest.php @@ -75,7 +75,9 @@ class ManagerTest extends TestCase { $this->crypto, $this->config, $this->logger - ])->setMethods($setMethods)->getMock(); + ]) + ->onlyMethods($setMethods) + ->getMock(); } } @@ -104,14 +106,10 @@ class ManagerTest extends TestCase { $folder ->expects($this->exactly(2)) ->method('getFile') - ->withConsecutive( - ['private'], - ['public'] - ) - ->willReturnOnConsecutiveCalls( - $privateFile, - $publicFile - ); + ->willReturnMap([ + ['private', $privateFile], + ['public', $publicFile], + ]); $this->appData ->expects($this->once()) ->method('getFolder') @@ -155,14 +153,10 @@ class ManagerTest extends TestCase { $folder ->expects($this->exactly(2)) ->method('newFile') - ->withConsecutive( - ['private'], - ['public'] - ) - ->willReturnOnConsecutiveCalls( - $privateFile, - $publicFile - ); + ->willReturnMap([ + ['private', null, $privateFile], + ['public', null, $publicFile], + ]); $this->appData ->expects($this->exactly(2)) ->method('getFolder') diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 90c195e6bd0..38b0262bb55 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -178,10 +178,6 @@ class ManagerTest extends TestCase { $this->container->expects($this->exactly(2)) ->method('get') - ->withConsecutive( - ['section1'], - ['section2'] - ) ->willReturnMap([ ['section1', $section], ['section2', $section2], diff --git a/tests/lib/Updater/ChangesCheckTest.php b/tests/lib/Updater/ChangesCheckTest.php index 81eaa95d1fe..4b0c54b0881 100644 --- a/tests/lib/Updater/ChangesCheckTest.php +++ b/tests/lib/Updater/ChangesCheckTest.php @@ -42,7 +42,7 @@ class ChangesCheckTest extends TestCase { $this->checker = new ChangesCheck($this->clientService, $this->mapper, $this->logger); } - public function statusCodeProvider():array { + public static function statusCodeProvider(): array { return [ [200, ChangesCheck::RESPONSE_HAS_CONTENT], [304, ChangesCheck::RESPONSE_USE_CACHE], @@ -74,8 +74,10 @@ class ChangesCheckTest extends TestCase { $entry = $this->createMock(Changes::class); $entry->expects($this->exactly(2)) ->method('__call') - ->withConsecutive(['getVersion'], ['setVersion', [$version]]) - ->willReturnOnConsecutiveCalls('', null); + ->willReturnMap([ + ['getVersion', [], ''], + ['setVersion', [$version], null], + ]); $this->mapper->expects($this->once()) ->method('insert'); @@ -100,7 +102,7 @@ class ChangesCheckTest extends TestCase { $this->invokePrivate($this->checker, 'cacheResult', [$entry, $version]); } - public function changesXMLProvider(): array { + public static function changesXMLProvider(): array { return [ [ # 0 - full example '<?xml version="1.0" encoding="utf-8" ?> @@ -277,7 +279,7 @@ class ChangesCheckTest extends TestCase { $this->assertSame($expected, $actual); } - public function etagProvider() { + public static function etagProvider() { return [ [''], ['a27aab83d8205d73978435076e53d143'] @@ -310,7 +312,7 @@ class ChangesCheckTest extends TestCase { $this->assertInstanceOf(IResponse::class, $response); } - public function versionProvider(): array { + public static function versionProvider(): array { return [ ['13.0.7', '13.0.7'], ['13.0.7.3', '13.0.7'], @@ -329,12 +331,12 @@ class ChangesCheckTest extends TestCase { $this->assertSame($expected, $normalized); } - public function changeDataProvider():array { - $testDataFound = $testDataNotFound = $this->versionProvider(); - array_walk($testDataFound, function (&$params) { + public static function changeDataProvider():array { + $testDataFound = $testDataNotFound = self::versionProvider(); + array_walk($testDataFound, static function (&$params) { $params[] = true; }); - array_walk($testDataNotFound, function (&$params) { + array_walk($testDataNotFound, static function (&$params) { $params[] = false; }); return array_merge($testDataFound, $testDataNotFound); diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php index 8b9446279a6..09c1528912b 100644 --- a/tests/lib/User/AvailabilityCoordinatorTest.php +++ b/tests/lib/User/AvailabilityCoordinatorTest.php @@ -88,10 +88,17 @@ class AvailabilityCoordinatorTest extends TestCase { ->method('getAbsence') ->with($user->getUID()) ->willReturn($absence); + + $calls = [ + [$user->getUID() . '_timezone', 'Europe/Berlin', 3600], + [$user->getUID(), '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation","replacementUserId":"batman","replacementUserDisplayName":"Bruce Wayne"}', 300], + ]; $this->cache->expects(self::exactly(2)) ->method('set') - ->withConsecutive([$user->getUID() . '_timezone', 'Europe/Berlin', 3600], - [$user->getUID(), '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation","replacementUserId":"batman","replacementUserDisplayName":"Bruce Wayne"}', 300]); + ->willReturnCallback(static function () use (&$calls): void { + $expected = array_shift($calls); + self::assertEquals($expected, func_get_args()); + }); $expected = new OutOfOfficeData( '420', |