diff options
Diffstat (limited to 'apps/settings/tests/UserMigration/AccountMigratorTest.php')
-rw-r--r-- | apps/settings/tests/UserMigration/AccountMigratorTest.php | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/apps/settings/tests/UserMigration/AccountMigratorTest.php b/apps/settings/tests/UserMigration/AccountMigratorTest.php index ab5ffc6b314..b8f8301f777 100644 --- a/apps/settings/tests/UserMigration/AccountMigratorTest.php +++ b/apps/settings/tests/UserMigration/AccountMigratorTest.php @@ -12,7 +12,9 @@ use OCA\Settings\UserMigration\AccountMigrator; use OCP\Accounts\IAccountManager; use OCP\AppFramework\App; use OCP\IAvatarManager; +use OCP\IConfig; use OCP\IUserManager; +use OCP\Server; use OCP\UserMigration\IExportDestination; use OCP\UserMigration\IImportSource; use PHPUnit\Framework\Constraint\JsonMatches; @@ -25,21 +27,12 @@ use Test\TestCase; * @group DB */ class AccountMigratorTest extends TestCase { - private IUserManager $userManager; - private IAvatarManager $avatarManager; - private AccountMigrator $migrator; - - /** @var IImportSource|MockObject */ - private $importSource; - - /** @var IExportDestination|MockObject */ - private $exportDestination; - - /** @var OutputInterface|MockObject */ - private $output; + private IImportSource&MockObject $importSource; + private IExportDestination&MockObject $exportDestination; + private OutputInterface&MockObject $output; private const ASSETS_DIR = __DIR__ . '/assets/'; @@ -50,8 +43,11 @@ class AccountMigratorTest extends TestCase { private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/'; protected function setUp(): void { + parent::setUp(); + $app = new App(Application::APP_ID); $container = $app->getContainer(); + $container->get(IConfig::class)->setSystemValue('has_internet_connection', false); $this->userManager = $container->get(IUserManager::class); $this->avatarManager = $container->get(IAvatarManager::class); @@ -62,9 +58,14 @@ class AccountMigratorTest extends TestCase { $this->output = $this->createMock(OutputInterface::class); } - public function dataImportExportAccount(): array { + protected function tearDown(): void { + Server::get(IConfig::class)->setSystemValue('has_internet_connection', true); + parent::tearDown(); + } + + public static function dataImportExportAccount(): array { return array_map( - function (string $filename) { + static function (string $filename): array { $dataPath = static::ASSETS_DIR . $filename; // For each account json file there is an avatar image and a config json file with the same basename $basename = pathinfo($filename, PATHINFO_FILENAME); @@ -84,9 +85,7 @@ class AccountMigratorTest extends TestCase { ); } - /** - * @dataProvider dataImportExportAccount - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataImportExportAccount')] public function testImportExportAccount(string $userId, array $importData, string $avatarPath, array $importConfig): void { $user = $this->userManager->createUser($userId, 'topsecretpassword'); $avatarExt = pathinfo($avatarPath, PATHINFO_EXTENSION); @@ -101,17 +100,18 @@ class AccountMigratorTest extends TestCase { ->with($this->migrator->getId()) ->willReturn(1); + $calls = [ + [static::REGEX_ACCOUNT_FILE, json_encode($importData)], + [static::REGEX_CONFIG_FILE, json_encode($importConfig)], + ]; $this->importSource ->expects($this->exactly(2)) ->method('getFileContents') - ->withConsecutive( - [$this->matchesRegularExpression(static::REGEX_ACCOUNT_FILE)], - [$this->matchesRegularExpression(static::REGEX_CONFIG_FILE)], - ) - ->willReturnOnConsecutiveCalls( - json_encode($importData), - json_encode($importConfig), - ); + ->willReturnCallback(function ($path) use (&$calls) { + $expected = array_shift($calls); + $this->assertMatchesRegularExpression($expected[0], $path); + return $expected[1]; + }); $this->importSource ->expects($this->once()) @@ -142,13 +142,18 @@ class AccountMigratorTest extends TestCase { ); } + $calls = [ + [static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))], + [static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))], + ]; $this->exportDestination ->expects($this->exactly(2)) ->method('addFileContents') - ->withConsecutive( - [$this->matchesRegularExpression(static::REGEX_ACCOUNT_FILE), new JsonMatches(json_encode($exportData))], - [$this->matchesRegularExpression(static::REGEX_CONFIG_FILE), new JsonMatches(json_encode($exportConfig))], - ); + ->willReturnCallback(function ($path) use (&$calls) { + $expected = array_shift($calls); + $this->assertMatchesRegularExpression($expected[0], $path); + return $expected[1]; + }); $this->exportDestination ->expects($this->once()) |