diff options
author | Robin Appelman <robin@icewind.nl> | 2023-04-21 13:48:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-21 13:48:12 +0200 |
commit | ccab101df85e8c5878361e7a9fa19480a3d54a96 (patch) | |
tree | f7183efe2acc724de4528ee79df0434c56d5e4fa /tests/lib/Http/Client | |
parent | c08026a92ab020ac327aa7b8d379fc26cfe447bd (diff) | |
parent | b294edad804f40618a96116845615831302d0357 (diff) | |
download | nextcloud-server-ccab101df85e8c5878361e7a9fa19480a3d54a96.tar.gz nextcloud-server-ccab101df85e8c5878361e7a9fa19480a3d54a96.zip |
Merge pull request #37596 from nextcloud/enh/type-iconfig-getter-calls
Use typed version of IConfig::getSystemValue as much as possible
Diffstat (limited to 'tests/lib/Http/Client')
-rw-r--r-- | tests/lib/Http/Client/ClientTest.php | 156 |
1 files changed, 84 insertions, 72 deletions
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 93948a5daf3..9a4fb1c657e 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -54,22 +54,25 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUri(): void { $this->config - ->method('getSystemValue') - ->with('proxy', null) - ->willReturn(null); + ->method('getSystemValueString') + ->with('proxy', '') + ->willReturn(''); $this->assertNull(self::invokePrivate($this->client, 'getProxyUri')); } public function testGetProxyUriProxyHostEmptyPassword(): void { - $map = [ - ['proxy', '', 'foo'], - ['proxyuserpwd', '', null], - ['proxyexclude', [], []], - ]; - $this->config ->method('getSystemValue') - ->will($this->returnValueMap($map)); + ->will($this->returnValueMap([ + ['proxyexclude', [], []], + ])); + + $this->config + ->method('getSystemValueString') + ->will($this->returnValueMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ])); $this->assertEquals([ 'http' => 'foo', @@ -79,32 +82,20 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostWithPassword(): void { $this->config - ->expects($this->exactly(3)) + ->expects($this->once()) ->method('getSystemValue') + ->with('proxyexclude', []) + ->willReturn([]); + $this->config + ->expects($this->exactly(2)) + ->method('getSystemValueString') ->withConsecutive( - [ - $this->equalTo('proxy'), - $this->callback(function ($input) { - return $input === ''; - }) - ], - [ - $this->equalTo('proxyuserpwd'), - $this->callback(function ($input) { - return $input === ''; - }) - ], - [ - $this->equalTo('proxyexclude'), - $this->callback(function ($input) { - return $input === []; - }) - ], + ['proxy', ''], + ['proxyuserpwd', ''], ) ->willReturnOnConsecutiveCalls( 'foo', 'username:password', - [], ); $this->assertEquals([ 'http' => 'username:password@foo', @@ -114,32 +105,20 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostWithPasswordAndExclude(): void { $this->config - ->expects($this->exactly(3)) + ->expects($this->once()) ->method('getSystemValue') + ->with('proxyexclude', []) + ->willReturn(['bar']); + $this->config + ->expects($this->exactly(2)) + ->method('getSystemValueString') ->withConsecutive( - [ - $this->equalTo('proxy'), - $this->callback(function ($input) { - return $input === ''; - }) - ], - [ - $this->equalTo('proxyuserpwd'), - $this->callback(function ($input) { - return $input === ''; - }) - ], - [ - $this->equalTo('proxyexclude'), - $this->callback(function ($input) { - return $input === []; - }) - ], + ['proxy', ''], + ['proxyuserpwd', ''], ) ->willReturnOnConsecutiveCalls( 'foo', 'username:password', - ['bar'], ); $this->assertEquals([ 'http' => 'username:password@foo', @@ -271,19 +250,23 @@ class ClientTest extends \Test\TestCase { } private function setUpDefaultRequestOptions(): void { - $map = [ - ['proxy', '', 'foo'], - ['proxyuserpwd', '', null], - ['proxyexclude', [], []], - ]; - $this->config ->method('getSystemValue') - ->will($this->returnValueMap($map)); + ->will($this->returnValueMap([ + ['proxyexclude', [], []], + ])); + $this->config + ->method('getSystemValueString') + ->will($this->returnValueMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ])); $this->config ->method('getSystemValueBool') - ->with('allow_local_remote_servers', false) - ->willReturn(true); + ->will($this->returnValueMap([ + ['installed', false, true], + ['allow_local_remote_servers', false, true], + ])); $this->certificateManager ->expects($this->once()) @@ -467,15 +450,20 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithNotInstalled(): void { $this->config ->expects($this->exactly(2)) - ->method('getSystemValue') + ->method('getSystemValueBool') ->withConsecutive( - ['proxy', ''], ['installed', false], + ['allow_local_remote_servers', false], ) ->willReturnOnConsecutiveCalls( - '', + false, false, ); + $this->config + ->expects($this->once()) + ->method('getSystemValueString') + ->with('proxy', '') + ->willReturn(''); $this->certificateManager ->expects($this->never()) ->method('listCertificates'); @@ -503,19 +491,31 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithProxy(): void { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) + ->method('getSystemValueBool') + ->withConsecutive( + ['installed', false], + ['allow_local_remote_servers', false], + ) + ->willReturnOnConsecutiveCalls( + true, + false, + ); + $this->config + ->expects($this->once()) ->method('getSystemValue') + ->with('proxyexclude', []) + ->willReturn([]); + $this->config + ->expects($this->exactly(2)) + ->method('getSystemValueString') ->withConsecutive( ['proxy', ''], ['proxyuserpwd', ''], - ['proxyexclude', []], - ['installed', false], ) ->willReturnOnConsecutiveCalls( 'foo', '', - [], - true, ); $this->certificateManager ->expects($this->once()) @@ -550,19 +550,31 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithProxyAndExclude(): void { $this->config - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) + ->method('getSystemValueBool') + ->withConsecutive( + ['installed', false], + ['allow_local_remote_servers', false], + ) + ->willReturnOnConsecutiveCalls( + true, + false, + ); + $this->config + ->expects($this->once()) ->method('getSystemValue') + ->with('proxyexclude', []) + ->willReturn(['bar']); + $this->config + ->expects($this->exactly(2)) + ->method('getSystemValueString') ->withConsecutive( ['proxy', ''], ['proxyuserpwd', ''], - ['proxyexclude', []], - ['installed', false], ) ->willReturnOnConsecutiveCalls( 'foo', '', - ['bar'], - true, ); $this->certificateManager ->expects($this->once()) |