From 0dcb223a3fbcae0bb2fafae9def5e9a2c9790afe Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 17 Jul 2024 12:40:08 +0200 Subject: [PATCH] Fixup to follow phpcs --- Tests/DeviceDetectorTest.php | 14 +++++++++----- Tests/Parser/Client/BrowserTest.php | 12 ++++++++---- Tests/Parser/Client/FeedReaderTest.php | 10 +++++++--- Tests/Parser/Client/MobileAppTest.php | 8 ++++++-- Tests/Parser/Client/PIMTest.php | 8 ++++++-- Tests/Parser/Device/NotebookTest.php | 8 ++++++-- 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Tests/DeviceDetectorTest.php b/Tests/DeviceDetectorTest.php index de0ffd4f30..748df3bff0 100644 --- a/Tests/DeviceDetectorTest.php +++ b/Tests/DeviceDetectorTest.php @@ -632,22 +632,26 @@ public static function getTypeMethodFixtures(): array { $fixturePath = \realpath(__DIR__ . '/Parser/fixtures/type-methods.yml'); + $fixtureData = \array_map(static function (array $item) { + return ['ua' => $item['user_agent'], 'checkTypes' => $item['check']]; + }, $fixtureData); + return \Spyc::YAMLLoad($fixturePath); } /** * @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 ); @@ -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 )); } diff --git a/Tests/Parser/Client/BrowserTest.php b/Tests/Parser/Client/BrowserTest.php index 1048455fcf..c46828722b 100644 --- a/Tests/Parser/Client/BrowserTest.php +++ b/Tests/Parser/Client/BrowserTest.php @@ -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)); @@ -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'] )); @@ -53,6 +53,10 @@ public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/browser.yml'); + $fixtureData = \array_map(static function (array $item) { + return ['useragent' => $item['user_agent'], 'client' => $item['client'], 'headers' => $item['headers'] ?? null]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Client/FeedReaderTest.php b/Tests/Parser/Client/FeedReaderTest.php index 4939d76091..38c126c24b 100644 --- a/Tests/Parser/Client/FeedReaderTest.php +++ b/Tests/Parser/Client/FeedReaderTest.php @@ -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) { + 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 c38317b44c..9add5b67c1 100644 --- a/Tests/Parser/Client/MobileAppTest.php +++ b/Tests/Parser/Client/MobileAppTest.php @@ -21,11 +21,11 @@ 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()); } @@ -33,6 +33,10 @@ public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/mobile_app.yml'); + $fixtureData = \array_map(static function (array $item) { + 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 5dd68aa6ab..f2ab52bacf 100644 --- a/Tests/Parser/Client/PIMTest.php +++ b/Tests/Parser/Client/PIMTest.php @@ -21,11 +21,11 @@ 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()); } @@ -33,6 +33,10 @@ public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/pim.yml'); + $fixtureData = \array_map(static function (array $item) { + return ['useragent' => $item['user_agent'], 'client' => $item['client']]; + }, $fixtureData); + return $fixtureData; } diff --git a/Tests/Parser/Device/NotebookTest.php b/Tests/Parser/Device/NotebookTest.php index 26db01a47d..1cc6d5e101 100644 --- a/Tests/Parser/Device/NotebookTest.php +++ b/Tests/Parser/Device/NotebookTest.php @@ -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()); @@ -35,6 +35,10 @@ public static function getFixtures(): array { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/notebook.yml'); + $fixtureData = \array_map(static function (array $item) { + return ['useragent' => $item['user_agent'], 'device' => $item['device']]; + }, $fixtureData); + return $fixtureData; } }