Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ misc/ export-ignore
phpunit.xml.dist text eol=lf export-ignore
.gitignore text eol=lf export-ignore
.gitattributes text eol=lf export-ignore
.phpcs.xml text eol=lf export-ignore
phpcs.xml text eol=lf export-ignore
phpstan.neon text eol=lf export-ignore
.yamllint text eol=lf export-ignore
6 changes: 3 additions & 3 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
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
5 changes: 2 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: composer:v2
- name: "Composer install"
run: |
composer install --ignore-platform-reqs
composer install --ignore-platform-req=php+
- name: PHPStan
run: |
php -v
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,42 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
php-version: ['7.2', '8.5']
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
- php-version: 8.4
os: ubuntu-latest
composer-options: ''
- php-version: nightly
os: ubuntu-latest
composer-options: '--ignore-platform-req=php+'
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2
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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/regular_expressions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
name: Validate regular expressions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1.97.0
uses: ruby/setup-ruby@v1.269.0
with:
ruby-version: '3.1'
bundler-cache: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
name: YAML Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: YAML Lint
uses: ibiqlik/action-yamllint@v3.0.1
uses: ibiqlik/action-yamllint@v3.1.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.phar
.buildpath
.project
.settings
.phpunit.result.cache
Comment thread
williamdes marked this conversation as resolved.
30 changes: 21 additions & 9 deletions Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use DeviceDetector\Parser\Device\Mobile;
use DeviceDetector\Yaml\Symfony;
use Doctrine\Common\Cache\MemcachedCache;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class DeviceDetectorTest extends TestCase
Expand Down Expand Up @@ -219,6 +220,7 @@ public function testIsParsed(): void
/**
* @dataProvider getFixtures
*/
#[DataProvider('getFixtures')]
public function testParse(array $fixtureData): void
{
$ua = $fixtureData['user_agent'];
Expand Down Expand Up @@ -247,7 +249,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');

Expand All @@ -268,6 +270,7 @@ public function getFixtures(): \Generator
/**
* @dataProvider getFixturesClient
*/
#[DataProvider('getFixturesClient')]
public function testParseClient(array $fixtureData): void
{
$ua = $fixtureData['user_agent'];
Expand Down Expand Up @@ -298,7 +301,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');

Expand All @@ -314,6 +317,7 @@ public function getFixturesClient(): \Generator
/**
* @dataProvider getFixturesDevice
*/
#[DataProvider('getFixturesDevice')]
public function testParseDevice(array $fixtureData): void
{
$ua = $fixtureData['user_agent'];
Expand All @@ -335,7 +339,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');

Expand All @@ -348,7 +352,7 @@ public function getFixturesDevice(): \Generator
}
}

public function getFixturesDeviceTypeFromClientHints(): array
public static function getFixturesDeviceTypeFromClientHints(): array
{
$useragent = 'Some Unknown UA';
$deviceName = '"Some Unknown Model"';
Expand Down Expand Up @@ -417,6 +421,7 @@ public function getFixturesDeviceTypeFromClientHints(): array
/**
* @dataProvider getFixturesDeviceTypeFromClientHints
*/
#[DataProvider('getFixturesDeviceTypeFromClientHints')]
public function testDetectDeviceTypeFromClientHints(string $useragent, array $headers, int $device): void
{
$clientHints = ClientHints::factory($headers);
Expand Down Expand Up @@ -467,6 +472,7 @@ public function testInstanceReusage(): void
/**
* @dataProvider getVersionTruncationFixtures
*/
#[DataProvider('getVersionTruncationFixtures')]
public function testVersionTruncation(string $useragent, int $truncationType, string $osVersion, string $clientVersion): void
{
AbstractParser::setVersionTruncation($truncationType);
Expand All @@ -477,7 +483,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'],
Expand Down Expand Up @@ -558,6 +564,7 @@ public function testVersionTruncationForClientHints(): void
/**
* @dataProvider getBotFixtures
*/
#[DataProvider('getBotFixtures')]
public function testParseBots(array $fixtureData): void
{
$ua = $fixtureData['user_agent'];
Expand Down Expand Up @@ -604,7 +611,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);
Expand Down Expand Up @@ -704,16 +711,21 @@ 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;
}

/**
* @dataProvider getTypeMethodFixtures
*/
#[DataProvider('getTypeMethodFixtures')]
public function testTypeMethods(string $ua, array $checkTypes): void
{
try {
Expand Down
29 changes: 24 additions & 5 deletions Tests/Parser/Client/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use DeviceDetector\Parser\Client\Browser;
use DeviceDetector\Parser\Client\Browser\Engine;
use DeviceDetector\Parser\Client\Hints\BrowserHints;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spyc;

Expand All @@ -26,6 +27,7 @@ class BrowserTest extends TestCase
/**
* @dataProvider getFixtures
*/
#[DataProvider('getFixtures')]
public function testParse(string $useragent, array $client, ?array $headers = null): void
{
$browserParser = new Browser();
Expand All @@ -49,10 +51,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;
}

Expand Down Expand Up @@ -109,11 +115,19 @@ public function testShortCodesComparisonWithBrowsers(): void
{
$reflectionClass = new \ReflectionClass(Browser::class);
$browserProperty = $reflectionClass->getProperty('availableBrowsers');
$browserProperty->setAccessible(true);

if (PHP_VERSION_ID < 80500) {
$browserProperty->setAccessible(true);
}

$availableBrowsers = $browserProperty->getValue();

$browserFamilyProperty = $reflectionClass->getProperty('browserFamilies');
$browserFamilyProperty->setAccessible(true);

if (PHP_VERSION_ID < 80500) {
$browserFamilyProperty->setAccessible(true);
}

$browserFamilies = $browserFamilyProperty->getValue();
$result = [];

Expand All @@ -133,10 +147,14 @@ public function testShortCodesComparisonWithBrowsers(): void
/**
* @return array
*/
public function getFixturesBrowserHints(): array
public static function getFixturesBrowserHints(): array
{
$method = new \ReflectionMethod(BrowserHints::class, 'getRegexes');
$method->setAccessible(true);

if (PHP_VERSION_ID < 80500) {
$method->setAccessible(true);
}

$hints = $method->invoke(new BrowserHints());
$fixtures = [];

Expand All @@ -150,6 +168,7 @@ public function getFixturesBrowserHints(): array
/**
* @dataProvider getFixturesBrowserHints
*/
#[DataProvider('getFixturesBrowserHints')]
public function testBrowserHintsForAvailableBrowsers(string $name): void
{
$browserShort = Browser::getBrowserShortName($name);
Expand Down
8 changes: 7 additions & 1 deletion Tests/Parser/Client/FeedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace DeviceDetector\Tests\Parser\Client;

use DeviceDetector\Parser\Client\FeedReader;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spyc;

Expand All @@ -21,6 +22,7 @@ class FeedReaderTest extends TestCase
/**
* @dataProvider getFixtures
*/
#[DataProvider('getFixtures')]
public function testParse(string $useragent, array $client): void
{
$feedReaderParser = new FeedReader();
Expand All @@ -29,10 +31,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;
}

Expand Down
Loading