diff options
Diffstat (limited to 'tests/lib/Updater/ChangesCheckTest.php')
-rw-r--r-- | tests/lib/Updater/ChangesCheckTest.php | 80 |
1 files changed, 27 insertions, 53 deletions
diff --git a/tests/lib/Updater/ChangesCheckTest.php b/tests/lib/Updater/ChangesCheckTest.php index 4afb9f05a5b..dd0d97a9e80 100644 --- a/tests/lib/Updater/ChangesCheckTest.php +++ b/tests/lib/Updater/ChangesCheckTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Updater; @@ -59,7 +42,7 @@ class ChangesCheckTest extends TestCase { $this->checker = new ChangesCheck($this->clientService, $this->mapper, $this->logger); } - public function statusCodeProvider():array { + public static function statusCodeProvider(): array { return [ [200, ChangesCheck::RESPONSE_HAS_CONTENT], [304, ChangesCheck::RESPONSE_USE_CACHE], @@ -68,10 +51,8 @@ class ChangesCheckTest extends TestCase { ]; } - /** - * @dataProvider statusCodeProvider - */ - public function testEvaluateResponse(int $statusCode, int $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('statusCodeProvider')] + public function testEvaluateResponse(int $statusCode, int $expected): void { $response = $this->createMock(IResponse::class); $response->expects($this->atLeastOnce()) ->method('getStatusCode') @@ -86,13 +67,15 @@ class ChangesCheckTest extends TestCase { $this->assertSame($expected, $evaluation); } - public function testCacheResultInsert() { + public function testCacheResultInsert(): void { $version = '13.0.4'; $entry = $this->createMock(Changes::class); $entry->expects($this->exactly(2)) ->method('__call') - ->withConsecutive(['getVersion'], ['setVersion', [$version]]) - ->willReturnOnConsecutiveCalls('', null); + ->willReturnMap([ + ['getVersion', [], ''], + ['setVersion', [$version], null], + ]); $this->mapper->expects($this->once()) ->method('insert'); @@ -102,7 +85,7 @@ class ChangesCheckTest extends TestCase { $this->invokePrivate($this->checker, 'cacheResult', [$entry, $version]); } - public function testCacheResultUpdate() { + public function testCacheResultUpdate(): void { $version = '13.0.4'; $entry = $this->createMock(Changes::class); $entry->expects($this->once()) @@ -117,7 +100,7 @@ class ChangesCheckTest extends TestCase { $this->invokePrivate($this->checker, 'cacheResult', [$entry, $version]); } - public function changesXMLProvider(): array { + public static function changesXMLProvider(): array { return [ [ # 0 - full example '<?xml version="1.0" encoding="utf-8" ?> @@ -286,25 +269,21 @@ class ChangesCheckTest extends TestCase { ]; } - /** - * @dataProvider changesXMLProvider - */ - public function testExtractData(string $body, array $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('changesXMLProvider')] + public function testExtractData(string $body, array $expected): void { $actual = $this->invokePrivate($this->checker, 'extractData', [$body]); $this->assertSame($expected, $actual); } - public function etagProvider() { + public static function etagProvider() { return [ [''], ['a27aab83d8205d73978435076e53d143'] ]; } - /** - * @dataProvider etagProvider - */ - public function testQueryChangesServer(string $etag) { + #[\PHPUnit\Framework\Attributes\DataProvider('etagProvider')] + public function testQueryChangesServer(string $etag): void { $uri = 'https://changes.nextcloud.server/?13.0.5'; $entry = $this->createMock(Changes::class); $entry->expects($this->any()) @@ -327,7 +306,7 @@ class ChangesCheckTest extends TestCase { $this->assertInstanceOf(IResponse::class, $response); } - public function versionProvider(): array { + public static function versionProvider(): array { return [ ['13.0.7', '13.0.7'], ['13.0.7.3', '13.0.7'], @@ -338,30 +317,25 @@ class ChangesCheckTest extends TestCase { ]; } - /** - * @dataProvider versionProvider - */ - public function testNormalizeVersion(string $input, string $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')] + public function testNormalizeVersion(string $input, string $expected): void { $normalized = $this->checker->normalizeVersion($input); $this->assertSame($expected, $normalized); } - public function changeDataProvider():array { - $testDataFound = $testDataNotFound = $this->versionProvider(); - array_walk($testDataFound, function (&$params) { + public static function changeDataProvider():array { + $testDataFound = $testDataNotFound = self::versionProvider(); + array_walk($testDataFound, static function (&$params): void { $params[] = true; }); - array_walk($testDataNotFound, function (&$params) { + array_walk($testDataNotFound, static function (&$params): void { $params[] = false; }); return array_merge($testDataFound, $testDataNotFound); } - /** - * @dataProvider changeDataProvider - * - */ - public function testGetChangesForVersion(string $inputVersion, string $normalizedVersion, bool $isFound) { + #[\PHPUnit\Framework\Attributes\DataProvider('changeDataProvider')] + public function testGetChangesForVersion(string $inputVersion, string $normalizedVersion, bool $isFound): void { $mocker = $this->mapper->expects($this->once()) ->method('getChanges') ->with($normalizedVersion); @@ -385,7 +359,7 @@ class ChangesCheckTest extends TestCase { $this->assertTrue(isset($data['changelogURL'])); } - public function testGetChangesForVersionEmptyData() { + public function testGetChangesForVersionEmptyData(): void { $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') |