From 1bae97044671ba0d7b00b019bc7ab7dc6bac2021 Mon Sep 17 00:00:00 2001 From: Eddie Palmans Date: Thu, 4 Aug 2022 12:06:41 +0200 Subject: [PATCH 1/5] Allow to pass geography parameter explicitly --- src/OpenFoodFacts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenFoodFacts.php b/src/OpenFoodFacts.php index a48d815..c30ed32 100644 --- a/src/OpenFoodFacts.php +++ b/src/OpenFoodFacts.php @@ -11,10 +11,10 @@ class OpenFoodFacts extends OpenFoodFactsApiWrapper { protected $max_results; - public function __construct(Container $app) + public function __construct(Container $app, string $geography = null) { parent::__construct([ - 'geography' => $app['config']->get('openfoodfacts.geography'), + 'geography' => $geography ?? $app['config']->get('openfoodfacts.geography'), 'app' => $app['config']->get('app.name'), ], $app['cache.store']); From 809905e2434dc26c049f2d40745e16ff764c33a2 Mon Sep 17 00:00:00 2001 From: Eddie Palmans Date: Thu, 4 Aug 2022 12:06:48 +0200 Subject: [PATCH 2/5] tests --- tests/GeographyTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/GeographyTest.php diff --git a/tests/GeographyTest.php b/tests/GeographyTest.php new file mode 100644 index 0000000..f155b51 --- /dev/null +++ b/tests/GeographyTest.php @@ -0,0 +1,32 @@ +make(OpenFoodFacts::class); + $product_default_content = $instanceWorld->barcode('8714200216964'); + + $instanceNL = app()->make(OpenFoodFacts::class, ['geography' => 'nl']); + $product_dutch_content = $instanceNL->barcode('8714200216964'); + + $this->assertEquals($product_default_content['_id'], $product_dutch_content['_id']); + $this->assertNotEquals($product_default_content, $product_dutch_content); + } + + /** @test */ + public function it_returns_geo_specific_content_through_config_setting() + { + Config::set('openfoodfacts.geography', 'nl'); + $product_dutch_content = OpenFoodFactsFacade::barcode('8714200216964'); + + $this->assertStringContainsString('front_nl.', $product_dutch_content['image_url']); + } +} From a52cb0b61adee1ed9a531663ba673a8308a737a2 Mon Sep 17 00:00:00 2001 From: Eddie Palmans Date: Mon, 8 Aug 2022 12:13:16 +0200 Subject: [PATCH 3/5] minor: barcode as variabele in tests (to please SonarCloud - Code Smell detection) --- tests/GeographyTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/GeographyTest.php b/tests/GeographyTest.php index f155b51..49ed89b 100644 --- a/tests/GeographyTest.php +++ b/tests/GeographyTest.php @@ -11,11 +11,13 @@ class GeographyTest extends Base\FacadeTestCase /** @test */ public function it_returns_different_content_based_on_geography_parameter() { + $barcode = '8714200216964'; + $instanceWorld = app()->make(OpenFoodFacts::class); - $product_default_content = $instanceWorld->barcode('8714200216964'); + $product_default_content = $instanceWorld->barcode($barcode); $instanceNL = app()->make(OpenFoodFacts::class, ['geography' => 'nl']); - $product_dutch_content = $instanceNL->barcode('8714200216964'); + $product_dutch_content = $instanceNL->barcode($barcode); $this->assertEquals($product_default_content['_id'], $product_dutch_content['_id']); $this->assertNotEquals($product_default_content, $product_dutch_content); From a464f94dd755c731becf2dbe05af31792eebdb46 Mon Sep 17 00:00:00 2001 From: Eddie Palmans Date: Mon, 8 Aug 2022 12:32:37 +0200 Subject: [PATCH 4/5] force deepsource ci rerun From 98fe63f6732282cca4be933314024c18387ad133 Mon Sep 17 00:00:00 2001 From: Eddie Palmans Date: Tue, 9 Aug 2022 16:12:23 +0200 Subject: [PATCH 5/5] force deepsource ci rerun #2