aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Command
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Command')
-rw-r--r--tests/lib/Command/AsyncBusTestCase.php (renamed from tests/lib/Command/AsyncBusTest.php)66
-rw-r--r--tests/lib/Command/BackgroundJobsTest.php57
-rw-r--r--tests/lib/Command/BackgroundModeTest.php60
-rw-r--r--tests/lib/Command/CronBusTest.php30
-rw-r--r--tests/lib/Command/Integrity/SignAppTest.php252
-rw-r--r--tests/lib/Command/Integrity/SignCoreTest.php199
6 files changed, 290 insertions, 374 deletions
diff --git a/tests/lib/Command/AsyncBusTest.php b/tests/lib/Command/AsyncBusTestCase.php
index bfe201ed369..bb47de30b11 100644
--- a/tests/lib/Command/AsyncBusTest.php
+++ b/tests/lib/Command/AsyncBusTestCase.php
@@ -1,10 +1,9 @@
<?php
/**
- * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Command;
@@ -16,19 +15,18 @@ use Test\TestCase;
class SimpleCommand implements ICommand {
public function handle() {
- AsyncBusTest::$lastCommand = 'SimpleCommand';
+ AsyncBusTestCase::$lastCommand = 'SimpleCommand';
}
}
class StateFullCommand implements ICommand {
- private $state;
-
- public function __construct($state) {
- $this->state = $state;
+ public function __construct(
+ private $state,
+ ) {
}
public function handle() {
- AsyncBusTest::$lastCommand = $this->state;
+ AsyncBusTestCase::$lastCommand = $this->state;
}
}
@@ -36,28 +34,28 @@ class FilesystemCommand implements ICommand {
use FileAccess;
public function handle() {
- AsyncBusTest::$lastCommand = 'FileAccess';
+ AsyncBusTestCase::$lastCommand = 'FileAccess';
}
}
function basicFunction() {
- AsyncBusTest::$lastCommand = 'function';
+ AsyncBusTestCase::$lastCommand = 'function';
}
// clean class to prevent phpunit putting closure in $this
class ThisClosureTest {
private function privateMethod() {
- AsyncBusTest::$lastCommand = 'closure-this';
+ AsyncBusTestCase::$lastCommand = 'closure-this';
}
public function test(IBus $bus) {
- $bus->push(function () {
+ $bus->push(function (): void {
$this->privateMethod();
});
}
}
-abstract class AsyncBusTest extends TestCase {
+abstract class AsyncBusTestCase extends TestCase {
/**
* Basic way to check output from a command
*
@@ -66,7 +64,7 @@ abstract class AsyncBusTest extends TestCase {
public static $lastCommand;
/**
- * @var \OCP\Command\IBus
+ * @var IBus
*/
private $bus;
@@ -93,57 +91,57 @@ abstract class AsyncBusTest extends TestCase {
self::$lastCommand = '';
}
- public function testSimpleCommand() {
+ public function testSimpleCommand(): void {
$command = new SimpleCommand();
$this->getBus()->push($command);
$this->runJobs();
$this->assertEquals('SimpleCommand', self::$lastCommand);
}
- public function testStateFullCommand() {
+ public function testStateFullCommand(): void {
$command = new StateFullCommand('foo');
$this->getBus()->push($command);
$this->runJobs();
$this->assertEquals('foo', self::$lastCommand);
}
- public function testStaticCallable() {
- $this->getBus()->push(['\Test\Command\AsyncBusTest', 'DummyCommand']);
+ public function testStaticCallable(): void {
+ $this->getBus()->push(['\Test\Command\AsyncBusTestCase', 'DummyCommand']);
$this->runJobs();
$this->assertEquals('static', self::$lastCommand);
}
- public function testMemberCallable() {
+ public function testMemberCallable(): void {
$command = new StateFullCommand('bar');
$this->getBus()->push([$command, 'handle']);
$this->runJobs();
$this->assertEquals('bar', self::$lastCommand);
}
- public function testFunctionCallable() {
+ public function testFunctionCallable(): void {
$this->getBus()->push('\Test\Command\BasicFunction');
$this->runJobs();
$this->assertEquals('function', self::$lastCommand);
}
- public function testClosure() {
- $this->getBus()->push(function () {
- AsyncBusTest::$lastCommand = 'closure';
+ public function testClosure(): void {
+ $this->getBus()->push(function (): void {
+ AsyncBusTestCase::$lastCommand = 'closure';
});
$this->runJobs();
$this->assertEquals('closure', self::$lastCommand);
}
- public function testClosureSelf() {
- $this->getBus()->push(function () {
- AsyncBusTest::$lastCommand = 'closure-self';
+ public function testClosureSelf(): void {
+ $this->getBus()->push(function (): void {
+ AsyncBusTestCase::$lastCommand = 'closure-self';
});
$this->runJobs();
$this->assertEquals('closure-self', self::$lastCommand);
}
- public function testClosureThis() {
+ public function testClosureThis(): void {
// clean class to prevent phpunit putting closure in $this
$test = new ThisClosureTest();
$test->test($this->getBus());
@@ -151,23 +149,23 @@ abstract class AsyncBusTest extends TestCase {
$this->assertEquals('closure-this', self::$lastCommand);
}
- public function testClosureBind() {
+ public function testClosureBind(): void {
$state = 'bar';
- $this->getBus()->push(function () use ($state) {
- AsyncBusTest::$lastCommand = 'closure-' . $state;
+ $this->getBus()->push(function () use ($state): void {
+ AsyncBusTestCase::$lastCommand = 'closure-' . $state;
});
$this->runJobs();
$this->assertEquals('closure-bar', self::$lastCommand);
}
- public function testFileFileAccessCommand() {
+ public function testFileFileAccessCommand(): void {
$this->getBus()->push(new FilesystemCommand());
$this->assertEquals('', self::$lastCommand);
$this->runJobs();
$this->assertEquals('FileAccess', self::$lastCommand);
}
- public function testFileFileAccessCommandSync() {
+ public function testFileFileAccessCommandSync(): void {
$this->getBus()->requireSync('\OC\Command\FileAccess');
$this->getBus()->push(new FilesystemCommand());
$this->assertEquals('FileAccess', self::$lastCommand);
diff --git a/tests/lib/Command/BackgroundJobsTest.php b/tests/lib/Command/BackgroundJobsTest.php
deleted file mode 100644
index 9d1741aff88..00000000000
--- a/tests/lib/Command/BackgroundJobsTest.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Christian Kampka <christian@kampka.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-namespace Test\Command;
-
-use OC\Core\Command\Background\Ajax;
-use OC\Core\Command\Background\Cron;
-use OC\Core\Command\Background\WebCron;
-
-use Symfony\Component\Console\Input\StringInput;
-use Symfony\Component\Console\Output\NullOutput;
-use Test\TestCase;
-
-class BackgroundJobsTest extends TestCase {
- public function testCronCommand() {
- $config = \OC::$server->getConfig();
- $job = new Cron($config);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('cron', $config->getAppValue('core', 'backgroundjobs_mode'));
- }
-
- public function testAjaxCommand() {
- $config = \OC::$server->getConfig();
- $job = new Ajax($config);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('ajax', $config->getAppValue('core', 'backgroundjobs_mode'));
- }
-
- public function testWebCronCommand() {
- $config = \OC::$server->getConfig();
- $job = new WebCron($config);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('webcron', $config->getAppValue('core', 'backgroundjobs_mode'));
- }
-}
diff --git a/tests/lib/Command/BackgroundModeTest.php b/tests/lib/Command/BackgroundModeTest.php
new file mode 100644
index 00000000000..ab036ef87ee
--- /dev/null
+++ b/tests/lib/Command/BackgroundModeTest.php
@@ -0,0 +1,60 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
+ * SPDX-License-Identifier: MIT
+ */
+namespace Test\Command;
+
+use OC\Core\Command\Background\Mode;
+use OCP\IAppConfig;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputDefinition;
+use Symfony\Component\Console\Tester\CommandTester;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class BackgroundModeTest extends TestCase {
+ private IAppConfig $appConfig;
+
+ private Mode $command;
+
+ public function setUp(): void {
+ $this->appConfig = $this->createMock(IAppConfig::class);
+
+ $inputDefinition = new InputDefinition([
+ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
+ ]);
+
+ $this->command = new Mode($this->appConfig);
+ $this->command->setDefinition($inputDefinition);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataModeCommand')]
+ public function testModeCommand(string $mode): void {
+ $this->appConfig->expects($this->once())
+ ->method('setValueString')
+ ->with('core', 'backgroundjobs_mode', $mode);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute(['command' => 'background:' . $mode]);
+
+ $commandTester->assertCommandIsSuccessful();
+
+ $output = $commandTester->getDisplay();
+ $this->assertStringContainsString($mode, $output);
+ }
+
+ public static function dataModeCommand(): array {
+ return [
+ 'ajax' => ['ajax'],
+ 'cron' => ['cron'],
+ 'webcron' => ['webcron'],
+ ];
+ }
+}
diff --git a/tests/lib/Command/CronBusTest.php b/tests/lib/Command/CronBusTest.php
index ea610a135d8..c86cdcb1da0 100644
--- a/tests/lib/Command/CronBusTest.php
+++ b/tests/lib/Command/CronBusTest.php
@@ -1,32 +1,22 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Command;
use OC\Command\CronBus;
+use OCP\BackgroundJob\IJobList;
use Test\BackgroundJob\DummyJobList;
-class CronBusTest extends AsyncBusTest {
+/**
+ * @group DB
+ */
+class CronBusTest extends AsyncBusTestCase {
/**
- * @var \OCP\BackgroundJob\IJobList
+ * @var IJobList
*/
private $jobList;
@@ -44,7 +34,7 @@ class CronBusTest extends AsyncBusTest {
protected function runJobs() {
$jobs = $this->jobList->getAll();
foreach ($jobs as $job) {
- $job->execute($this->jobList);
+ $job->start($this->jobList);
}
}
}
diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php
index 66005ca06f5..237afe3a5b5 100644
--- a/tests/lib/Command/Integrity/SignAppTest.php
+++ b/tests/lib/Command/Integrity/SignAppTest.php
@@ -1,22 +1,9 @@
<?php
+
/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Command\Integrity;
@@ -51,188 +38,187 @@ class SignAppTest extends TestCase {
);
}
- public function testExecuteWithMissingPath() {
+ public function testExecuteWithMissingPath(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- null,
- 'PrivateKey',
- 'Certificate',
- );
-
+ ->willReturnMap([
+ ['path', null],
+ ['privateKey', 'PrivateKey'],
+ ['certificate', 'Certificate'],
+ ]);
+
+ $calls = [
+ 'This command requires the --path, --privateKey and --certificate.',
+ '*',
+ '*',
+ ];
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['This command requires the --path, --privateKey and --certificate.']
- );
+ ->willReturnCallback(function (string $message) use (&$calls): void {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithMissingPrivateKey() {
+ public function testExecuteWithMissingPrivateKey(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- null,
- 'Certificate',
- );
-
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', null],
+ ['certificate', 'Certificate'],
+ ]);
+
+ $calls = [
+ 'This command requires the --path, --privateKey and --certificate.',
+ '*',
+ '*',
+ ];
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['This command requires the --path, --privateKey and --certificate.']
- );
+ ->willReturnCallback(function (string $message) use (&$calls): void {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithMissingCertificate() {
+ public function testExecuteWithMissingCertificate(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- 'privateKey',
- null,
- );
-
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', 'PrivateKey'],
+ ['certificate', null],
+ ]);
+
+ $calls = [
+ 'This command requires the --path, --privateKey and --certificate.',
+ '*',
+ '*',
+ ];
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['This command requires the --path, --privateKey and --certificate.']
- );
+ ->willReturnCallback(function (string $message) use (&$calls): void {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithNotExistingPrivateKey() {
+ public function testExecuteWithNotExistingPrivateKey(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- 'privateKey',
- 'certificate',
- );
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(['privateKey'])
- ->willReturnOnConsecutiveCalls(false);
+ ->willReturnMap([
+ ['privateKey', false],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Private key "privateKey" does not exists.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Private key "privateKey" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithNotExistingCertificate() {
+ public function testExecuteWithNotExistingCertificate(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- 'privateKey',
- 'certificate',
- );
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- \OC::$SERVERROOT . '/tests/data/integritycheck/core.key',
- false
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', false],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Certificate "certificate" does not exists.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Certificate "certificate" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithException() {
+ public function testExecuteWithException(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- 'privateKey',
- 'certificate',
- );
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', \OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'],
+ ]);
$this->checker
->expects($this->once())
@@ -242,41 +228,33 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Error: My error message']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Error: My error message', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecute() {
+ public function testExecute(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['path'],
- ['privateKey'],
- ['certificate'],
- )->willReturnOnConsecutiveCalls(
- 'AppId',
- 'privateKey',
- 'certificate',
- );
+ ->willReturnMap([
+ ['path', 'AppId'],
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', \OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'],
+ ]);
$this->checker
->expects($this->once())
@@ -285,9 +263,9 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Successfully signed "AppId"']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Successfully signed "AppId"', $message);
+ });
$this->assertSame(0, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
diff --git a/tests/lib/Command/Integrity/SignCoreTest.php b/tests/lib/Command/Integrity/SignCoreTest.php
index d67e2a9e2b4..843084eebd9 100644
--- a/tests/lib/Command/Integrity/SignCoreTest.php
+++ b/tests/lib/Command/Integrity/SignCoreTest.php
@@ -1,22 +1,9 @@
<?php
+
/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Command\Integrity;
@@ -46,164 +33,132 @@ class SignCoreTest extends TestCase {
);
}
- public function testExecuteWithMissingPrivateKey() {
+ public function testExecuteWithMissingPrivateKey(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- null,
- 'certificate',
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', null],
+ ['certificate', 'certificate'],
+ ['path', 'certificate'],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['--privateKey, --certificate and --path are required.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('--privateKey, --certificate and --path are required.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithMissingCertificate() {
+ public function testExecuteWithMissingCertificate(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- 'privateKey',
- null,
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', 'privateKey'],
+ ['certificate', null],
+ ['path', 'certificate'],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['--privateKey, --certificate and --path are required.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('--privateKey, --certificate and --path are required.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithNotExistingPrivateKey() {
+ public function testExecuteWithNotExistingPrivateKey(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- 'privateKey',
- 'certificate',
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ['path', 'certificate'],
+ ]);
$this->fileAccessHelper
- ->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- )
- ->willReturnOnConsecutiveCalls(
- false,
- );
+ ->willReturnMap([
+ ['privateKey', false],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Private key "privateKey" does not exists.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Private key "privateKey" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithNotExistingCertificate() {
+ public function testExecuteWithNotExistingCertificate(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- 'privateKey',
- 'certificate',
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ['path', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
- false,
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', false],
+ ]);
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Certificate "certificate" does not exists.']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Certificate "certificate" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecuteWithException() {
+ public function testExecuteWithException(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- 'privateKey',
- 'certificate',
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ['path', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')],
+ ]);
$this->checker
->expects($this->once())
@@ -213,41 +168,33 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Error: My exception message']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Error: My exception message', $message);
+ });
$this->assertEquals(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
- public function testExecute() {
+ public function testExecute(): void {
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);
$inputInterface
->expects($this->exactly(3))
->method('getOption')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- ['path'],
- )->willReturnOnConsecutiveCalls(
- 'privateKey',
- 'certificate',
- 'certificate',
- );
+ ->willReturnMap([
+ ['privateKey', 'privateKey'],
+ ['certificate', 'certificate'],
+ ['path', 'certificate'],
+ ]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
- ->withConsecutive(
- ['privateKey'],
- ['certificate'],
- )
- ->willReturnOnConsecutiveCalls(
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
- file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
- );
+ ->willReturnMap([
+ ['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
+ ['certificate', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')],
+ ]);
$this->checker
->expects($this->once())
@@ -256,9 +203,9 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Successfully signed "core"']
- );
+ ->willReturnCallback(function (string $message): void {
+ $this->assertEquals('Successfully signed "core"', $message);
+ });
$this->assertEquals(0, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}