diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index f4d2625406..12b280713e 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -22,13 +22,13 @@ jobs: name: PHPCS runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: composer install --dev --prefer-dist --no-progress --no-suggest --ignore-platform-reqs + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '7.2' tools: cs2pr + - name: Install dependencies + run: composer install --dev --prefer-dist --no-progress --no-suggest - name: Run phpcs run: ./vendor/bin/phpcs -q --report=checkstyle | cs2pr diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index e30505f0d9..dcc23ab028 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -29,10 +29,9 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - tools: composer:v2 - name: "Composer install" run: | - composer install --ignore-platform-reqs + composer install --ignore-platform-req=php+ - name: PHPStan run: | php -v diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index ab1482444c..5ee4325b34 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -24,20 +24,30 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - php-version: ['7.2', '8.4'] + php-version: ['7.2'] + composer-options: [''] include: - php-version: 7.3 os: ubuntu-latest + composer-options: '' - php-version: 7.4 os: ubuntu-latest + composer-options: '' - php-version: 8.0 os: ubuntu-latest + composer-options: '' - php-version: 8.1 os: ubuntu-latest + composer-options: '' - php-version: 8.2 os: ubuntu-latest + composer-options: '' - php-version: 8.3 os: ubuntu-latest + composer-options: '' + - php-version: 8.4 + os: ubuntu-latest + composer-options: '--ignore-platform-req=php+' steps: - uses: actions/checkout@v4 - name: Install PHP @@ -48,8 +58,8 @@ jobs: extensions: memcached - name: "Composer install" run: | - composer install --ignore-platform-reqs - composer require doctrine/cache ~1.2 --ignore-platform-reqs + composer install ${{ matrix.composer-options }} + composer require doctrine/cache ~1.2 ${{ matrix.composer-options }} - name: PHPUnit / PHP ${{ matrix.php-version }} run: | php -v diff --git a/.gitignore b/.gitignore index fbf9f5df16..3640cfb77a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.phar .buildpath .project .settings +.phpunit.result.cache diff --git a/Tests/DeviceDetectorTest.php b/Tests/DeviceDetectorTest.php index a74859cc5b..cdf2db99e2 100644 --- a/Tests/DeviceDetectorTest.php +++ b/Tests/DeviceDetectorTest.php @@ -247,7 +247,7 @@ public function testParse(array $fixtureData): void $this->assertEquals($fixtureData, $uaInfo, $errorMessage); } - public function getFixtures(): \Generator + public static function getFixtures(): \Generator { $fixtureFiles = \glob(\realpath(__DIR__) . '/fixtures/*.yml'); @@ -298,7 +298,7 @@ public function testParseClient(array $fixtureData): void $this->assertEquals($fixtureData['client'], $uaInfo['client'], $messageError); } - public function getFixturesClient(): \Generator + public static function getFixturesClient(): \Generator { $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Client/fixtures/*.yml'); @@ -335,7 +335,7 @@ public function testParseDevice(array $fixtureData): void $this->assertEquals($fixtureData['device'], $uaInfo['device']); } - public function getFixturesDevice(): \Generator + public static function getFixturesDevice(): \Generator { $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Device/fixtures/*.yml'); @@ -348,7 +348,7 @@ public function getFixturesDevice(): \Generator } } - public function getFixturesDeviceTypeFromClientHints(): array + public static function getFixturesDeviceTypeFromClientHints(): array { $useragent = 'Some Unknown UA'; $deviceName = '"Some Unknown Model"'; @@ -477,7 +477,7 @@ public function testVersionTruncation(string $useragent, int $truncationType, st AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_NONE); } - public function getVersionTruncationFixtures(): array + public static function getVersionTruncationFixtures(): array { return [ ['Mozilla/5.0 (Linux; Android 4.2.2; ARCHOS 101 PLATINUM Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Safari/537.36', AbstractParser::VERSION_TRUNCATION_NONE, '4.2.2', '34.0.1847.114'], @@ -604,7 +604,7 @@ public function testParseBots(array $fixtureData): void ); } - public function getBotFixtures(): array + public static function getBotFixtures(): array { $fixturesPath = \realpath(__DIR__ . '/fixtures/bots.yml'); $fixtures = \Spyc::YAMLLoad($fixturesPath); @@ -704,11 +704,15 @@ public function testGetClient(): void $this->assertEquals($expected, $dd->getClient()); } - public function getTypeMethodFixtures(): array + public static function getTypeMethodFixtures(): array { - $fixturePath = \realpath(__DIR__ . '/Parser/fixtures/type-methods.yml'); + $fixtureData = \Spyc::YAMLLoad(\realpath(__DIR__ . '/Parser/fixtures/type-methods.yml')); - return \Spyc::YAMLLoad($fixturePath); + $fixtureData = \array_map(static function (array $item): array { + return ['ua' => $item['user_agent'], 'checkTypes' => $item['check']]; + }, $fixtureData); + + return $fixtureData; } /** diff --git a/Tests/Parser/Client/BrowserTest.php b/Tests/Parser/Client/BrowserTest.php index d52600c063..c096f819b0 100644 --- a/Tests/Parser/Client/BrowserTest.php +++ b/Tests/Parser/Client/BrowserTest.php @@ -49,10 +49,14 @@ public function testParse(string $useragent, array $client, ?array $headers = nu self::$browsersTested[] = $client['name']; } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/browser.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client'], 'headers' => $item['headers'] ?? null]; + }, $fixtureData); + return $fixtureData; } @@ -133,7 +137,7 @@ public function testShortCodesComparisonWithBrowsers(): void /** * @return array */ - public function getFixturesBrowserHints(): array + public static function getFixturesBrowserHints(): array { $method = new \ReflectionMethod(BrowserHints::class, 'getRegexes'); $method->setAccessible(true); diff --git a/Tests/Parser/Client/FeedReaderTest.php b/Tests/Parser/Client/FeedReaderTest.php index c8fd3ca74a..4d4cba3a9c 100644 --- a/Tests/Parser/Client/FeedReaderTest.php +++ b/Tests/Parser/Client/FeedReaderTest.php @@ -29,10 +29,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $feedReaderParser->parse(), "UserAgent: {$useragent}"); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/feed_reader.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Client/LibraryTest.php b/Tests/Parser/Client/LibraryTest.php index a9baa68ee3..7161209390 100644 --- a/Tests/Parser/Client/LibraryTest.php +++ b/Tests/Parser/Client/LibraryTest.php @@ -29,10 +29,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $libraryParser->parse()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/library.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Client/MediaPlayerTest.php b/Tests/Parser/Client/MediaPlayerTest.php index b8ca8482ea..b69e68d188 100644 --- a/Tests/Parser/Client/MediaPlayerTest.php +++ b/Tests/Parser/Client/MediaPlayerTest.php @@ -29,10 +29,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $mediaPlayerParser->parse()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/mediaplayer.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Client/MobileAppTest.php b/Tests/Parser/Client/MobileAppTest.php index c15da0f6a2..cda42c5917 100644 --- a/Tests/Parser/Client/MobileAppTest.php +++ b/Tests/Parser/Client/MobileAppTest.php @@ -29,10 +29,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $mobileAppParser->parse()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/mobile_app.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Client/PIMTest.php b/Tests/Parser/Client/PIMTest.php index 27a389143c..1c9f781f2c 100644 --- a/Tests/Parser/Client/PIMTest.php +++ b/Tests/Parser/Client/PIMTest.php @@ -29,10 +29,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $PIMParser->parse()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/pim.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Device/CameraTest.php b/Tests/Parser/Device/CameraTest.php index c429fe2bb6..5b1ec2dd89 100644 --- a/Tests/Parser/Device/CameraTest.php +++ b/Tests/Parser/Device/CameraTest.php @@ -31,10 +31,14 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/camera.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'device' => $item['device']]; + }, $fixtureData); + return $fixtureData; } } diff --git a/Tests/Parser/Device/CarBrowserTest.php b/Tests/Parser/Device/CarBrowserTest.php index 2758e07dd1..03919aaa92 100644 --- a/Tests/Parser/Device/CarBrowserTest.php +++ b/Tests/Parser/Device/CarBrowserTest.php @@ -31,10 +31,14 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/car_browser.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'device' => $item['device']]; + }, $fixtureData); + return $fixtureData; } } diff --git a/Tests/Parser/Device/ConsoleTest.php b/Tests/Parser/Device/ConsoleTest.php index 83c4593978..1d78acebab 100644 --- a/Tests/Parser/Device/ConsoleTest.php +++ b/Tests/Parser/Device/ConsoleTest.php @@ -31,10 +31,14 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/console.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'device' => $item['device']]; + }, $fixtureData); + return $fixtureData; } } diff --git a/Tests/Parser/Device/NotebookTest.php b/Tests/Parser/Device/NotebookTest.php index 9801229341..a7015e43d2 100644 --- a/Tests/Parser/Device/NotebookTest.php +++ b/Tests/Parser/Device/NotebookTest.php @@ -31,10 +31,14 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $notebookParser->getModel()); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/notebook.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'device' => $item['device']]; + }, $fixtureData); + return $fixtureData; } } diff --git a/Tests/Parser/OperatingSystemTest.php b/Tests/Parser/OperatingSystemTest.php index e68a2609a4..8873ac0909 100644 --- a/Tests/Parser/OperatingSystemTest.php +++ b/Tests/Parser/OperatingSystemTest.php @@ -37,10 +37,14 @@ public function testParse(string $useragent, array $os, ?array $headers = null): self::$osTested[] = $os['name']; } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/oss.yml'); + $fixtureData = \array_map(static function (array $item): array { + return ['useragent' => $item['user_agent'], 'os' => $item['os'], 'headers' => $item['headers'] ?? null]; + }, $fixtureData); + return $fixtureData; } @@ -53,7 +57,7 @@ public function testOSInGroup(string $os): void $this->assertContains($os, $familyOs); } - public function getAllOs(): array + public static function getAllOs(): array { $allOs = \array_keys(OperatingSystem::getAvailableOperatingSystems()); $allOs = \array_map(static function ($os) { @@ -72,7 +76,7 @@ public function testFamilyOSExists(string $os): void $this->assertContains($os, $allOs); } - public function getAllFamilyOs(): array + public static function getAllFamilyOs(): array { $allFamilyOs = \call_user_func_array('array_merge', \array_values(OperatingSystem::getAvailableOperatingSystemFamilies())); $allFamilyOs = \array_map(static function ($os) { @@ -95,7 +99,7 @@ public function testGetNameFromId(string $os, string $version, ?string $expected $this->assertEquals($expected, OperatingSystem::getNameFromId($os, $version)); } - public function getNameFromIds(): array + public static function getNameFromIds(): array { return [ ['DEB', '4.5', 'Debian 4.5'], diff --git a/Tests/Parser/VendorFragmentTest.php b/Tests/Parser/VendorFragmentTest.php index fbeb7af4c4..af7f294635 100644 --- a/Tests/Parser/VendorFragmentTest.php +++ b/Tests/Parser/VendorFragmentTest.php @@ -31,7 +31,7 @@ public function testParse(string $useragent, string $vendor): void self::$regexesTested[] = $vfParser->getMatchedRegex(); } - public function getFixtures(): array + public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/vendorfragments.yml'); diff --git a/composer.json b/composer.json index 46d7dda060..09e141e2e5 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "mustangostang/spyc": "*" }, "require-dev": { - "phpunit/phpunit": "^8.5.8", + "phpunit/phpunit": "^8.5.2 || ^9 || ^10 || ^11", "psr/cache": "^1.0.1", "psr/simple-cache": "^1.0.1", "matthiasmullie/scrapbook": "^1.4.7",