diff options
Diffstat (limited to 'tests/lib/Http/Client')
-rw-r--r-- | tests/lib/Http/Client/ClientServiceTest.php | 12 | ||||
-rw-r--r-- | tests/lib/Http/Client/ClientTest.php | 126 | ||||
-rw-r--r-- | tests/lib/Http/Client/DnsPinMiddlewareTest.php | 10 | ||||
-rw-r--r-- | tests/lib/Http/Client/NegativeDnsCacheTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Http/Client/ResponseTest.php | 1 |
5 files changed, 62 insertions, 89 deletions
diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php index 7c9cd55a6cc..fd5b155ca69 100644 --- a/tests/lib/Http/Client/ClientServiceTest.php +++ b/tests/lib/Http/Client/ClientServiceTest.php @@ -40,7 +40,7 @@ class ClientServiceTest extends \Test\TestCase { $dnsPinMiddleware ->expects($this->atLeastOnce()) ->method('addDnsPinning') - ->willReturn(function () { + ->willReturn(function (): void { }); $remoteHostValidator = $this->createMock(IRemoteHostValidator::class); $eventLogger = $this->createMock(IEventLogger::class); @@ -58,9 +58,9 @@ class ClientServiceTest extends \Test\TestCase { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); $stack->push($dnsPinMiddleware->addDnsPinning()); - $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger) { + $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger): void { $eventLogger->start('http:request', $request->getMethod() . ' request to ' . $request->getRequestTarget()); - }, function () use ($eventLogger) { + }, function () use ($eventLogger): void { $eventLogger->end('http:request'); }), 'event logger'); $guzzleClient = new GuzzleClient(['handler' => $stack]); @@ -89,7 +89,7 @@ class ClientServiceTest extends \Test\TestCase { $dnsPinMiddleware ->expects($this->never()) ->method('addDnsPinning') - ->willReturn(function () { + ->willReturn(function (): void { }); $remoteHostValidator = $this->createMock(IRemoteHostValidator::class); $eventLogger = $this->createMock(IEventLogger::class); @@ -106,9 +106,9 @@ class ClientServiceTest extends \Test\TestCase { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); - $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger) { + $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger): void { $eventLogger->start('http:request', $request->getMethod() . ' request to ' . $request->getRequestTarget()); - }, function () use ($eventLogger) { + }, function () use ($eventLogger): void { $eventLogger->end('http:request'); }), 'event logger'); $guzzleClient = new GuzzleClient(['handler' => $stack]); diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 47a6b885aed..e76b66b52d7 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -66,16 +66,16 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostEmptyPassword(): void { $this->config ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxyexclude', [], []], - ])); + ]); $this->config ->method('getSystemValueString') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxy', '', 'foo'], ['proxyuserpwd', '', ''], - ])); + ]); $this->assertEquals([ 'http' => 'foo', @@ -92,14 +92,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - 'username:password', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', 'username:password'], + ]); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo' @@ -115,14 +111,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - 'username:password', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', 'username:password'], + ]); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo', @@ -137,7 +129,7 @@ class ClientTest extends \Test\TestCase { self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]); } - public function dataPreventLocalAddress():array { + public static function dataPreventLocalAddress(): array { return [ ['https://localhost/foo.bar'], ['https://localHost/foo.bar'], @@ -159,9 +151,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressDisabledByGlobalConfig(string $uri): void { $this->config->expects($this->once()) ->method('getSystemValueBool') @@ -172,9 +164,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressDisabledByOption(string $uri): void { $this->config->expects($this->never()) ->method('getSystemValueBool'); @@ -185,9 +177,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnGet(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -200,9 +192,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnHead(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -215,9 +207,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnPost(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -230,9 +222,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnPut(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -245,9 +237,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnDelete(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -262,21 +254,21 @@ class ClientTest extends \Test\TestCase { private function setUpDefaultRequestOptions(): void { $this->config ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxyexclude', [], []], - ])); + ]); $this->config ->method('getSystemValueString') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxy', '', 'foo'], ['proxyuserpwd', '', ''], - ])); + ]); $this->config ->method('getSystemValueBool') - ->will($this->returnValueMap([ + ->willReturnMap([ ['installed', false, true], ['allow_local_remote_servers', false, true], - ])); + ]); $this->certificateManager ->expects($this->once()) @@ -461,14 +453,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - false, - false, - ); + ->willReturnMap([ + ['installed', false, false], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValueString') @@ -493,7 +481,7 @@ class ClientTest extends \Test\TestCase { \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, \Psr\Http\Message\UriInterface $uri, - ) { + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -503,14 +491,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - true, - false, - ); + ->willReturnMap([ + ['installed', false, true], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValue') @@ -519,14 +503,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - '', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ]); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') @@ -552,7 +532,7 @@ class ClientTest extends \Test\TestCase { \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, \Psr\Http\Message\UriInterface $uri, - ) { + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -562,14 +542,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - true, - false, - ); + ->willReturnMap([ + ['installed', false, true], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValue') @@ -578,14 +554,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - '', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ]); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') @@ -612,7 +584,7 @@ class ClientTest extends \Test\TestCase { \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, \Psr\Http\Message\UriInterface $uri, - ) { + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); diff --git a/tests/lib/Http/Client/DnsPinMiddlewareTest.php b/tests/lib/Http/Client/DnsPinMiddlewareTest.php index 88059d44121..9c0aa198cd8 100644 --- a/tests/lib/Http/Client/DnsPinMiddlewareTest.php +++ b/tests/lib/Http/Client/DnsPinMiddlewareTest.php @@ -273,7 +273,7 @@ class DnsPinMiddlewareTest extends TestCase { $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ - static function (RequestInterface $request, array $options) { + static function (RequestInterface $request, array $options): void { // The handler should not be called }, ]); @@ -320,7 +320,7 @@ class DnsPinMiddlewareTest extends TestCase { $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ - static function (RequestInterface $request, array $options) { + static function (RequestInterface $request, array $options): void { // The handler should not be called }, ]); @@ -367,7 +367,7 @@ class DnsPinMiddlewareTest extends TestCase { $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ - static function (RequestInterface $request, array $options) { + static function (RequestInterface $request, array $options): void { // The handler should not be called }, ]); @@ -457,7 +457,7 @@ class DnsPinMiddlewareTest extends TestCase { $this->expectExceptionMessage('No DNS record found for www.example.com'); $mockHandler = new MockHandler([ - static function (RequestInterface $request, array $options) { + static function (RequestInterface $request, array $options): void { // The handler should not be called }, ]); @@ -480,7 +480,7 @@ class DnsPinMiddlewareTest extends TestCase { public function testIgnoreSubdomainForSoaQuery(): void { $mockHandler = new MockHandler([ - static function (RequestInterface $request, array $options) { + static function (RequestInterface $request, array $options): void { // The handler should not be called }, ]); diff --git a/tests/lib/Http/Client/NegativeDnsCacheTest.php b/tests/lib/Http/Client/NegativeDnsCacheTest.php index ba91e95a906..eb0f86f5c7a 100644 --- a/tests/lib/Http/Client/NegativeDnsCacheTest.php +++ b/tests/lib/Http/Client/NegativeDnsCacheTest.php @@ -30,7 +30,7 @@ class NegativeDnsCacheTest extends \Test\TestCase { ->method('createLocal') ->with('NegativeDnsCache') ->willReturn($this->cache); - + $this->negativeDnsCache = new NegativeDnsCache($this->cacheFactory); } diff --git a/tests/lib/Http/Client/ResponseTest.php b/tests/lib/Http/Client/ResponseTest.php index 291dc287148..1acf1eb1cbd 100644 --- a/tests/lib/Http/Client/ResponseTest.php +++ b/tests/lib/Http/Client/ResponseTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |