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)20
-rw-r--r--tests/lib/Command/BackgroundModeTest.php5
-rw-r--r--tests/lib/Command/CronBusTest.php5
-rw-r--r--tests/lib/Command/Integrity/SignAppTest.php217
-rw-r--r--tests/lib/Command/Integrity/SignCoreTest.php166
5 files changed, 185 insertions, 228 deletions
diff --git a/tests/lib/Command/AsyncBusTest.php b/tests/lib/Command/AsyncBusTestCase.php
index e8d7a857129..c4f173f8b32 100644
--- a/tests/lib/Command/AsyncBusTest.php
+++ b/tests/lib/Command/AsyncBusTestCase.php
@@ -15,7 +15,7 @@ use Test\TestCase;
class SimpleCommand implements ICommand {
public function handle() {
- AsyncBusTest::$lastCommand = 'SimpleCommand';
+ AsyncBusTestCase::$lastCommand = 'SimpleCommand';
}
}
@@ -27,7 +27,7 @@ class StateFullCommand implements ICommand {
}
public function handle() {
- AsyncBusTest::$lastCommand = $this->state;
+ AsyncBusTestCase::$lastCommand = $this->state;
}
}
@@ -35,18 +35,18 @@ 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) {
@@ -56,7 +56,7 @@ class ThisClosureTest {
}
}
-abstract class AsyncBusTest extends TestCase {
+abstract class AsyncBusTestCase extends TestCase {
/**
* Basic way to check output from a command
*
@@ -107,7 +107,7 @@ abstract class AsyncBusTest extends TestCase {
}
public function testStaticCallable(): void {
- $this->getBus()->push(['\Test\Command\AsyncBusTest', 'DummyCommand']);
+ $this->getBus()->push(['\Test\Command\AsyncBusTestCase', 'DummyCommand']);
$this->runJobs();
$this->assertEquals('static', self::$lastCommand);
}
@@ -127,7 +127,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosure(): void {
$this->getBus()->push(function () {
- AsyncBusTest::$lastCommand = 'closure';
+ AsyncBusTestCase::$lastCommand = 'closure';
});
$this->runJobs();
$this->assertEquals('closure', self::$lastCommand);
@@ -135,7 +135,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosureSelf(): void {
$this->getBus()->push(function () {
- AsyncBusTest::$lastCommand = 'closure-self';
+ AsyncBusTestCase::$lastCommand = 'closure-self';
});
$this->runJobs();
$this->assertEquals('closure-self', self::$lastCommand);
@@ -153,7 +153,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosureBind(): void {
$state = 'bar';
$this->getBus()->push(function () use ($state) {
- AsyncBusTest::$lastCommand = 'closure-' . $state;
+ AsyncBusTestCase::$lastCommand = 'closure-' . $state;
});
$this->runJobs();
$this->assertEquals('closure-bar', self::$lastCommand);
diff --git a/tests/lib/Command/BackgroundModeTest.php b/tests/lib/Command/BackgroundModeTest.php
index 941449c98bb..2f874deb78a 100644
--- a/tests/lib/Command/BackgroundModeTest.php
+++ b/tests/lib/Command/BackgroundModeTest.php
@@ -16,6 +16,9 @@ use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
+/**
+ * @group DB
+ */
class BackgroundModeTest extends TestCase {
private IAppConfig $appConfig;
@@ -49,7 +52,7 @@ class BackgroundModeTest extends TestCase {
$this->assertStringContainsString($mode, $output);
}
- public function dataModeCommand(): array {
+ public static function dataModeCommand(): array {
return [
'ajax' => ['ajax'],
'cron' => ['cron'],
diff --git a/tests/lib/Command/CronBusTest.php b/tests/lib/Command/CronBusTest.php
index 96190f717c6..2e5617efb31 100644
--- a/tests/lib/Command/CronBusTest.php
+++ b/tests/lib/Command/CronBusTest.php
@@ -9,7 +9,10 @@ namespace Test\Command;
use OC\Command\CronBus;
use Test\BackgroundJob\DummyJobList;
-class CronBusTest extends AsyncBusTest {
+/**
+ * @group DB
+ */
+class CronBusTest extends AsyncBusTestCase {
/**
* @var \OCP\BackgroundJob\IJobList
*/
diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php
index d4921c79431..38b5c68e026 100644
--- a/tests/lib/Command/Integrity/SignAppTest.php
+++ b/tests/lib/Command/Integrity/SignAppTest.php
@@ -44,22 +44,28 @@ class SignAppTest extends TestCase {
$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) {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -71,22 +77,28 @@ class SignAppTest extends TestCase {
$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) {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -98,22 +110,28 @@ class SignAppTest extends TestCase {
$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) {
+ $expected = array_shift($calls);
+ if ($expected === '*') {
+ $this->assertNotEmpty($message);
+ } else {
+ $this->assertEquals($expected, $message);
+ }
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -125,29 +143,26 @@ class SignAppTest extends TestCase {
$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) {
+ $this->assertEquals('Private key "privateKey" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -159,34 +174,26 @@ class SignAppTest extends TestCase {
$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) {
+ $this->assertEquals('Certificate "certificate" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -198,27 +205,19 @@ class SignAppTest extends TestCase {
$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())
@@ -228,9 +227,9 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Error: My error message']
- );
+ ->willReturnCallback(function (string $message) {
+ $this->assertEquals('Error: My error message', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@@ -242,27 +241,19 @@ class SignAppTest extends TestCase {
$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())
@@ -271,9 +262,9 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Successfully signed "AppId"']
- );
+ ->willReturnCallback(function (string $message) {
+ $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 bbb68e00a84..66227322dda 100644
--- a/tests/lib/Command/Integrity/SignCoreTest.php
+++ b/tests/lib/Command/Integrity/SignCoreTest.php
@@ -39,22 +39,18 @@ class SignCoreTest extends TestCase {
$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) {
+ $this->assertEquals('--privateKey, --certificate and --path are required.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@@ -66,22 +62,18 @@ class SignCoreTest extends TestCase {
$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) {
+ $this->assertEquals('--privateKey, --certificate and --path are required.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@@ -93,32 +85,24 @@ class SignCoreTest extends TestCase {
$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) {
+ $this->assertEquals('Private key "privateKey" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@@ -130,34 +114,26 @@ class SignCoreTest extends TestCase {
$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) {
+ $this->assertEquals('Certificate "certificate" does not exists.', $message);
+ });
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@@ -169,27 +145,19 @@ class SignCoreTest extends TestCase {
$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())
@@ -199,9 +167,9 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Error: My exception message']
- );
+ ->willReturnCallback(function (string $message) {
+ $this->assertEquals('Error: My exception message', $message);
+ });
$this->assertEquals(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@@ -213,27 +181,19 @@ class SignCoreTest extends TestCase {
$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())
@@ -242,9 +202,9 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['Successfully signed "core"']
- );
+ ->willReturnCallback(function (string $message) {
+ $this->assertEquals('Successfully signed "core"', $message);
+ });
$this->assertEquals(0, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}