Skip to content

Commit

Permalink
Fixup to follow phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jul 17, 2024
1 parent 10faa34 commit 76b7e67
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 33 deletions.
18 changes: 11 additions & 7 deletions Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,24 +630,28 @@ public function testGetClient(): void

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
*/
public function testTypeMethods(string $user_agent, array $check): void
public function testTypeMethods(string $ua, array $checkTypes): void
{
try {
$dd = $this->getDeviceDetector();
$dd->discardBotInformation();
$dd->setUserAgent($user_agent);
$dd->setUserAgent($ua);
$dd->parse();
} catch (\Exception $exception) {
throw new \Exception(
\sprintf('Error: %s from useragent %s', $exception->getMessage(), $user_agent),
\sprintf('Error: %s from useragent %s', $exception->getMessage(), $ua),
$exception->getCode(),
$exception
);
Expand All @@ -656,10 +660,10 @@ public function testTypeMethods(string $user_agent, array $check): void
$this->assertEquals([
$dd->isBot(), $dd->isMobile(), $dd->isDesktop(),
$dd->isTablet(), $dd->isTV(), $dd->isWearable(),
], $check, \sprintf(
], $checkTypes, \sprintf(
"test: %s\nfrom useragent %s",
'[isBot(), isMobile(), isDesktop(), isTablet(), isTV(), isWearable()]',
$user_agent
$ua
));
}

Expand Down
12 changes: 8 additions & 4 deletions Tests/Parser/Client/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class BrowserTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client, ?array $headers = null): void
public function testParse(string $useragent, array $client, ?array $headers = null): void
{
$browserParser = new Browser();
$browserParser->setVersionTruncation(Browser::VERSION_TRUNCATION_NONE);
$browserParser->setUserAgent($user_agent);
$browserParser->setUserAgent($useragent);

if (null !== $headers) {
$browserParser->setClientHints(ClientHints::factory($headers));
Expand All @@ -39,10 +39,10 @@ public function testParse(string $user_agent, array $client, ?array $headers = n
$browser = $browserParser->parse();
unset($browser['short_name']);

$this->assertEquals($client, $browser, "UserAgent: {$user_agent}");
$this->assertEquals($client, $browser, "UserAgent: {$useragent}");
$this->assertTrue($this->checkBrowserEngine($browser['engine']), \sprintf(
"UserAgent: %s\nEngine wrong name: `%s`",
$user_agent,
$useragent,
$browser['engine']
));

Expand All @@ -53,6 +53,10 @@ 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
10 changes: 7 additions & 3 deletions Tests/Parser/Client/FeedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class FeedReaderTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client): void
public function testParse(string $useragent, array $client): void
{
$feedReaderParser = new FeedReader();
$feedReaderParser->setVersionTruncation(FeedReader::VERSION_TRUNCATION_NONE);
$feedReaderParser->setUserAgent($user_agent);
$this->assertEquals($client, $feedReaderParser->parse(), "UserAgent: {$user_agent}");
$feedReaderParser->setUserAgent($useragent);
$this->assertEquals($client, $feedReaderParser->parse(), "UserAgent: {$useragent}");
}

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
8 changes: 6 additions & 2 deletions Tests/Parser/Client/LibraryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class LibraryTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client): void
public function testParse(string $useragent, array $client): void
{
$libraryParser = new Library();
$libraryParser->setVersionTruncation(Library::VERSION_TRUNCATION_NONE);
$libraryParser->setUserAgent($user_agent);
$libraryParser->setUserAgent($useragent);
$this->assertEquals($client, $libraryParser->parse());
}

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
8 changes: 6 additions & 2 deletions Tests/Parser/Client/MediaPlayerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class MediaPlayerTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client): void
public function testParse(string $useragent, array $client): void
{
$mediaPlayerParser = new MediaPlayer();
$mediaPlayerParser->setVersionTruncation(MediaPlayer::VERSION_TRUNCATION_NONE);
$mediaPlayerParser->setUserAgent($user_agent);
$mediaPlayerParser->setUserAgent($useragent);
$this->assertEquals($client, $mediaPlayerParser->parse());
}

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
8 changes: 6 additions & 2 deletions Tests/Parser/Client/MobileAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class MobileAppTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client): void
public function testParse(string $useragent, array $client): void
{
$mobileAppParser = new MobileApp();
$mobileAppParser->setVersionTruncation(MobileApp::VERSION_TRUNCATION_NONE);
$mobileAppParser->setUserAgent($user_agent);
$mobileAppParser->setUserAgent($useragent);
$this->assertEquals($client, $mobileAppParser->parse());
}

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
8 changes: 6 additions & 2 deletions Tests/Parser/Client/PIMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class PIMTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $client): void
public function testParse(string $useragent, array $client): void
{
$PIMParser = new PIM();
$PIMParser->setVersionTruncation(PIM::VERSION_TRUNCATION_NONE);
$PIMParser->setUserAgent($user_agent);
$PIMParser->setUserAgent($useragent);
$this->assertEquals($client, $PIMParser->parse());
}

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
8 changes: 6 additions & 2 deletions Tests/Parser/Device/CameraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class CameraTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $device): void
public function testParse(string $useragent, array $device): void
{
$consoleParser = new Camera();
$consoleParser->setUserAgent($user_agent);
$consoleParser->setUserAgent($useragent);
$this->assertTrue(\is_array($consoleParser->parse()));
$this->assertEquals($device['type'], Camera::getDeviceName($consoleParser->getDeviceType()));
$this->assertEquals($device['brand'], $consoleParser->getBrand());
Expand All @@ -35,6 +35,10 @@ 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;
}
}
8 changes: 6 additions & 2 deletions Tests/Parser/Device/CarBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class CarBrowserTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $device): void
public function testParse(string $useragent, array $device): void
{
$consoleParser = new CarBrowser();
$consoleParser->setUserAgent($user_agent);
$consoleParser->setUserAgent($useragent);
$this->assertTrue(\is_array($consoleParser->parse()));
$this->assertEquals($device['type'], CarBrowser::getDeviceName($consoleParser->getDeviceType()));
$this->assertEquals($device['brand'], $consoleParser->getBrand());
Expand All @@ -35,6 +35,10 @@ 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;
}
}
8 changes: 6 additions & 2 deletions Tests/Parser/Device/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ConsoleTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $device): void
public function testParse(string $useragent, array $device): void
{
$consoleParser = new Console();
$consoleParser->setUserAgent($user_agent);
$consoleParser->setUserAgent($useragent);
$this->assertTrue(\is_array($consoleParser->parse()));
$this->assertEquals($device['type'], Console::getDeviceName($consoleParser->getDeviceType()));
$this->assertEquals($device['brand'], $consoleParser->getBrand());
Expand All @@ -35,6 +35,10 @@ 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;
}
}
8 changes: 6 additions & 2 deletions Tests/Parser/Device/NotebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class NotebookTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $device): void
public function testParse(string $useragent, array $device): void
{
$notebookParser = new Notebook();
$notebookParser->setUserAgent($user_agent);
$notebookParser->setUserAgent($useragent);
$this->assertNotNull($notebookParser->parse());
$this->assertEquals($device['type'], Notebook::getDeviceName($notebookParser->getDeviceType()));
$this->assertEquals($device['brand'], $notebookParser->getBrand());
Expand All @@ -35,6 +35,10 @@ 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;
}
}
10 changes: 7 additions & 3 deletions Tests/Parser/OperatingSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ class OperatingSystemTest extends TestCase
/**
* @dataProvider getFixtures
*/
public function testParse(string $user_agent, array $os, ?array $headers = null): void
public function testParse(string $useragent, array $os, ?array $headers = null): void
{
$osParser = new OperatingSystem();
$osParser->setUserAgent($user_agent);
$osParser->setUserAgent($useragent);

if (null !== $headers) {
$osParser->setClientHints(ClientHints::factory($headers));
}

$this->assertEquals($os, $osParser->parse(), "UserAgent: {$user_agent}");
$this->assertEquals($os, $osParser->parse(), "UserAgent: {$useragent}");
self::$osTested[] = $os['name'];
}

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 Down

0 comments on commit 76b7e67

Please sign in to comment.