diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-06-16 17:43:17 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-06-16 17:43:17 +0200 |
commit | c7e1c36362a7e4de5a7d074ab43f97c2559e06ea (patch) | |
tree | 44029b863ad1dd0a4ad05d029b13c0a64772369e /tests/lib/Command/Integrity | |
parent | 0c14ee6ff5a2d3aa3f77f8cd2bf331590ee62f44 (diff) | |
download | nextcloud-server-c7e1c36362a7e4de5a7d074ab43f97c2559e06ea.tar.gz nextcloud-server-c7e1c36362a7e4de5a7d074ab43f97c2559e06ea.zip |
Remove at matcher uses in tests/lib
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/lib/Command/Integrity')
-rw-r--r-- | tests/lib/Command/Integrity/SignAppTest.php | 263 | ||||
-rw-r--r-- | tests/lib/Command/Integrity/SignCoreTest.php | 225 |
2 files changed, 248 insertions, 240 deletions
diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php index fefed296a0c..66005ca06f5 100644 --- a/tests/lib/Command/Integrity/SignAppTest.php +++ b/tests/lib/Command/Integrity/SignAppTest.php @@ -56,25 +56,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn(null); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('PrivateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + null, + 'PrivateKey', + 'Certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -84,25 +83,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn(null); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + null, + 'Certificate', + ); $outputInterface - ->expects($this->at(0)) - ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->expects($this->any()) + ->method('writeln') + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -112,25 +110,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn(null); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + null, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -140,31 +137,31 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(false); + ->withConsecutive(['privateKey']) + ->willReturnOnConsecutiveCalls(false); + $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Private key "privateKey" does not exists.'); + ->withConsecutive( + ['Private key "privateKey" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -174,36 +171,36 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with('certificate') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + \OC::$SERVERROOT . '/tests/data/integritycheck/core.key', + false + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Certificate "certificate" does not exists.'); + ->withConsecutive( + ['Certificate "certificate" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -213,31 +210,29 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) @@ -245,9 +240,11 @@ class SignAppTest extends TestCase { ->willThrowException(new \Exception('My error message')); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Error: My error message'); + ->withConsecutive( + ['Error: My error message'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -257,40 +254,40 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) ->method('writeAppSignature'); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Successfully signed "AppId"'); + ->withConsecutive( + ['Successfully signed "AppId"'] + ); $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 3b7fe7f3a8b..d67e2a9e2b4 100644 --- a/tests/lib/Command/Integrity/SignCoreTest.php +++ b/tests/lib/Command/Integrity/SignCoreTest.php @@ -51,20 +51,24 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn(null); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + null, + 'certificate', + 'certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('--privateKey, --certificate and --path are required.'); + ->withConsecutive( + ['--privateKey, --certificate and --path are required.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -74,20 +78,24 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn(null); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + null, + 'certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('--privateKey, --certificate and --path are required.'); + ->withConsecutive( + ['--privateKey, --certificate and --path are required.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -97,31 +105,34 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ) + ->willReturnOnConsecutiveCalls( + false, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Private key "privateKey" does not exists.'); + ->withConsecutive( + ['Private key "privateKey" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -131,36 +142,36 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + false, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Certificate "certificate" does not exists.'); + ->withConsecutive( + ['Certificate "certificate" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -170,31 +181,29 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) @@ -202,9 +211,11 @@ class SignCoreTest extends TestCase { ->willThrowException(new \Exception('My exception message')); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Error: My exception message'); + ->withConsecutive( + ['Error: My exception message'] + ); $this->assertEquals(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -214,40 +225,40 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) ->method('writeCoreSignature'); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Successfully signed "core"'); + ->withConsecutive( + ['Successfully signed "core"'] + ); $this->assertEquals(0, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } |