From 908c6c8024f1265b1548614073cb5fd052f0c5b7 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 2 Mar 2024 11:16:57 +0330 Subject: [PATCH] create test directory --- app/Services/NominatimService.php | 24 +++++++++++++++++++++++- tests/CreatesApplication.php | 21 +++++++++++++++++++++ tests/Feature/Services/NominatimTest.php | 22 ++++++++++++++++++++++ tests/TestCase.php | 10 ++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/CreatesApplication.php create mode 100644 tests/Feature/Services/NominatimTest.php create mode 100644 tests/TestCase.php diff --git a/app/Services/NominatimService.php b/app/Services/NominatimService.php index cfe2fc50..209d59bb 100644 --- a/app/Services/NominatimService.php +++ b/app/Services/NominatimService.php @@ -2,10 +2,32 @@ namespace App\Services; +use Illuminate\Support\Facades\App; + class NominatimService { - public function get_way_id_from_nominatim(): string + public function get_way_id_from_nominatim($lat = null, $lng = null) { + if (App::environment('production')) + { + $url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16"; + $arrContextOptions=array( + "ssl"=>array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + ); + + $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); + $result = json_decode($result); + if (isset($result->osm_type)) { + if ($result->osm_type == 'way') { + return $result->osm_id; + } + } + return 0; + } + return 0; } } \ No newline at end of file diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php new file mode 100644 index 00000000..c627fb76 --- /dev/null +++ b/tests/CreatesApplication.php @@ -0,0 +1,21 @@ +make(Kernel::class)->bootstrap(); + + return $app; + } +} diff --git a/tests/Feature/Services/NominatimTest.php b/tests/Feature/Services/NominatimTest.php new file mode 100644 index 00000000..8fc7fcd5 --- /dev/null +++ b/tests/Feature/Services/NominatimTest.php @@ -0,0 +1,22 @@ +get_way_id_from_nominatim(); + + $this->assertEquals($wayId, 0); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..d3aab464 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,10 @@ +