create test directory
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
21
tests/CreatesApplication.php
Normal file
21
tests/CreatesApplication.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*/
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
22
tests/Feature/Services/NominatimTest.php
Normal file
22
tests/Feature/Services/NominatimTest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Services;
|
||||
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NominatimTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_nominatim_service_return_0_if_the_environment_is_not_production(): void
|
||||
{
|
||||
$wayId = (new NominatimService())->get_way_id_from_nominatim();
|
||||
|
||||
$this->assertEquals($wayId, 0);
|
||||
}
|
||||
}
|
||||
10
tests/TestCase.php
Normal file
10
tests/TestCase.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
}
|
||||
Reference in New Issue
Block a user