Skip to content

Commit

Permalink
Make tests compatible with newer phpunit versions
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Dec 22, 2024
1 parent fbd5f4f commit 940a837
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 25 deletions.
22 changes: 13 additions & 9 deletions Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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"';
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions Tests/Parser/Client/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Client/FeedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Client/LibraryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Client/MediaPlayerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Client/MobileAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Client/PIMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Parser/Device/CameraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion Tests/Parser/Device/CarBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion Tests/Parser/Device/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion Tests/Parser/Device/NotebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 8 additions & 4 deletions Tests/Parser/OperatingSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion Tests/Parser/VendorFragmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 940a837

Please sign in to comment.