From 3b5aebb892956a8e761fafb4cab7d8273c3f5b43 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 16 Mar 2021 11:19:38 -0500 Subject: [PATCH] user_agents.json -> user_agents.dist.json --- .gitignore | 2 ++ Makefile | 4 ++-- bin/benchmark.php | 2 +- bin/constant_generator.php | 2 +- bin/init_user_agent.php | 2 +- bin/user_agent_sorter.php | 2 +- tests/UserAgentParserFunctionTest.php | 7 ++++++- tests/UserAgentParserObjectTest.php | 7 ++++++- tests/{user_agents.json => user_agents.dist.json} | 0 9 files changed, 20 insertions(+), 8 deletions(-) rename tests/{user_agents.json => user_agents.dist.json} (100%) diff --git a/.gitignore b/.gitignore index d426ba8..c45eed6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ vendor/ composer.lock coverage.xml phpunit.xml + +tests/user_agents.json \ No newline at end of file diff --git a/Makefile b/Makefile index 9281366..54ffee1 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ test: .PHONY: generate generate: - php bin/user_agent_sorter.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.json + php bin/user_agent_sorter.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.dist.json php bin/constant_generator.php .PHONY: init init: - php bin/init_user_agent.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.json + php bin/init_user_agent.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.dist.json make generate \ No newline at end of file diff --git a/bin/benchmark.php b/bin/benchmark.php index a47ea30..4f06139 100644 --- a/bin/benchmark.php +++ b/bin/benchmark.php @@ -4,7 +4,7 @@ $time = microtime(true); -$uas = json_decode(file_get_contents(__DIR__ . '/../tests/user_agents.json'), true); +$uas = json_decode(file_get_contents(__DIR__ . '/../tests/user_agents.dist.json'), true); foreach( $uas as $ua => $junk ) { diff --git a/bin/constant_generator.php b/bin/constant_generator.php index 34c2540..f69e19c 100644 --- a/bin/constant_generator.php +++ b/bin/constant_generator.php @@ -2,7 +2,7 @@ require __DIR__ . '/../vendor/autoload.php'; -$jsonfile = __DIR__ . '/../tests/user_agents.json'; +$jsonfile = __DIR__ . '/../tests/user_agents.dist.json'; $uas = json_decode( file_get_contents($jsonfile), diff --git a/bin/init_user_agent.php b/bin/init_user_agent.php index 80598c0..170d8e3 100644 --- a/bin/init_user_agent.php +++ b/bin/init_user_agent.php @@ -2,7 +2,7 @@ require(__DIR__ . '/../vendor/autoload.php'); -$jsonfile = __DIR__ . '/../Tests/user_agents.json'; +$jsonfile = __DIR__ . '/../Tests/user_agents.dist.json'; $uas = json_decode(file_get_contents($jsonfile), true); diff --git a/bin/user_agent_sorter.php b/bin/user_agent_sorter.php index 07c6fb8..10a6f69 100644 --- a/bin/user_agent_sorter.php +++ b/bin/user_agent_sorter.php @@ -2,7 +2,7 @@ require(__DIR__ . '/../vendor/autoload.php'); -$jsonfile = __DIR__ . '/../Tests/user_agents.json'; +$jsonfile = __DIR__ . '/../Tests/user_agents.dist.json'; $uas = json_decode(file_get_contents($jsonfile), true); diff --git a/tests/UserAgentParserFunctionTest.php b/tests/UserAgentParserFunctionTest.php index 7ea79cf..1dbdda9 100644 --- a/tests/UserAgentParserFunctionTest.php +++ b/tests/UserAgentParserFunctionTest.php @@ -12,7 +12,12 @@ public function test_parse_user_agent( $string, $expected ) { public function userAgentDataProvider() { $out = array(); - $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.json'), true); + if( filesize(__DIR__ . '/user_agents.json') > 0 ) { + $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.json'), true); + } else { + $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.dist.json'), true); + } + foreach( $uas as $string => $parts ) { $out[] = array( $string, $parts ); } diff --git a/tests/UserAgentParserObjectTest.php b/tests/UserAgentParserObjectTest.php index a7d54d1..54e3c3b 100644 --- a/tests/UserAgentParserObjectTest.php +++ b/tests/UserAgentParserObjectTest.php @@ -6,7 +6,12 @@ class UserAgentParserObjectTest extends \PHPUnit\Framework\TestCase { public function userAgentDataProvider() { $out = array(); - $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.json'), true); + if( filesize(__DIR__ . '/user_agents.json') > 0 ) { + $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.json'), true); + } else { + $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.dist.json'), true); + } + foreach( $uas as $string => $parts ) { $out[] = array( $string ); } diff --git a/tests/user_agents.json b/tests/user_agents.dist.json similarity index 100% rename from tests/user_agents.json rename to tests/user_agents.dist.json