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 | |
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')
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 16 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/FetcherBase.php | 203 | ||||
-rw-r--r-- | tests/lib/AppFramework/Http/RequestTest.php | 177 | ||||
-rw-r--r-- | tests/lib/AppFramework/Routing/RoutingTest.php | 86 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/LookupPluginTest.php | 59 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/UserPluginTest.php | 39 | ||||
-rw-r--r-- | tests/lib/Collaboration/Resources/ProviderManagerTest.php | 15 | ||||
-rw-r--r-- | tests/lib/Command/Integrity/SignAppTest.php | 263 | ||||
-rw-r--r-- | tests/lib/Command/Integrity/SignCoreTest.php | 225 |
9 files changed, 522 insertions, 561 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index 4746c296ab4..a2d56838b07 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -1890,12 +1890,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('apps.json') ->willReturn($file); @@ -1946,7 +1946,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent'); $file ->method('getContent') @@ -2017,12 +2017,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('future-apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('future-apps.json') ->willReturn($file); @@ -2073,7 +2073,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent'); $file ->method('getContent') @@ -2104,12 +2104,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('apps.json') ->willReturn($file); diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 87a09cb617d..42ad02ce6d8 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -76,22 +76,20 @@ abstract class FetcherBase extends TestCase { public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('getSystemValueBool') ->with('appstoreenabled', true) ->willReturn(true); $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('has_internet_connection', true) - ->willReturn(true); - $this->config - ->expects($this->at(2)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with( - $this->equalTo('version'), - $this->anything() - )->willReturn('11.0.0.2'); + ->withConsecutive( + ['has_internet_connection', true], + [$this->equalTo('version'), $this->anything()], + )->willReturnOnConsecutiveCalls( + true, + '11.0.0.2', + ); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -148,12 +146,12 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with($this->fileName) ->willReturn($file); @@ -177,15 +175,15 @@ abstract class FetcherBase extends TestCase { ->willReturn('"myETag"'); $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent') ->with($fileData); $file - ->expects($this->at(1)) + ->expects($this->once()) ->method('getContent') ->willReturn($fileData); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTime') ->willReturn(1502); @@ -227,14 +225,25 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}', + $fileData + ); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getTime') - ->willReturn(4801); + ->willReturnOnConsecutiveCalls( + 4801, + 1502 + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -253,19 +262,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); - $this->timeFactory - ->expects($this->at(1)) - ->method('getTime') - ->willReturn(1502); $expected = [ [ @@ -309,12 +305,20 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}', + $fileData + ); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTime') ->willReturn(1201); $client = $this->createMock(IClient::class); @@ -335,15 +339,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $expected = [ [ @@ -387,10 +382,18 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"', + $fileData + ); $this->timeFactory ->method('getTime') ->willReturn(1201); @@ -412,15 +415,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $expected = [ [ @@ -457,7 +451,7 @@ abstract class FetcherBase extends TestCase { ->with($this->fileName) ->willReturn($file); $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('getContent') ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}'); $client = $this->createMock(IClient::class); @@ -501,18 +495,26 @@ abstract class FetcherBase extends TestCase { ->with($this->fileName) ->willReturn($file); $origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + + $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($newData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn($origData); - $this->timeFactory - ->expects($this->at(0)) - ->method('getTime') - ->willReturn(4801); + ->willReturnOnConsecutiveCalls( + $origData, + $newData, + ); $this->timeFactory - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getTime') - ->willReturn(4802); + ->willReturnOnConsecutiveCalls( + 4801, + 4802 + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -534,16 +536,6 @@ abstract class FetcherBase extends TestCase { $response->method('getStatusCode') ->willReturn(304); - $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($newData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($newData); - $expected = [ [ 'id' => 'MyNewApp', @@ -579,14 +571,29 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'); + ->willReturnOnConsecutiveCalls( + '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}', + $fileData, + ); + $this->timeFactory + ->expects($this->exactly(2)) + ->method('getTime') + ->willReturnOnConsecutiveCalls( + 4801, + 4802, + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -615,23 +622,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"newETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); - $this->timeFactory - ->expects($this->at(0)) - ->method('getTime') - ->willReturn(4801); - $this->timeFactory - ->expects($this->at(1)) - ->method('getTime') - ->willReturn(4802); $expected = [ [ @@ -668,14 +658,22 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'); + ->willReturnOnConsecutiveCalls( + '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}', + $fileData + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -701,15 +699,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"newETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $this->timeFactory ->expects($this->once()) ->method('getTime') diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index e15f3fe656c..3289a373a12 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -381,15 +381,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithNoTrustedHeader() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )->willReturnOnConsecutiveCalls( + ['10.0.0.2'], + [] + ); $request = new Request( [ @@ -410,15 +410,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithSingleTrustedRemote() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['10.0.0.2'], + ['HTTP_X_FORWARDED'], + ); $request = new Request( [ @@ -439,15 +439,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressIPv6WithSingleTrustedRemote() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['2001:db8:85a3:8d3:1319:8a2e:370:7348']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['2001:db8:85a3:8d3:1319:8a2e:370:7348'], + ['HTTP_X_FORWARDED'], + ); $request = new Request( [ @@ -468,19 +468,19 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressVerifyPriorityHeader() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([ - 'HTTP_CLIENT_IP', - 'HTTP_X_FORWARDED_FOR', - 'HTTP_X_FORWARDED' - ]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['10.0.0.2'], + [ + 'HTTP_CLIENT_IP', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED', + ], + ); $request = new Request( [ @@ -501,19 +501,19 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressIPv6VerifyPriorityHeader() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['2001:db8:85a3:8d3:1319:8a2e:370:7348']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([ - 'HTTP_CLIENT_IP', - 'HTTP_X_FORWARDED_FOR', - 'HTTP_X_FORWARDED' - ]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['2001:db8:85a3:8d3:1319:8a2e:370:7348'], + [ + 'HTTP_CLIENT_IP', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED' + ], + ); $request = new Request( [ @@ -534,15 +534,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithMatchingCidrTrustedRemote() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['192.168.2.0/24']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED_FOR']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['192.168.2.0/24'], + ['HTTP_X_FORWARDED_FOR'], + ); $request = new Request( [ @@ -587,15 +587,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithXForwardedForIPv6() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['192.168.2.0/24']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED_FOR']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['192.168.2.0/24'], + ['HTTP_X_FORWARDED_FOR'], + ); $request = new Request( [ @@ -666,20 +666,12 @@ class RequestTest extends \Test\TestCase { public function testGetServerProtocolWithOverride() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with('overwriteprotocol') - ->willReturn('customProtocol'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn(''); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('overwriteprotocol') - ->willReturn('customProtocol'); + ->willReturnMap([ + ['overwriteprotocol', '', 'customProtocol'], + ['overwritecondaddr', '', ''], + ]); $request = new Request( [], @@ -1266,20 +1258,12 @@ class RequestTest extends \Test\TestCase { public function testGetOverwriteHostWithOverwrite() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with('overwritehost') - ->willReturn('www.owncloud.org'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn(''); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('overwritehost') - ->willReturn('www.owncloud.org'); + ->willReturnMap([ + ['overwritehost', '', 'www.owncloud.org'], + ['overwritecondaddr', '', ''], + ]); $request = new Request( [], @@ -1493,15 +1477,12 @@ class RequestTest extends \Test\TestCase { */ public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr) { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('overwritewebroot') - ->willReturn($overwriteWebRoot); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn($overwriteCondAddr); + ->willReturnMap([ + ['overwritewebroot', '', $overwriteWebRoot], + ['overwritecondaddr', '', $overwriteCondAddr], + ]); $request = $this->getMockBuilder('\OC\AppFramework\Http\Request') ->setMethods(['getScriptName']) diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index b4965d61d4f..22037c31d0d 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -304,36 +304,23 @@ class RoutingTest extends \Test\TestCase { $urlWithParam = $url . '/{' . $paramName . '}'; - // we expect create to be called once: - $router - ->expects($this->at(0)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)) - ->willReturn($indexRoute); - - $router - ->expects($this->at(1)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)) - ->willReturn($showRoute); - - $router - ->expects($this->at(2)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)) - ->willReturn($createRoute); - - $router - ->expects($this->at(3)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)) - ->willReturn($updateRoute); - + // we expect create to be called five times: $router - ->expects($this->at(4)) + ->expects($this->exactly(5)) ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)) - ->willReturn($destroyRoute); + ->withConsecutive( + [$this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)], + [$this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)], + [$this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)], + [$this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)], + [$this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)], + )->willReturnOnConsecutiveCalls( + $indexRoute, + $showRoute, + $createRoute, + $updateRoute, + $destroyRoute, + ); // load route configuration $config = new RouteConfig($container, $router, $yaml); @@ -364,36 +351,23 @@ class RoutingTest extends \Test\TestCase { $urlWithParam = $url . '/{' . $paramName . '}'; - // we expect create to be called once: - $router - ->expects($this->at(0)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)) - ->willReturn($indexRoute); - - $router - ->expects($this->at(1)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)) - ->willReturn($showRoute); - - $router - ->expects($this->at(2)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)) - ->willReturn($createRoute); - - $router - ->expects($this->at(3)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)) - ->willReturn($updateRoute); - + // we expect create to be called five times: $router - ->expects($this->at(4)) + ->expects($this->exactly(5)) ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)) - ->willReturn($destroyRoute); + ->withConsecutive( + [$this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)], + [$this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)], + [$this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)], + [$this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)], + [$this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)], + )->willReturnOnConsecutiveCalls( + $indexRoute, + $showRoute, + $createRoute, + $updateRoute, + $destroyRoute, + ); // load route configuration $config = new RouteConfig($container, $router, $yaml); diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 1d856252745..b52e1d2745e 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -92,19 +92,20 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + false, + '', + ); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn(''); $this->clientService->expects($this->never()) ->method('newClient'); @@ -120,12 +121,12 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->once()) ->method('getSystemValue') ->with('gs.enabled', false) ->willReturn(false); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(false); @@ -156,19 +157,20 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + false, + $searchParams['server'], + ); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn($searchParams['server']); $response = $this->createMock(IResponse::class); $response->expects($this->once()) @@ -215,23 +217,24 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn($LookupEnabled ? 'yes' : 'no'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn($GSEnabled); if ($GSEnabled || $LookupEnabled) { $searchResult->expects($this->once()) ->method('addResultSet') ->with($type, $searchParams['expectedResult'], []); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn($searchParams['server']); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + $GSEnabled, + $searchParams['server'], + ); $response = $this->createMock(IResponse::class); $response->expects($this->once()) @@ -252,6 +255,10 @@ class LookupPluginTest extends TestCase { ->willReturn($client); } else { $searchResult->expects($this->never())->method('addResultSet'); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('gs.enabled', false) + ->willReturn($GSEnabled); } $moreResults = $this->plugin->search( $searchParams['search'], diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 20e1ed898ad..2c8297014d2 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -23,9 +23,6 @@ namespace Test\Collaboration\Collaborators; -use OC\Collaboration\Collaborators\SearchResult; -use OC\Collaboration\Collaborators\UserPlugin; -use OC\KnownUser\KnownUserService; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\IConfig; use OCP\IGroup; @@ -35,25 +32,29 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; +use OC\Collaboration\Collaborators\SearchResult; +use OC\Collaboration\Collaborators\UserPlugin; +use OC\KnownUser\KnownUserService; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UserPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserManager|MockObject */ protected $userManager; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|MockObject */ protected $groupManager; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|MockObject */ protected $session; - /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var KnownUserService|MockObject */ protected $knownUserService; - /** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserStatusManager|MockObject */ protected $userStatusManager; /** @var UserPlugin */ @@ -62,13 +63,11 @@ class UserPluginTest extends TestCase { /** @var ISearchResult */ protected $searchResult; - /** @var int */ - protected $limit = 2; + protected int $limit = 2; - /** @var int */ - protected $offset = 0; + protected int $offset = 0; - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|MockObject */ protected $user; protected function setUp(): void { @@ -798,13 +797,15 @@ class UserPluginTest extends TestCase { $this->session->expects($this->any()) ->method('getUser') ->willReturn($this->getUserMock('test', 'foo')); - // current user - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->willReturn($userGroups); $this->groupManager->expects($this->any()) ->method('getUserGroupIds') - ->willReturnCallback(function ($user) use ($matchingUsers) { + ->willReturnCallback(function ($user) use ($matchingUsers, $userGroups) { + static $firstCall = true; + if ($firstCall) { + $firstCall = false; + // current user + return $userGroups; + } $neededObject = array_filter( $matchingUsers, function ($e) use ($user) { diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 01e45de9fdf..8f408418409 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -91,14 +91,15 @@ class ProviderManagerTest extends TestCase { } public function testGetResourceProvidersValidAndInvalidProvider(): void { - $this->serverContainer->expects($this->at(0)) + $this->serverContainer->expects($this->exactly(2)) ->method('query') - ->with($this->equalTo('InvalidResourceProvider')) - ->willThrowException(new QueryException('A meaningful error message')); - $this->serverContainer->expects($this->at(1)) - ->method('query') - ->with($this->equalTo(ResourceProvider::class)) - ->willReturn($this->createMock(ResourceProvider::class)); + ->withConsecutive( + [$this->equalTo('InvalidResourceProvider')], + [$this->equalTo(ResourceProvider::class)], + )->willReturnOnConsecutiveCalls( + $this->throwException(new QueryException('A meaningful error message')), + $this->createMock(ResourceProvider::class), + ); $this->logger->expects($this->once()) ->method('error'); 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])); } |