diff options
Diffstat (limited to 'tests/lib/Command/Integrity')
-rw-r--r-- | tests/lib/Command/Integrity/SignAppTest.php | 218 | ||||
-rw-r--r-- | tests/lib/Command/Integrity/SignCoreTest.php | 167 |
2 files changed, 169 insertions, 216 deletions
diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php index d4921c79431..237afe3a5b5 100644 --- a/tests/lib/Command/Integrity/SignAppTest.php +++ b/tests/lib/Command/Integrity/SignAppTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -44,22 +45,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): 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])); } @@ -71,22 +78,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): 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])); } @@ -98,22 +111,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): 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])); } @@ -125,29 +144,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): void { + $this->assertEquals('Private key "privateKey" does not exists.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -159,34 +175,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): void { + $this->assertEquals('Certificate "certificate" does not exists.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -198,27 +206,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 +228,9 @@ 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])); } @@ -242,27 +242,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 +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 bbb68e00a84..843084eebd9 100644 --- a/tests/lib/Command/Integrity/SignCoreTest.php +++ b/tests/lib/Command/Integrity/SignCoreTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -39,22 +40,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): void { + $this->assertEquals('--privateKey, --certificate and --path are required.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -66,22 +63,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): void { + $this->assertEquals('--privateKey, --certificate and --path are required.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -93,32 +86,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): void { + $this->assertEquals('Private key "privateKey" does not exists.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -130,34 +115,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): void { + $this->assertEquals('Certificate "certificate" does not exists.', $message); + }); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -169,27 +146,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 +168,9 @@ 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])); } @@ -213,27 +182,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 +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])); } |