-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
342 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ jobs: | |
- BingMaps | ||
- Cache | ||
- Chain | ||
- Faker | ||
- FreeGeoIp | ||
- GeoIP2 | ||
# - GeoIPs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.gitattributes export-ignore | ||
phpunit.xml.dist export-ignore | ||
Tests/ export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Provider | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
test: | ||
name: PHP ${{ matrix.php-version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-version: ['8.0', '8.1', '8.2'] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use PHP ${{ matrix.php-version }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
extensions: curl | ||
- name: Validate composer.json and composer.lock | ||
run: composer validate --strict | ||
- name: Install dependencies | ||
run: composer update --prefer-stable --prefer-dist --no-progress | ||
- name: Run test suite | ||
run: composer run-script test-ci | ||
- name: Upload Coverage report | ||
run: | | ||
wget https://scrutinizer-ci.com/ocular.phar | ||
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
composer.lock | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Change Log | ||
|
||
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. | ||
|
||
## 5.0.0 | ||
|
||
First release of this library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Geocoder\Provider\Faker; | ||
|
||
use Faker\Factory; | ||
use Geocoder\Collection; | ||
use Geocoder\Model\AddressBuilder; | ||
use Geocoder\Model\AddressCollection; | ||
use Geocoder\Provider\Provider; | ||
use Geocoder\Query\GeocodeQuery; | ||
use Geocoder\Query\Query; | ||
use Geocoder\Query\ReverseQuery; | ||
|
||
/** | ||
* @author Romain Monteil <[email protected]> | ||
*/ | ||
final class Faker implements Provider | ||
{ | ||
public const PROVIDER_NAME = 'faker'; | ||
|
||
public function geocodeQuery(GeocodeQuery $query): Collection | ||
{ | ||
return $this->generateFakeLocations($query); | ||
} | ||
|
||
public function reverseQuery(ReverseQuery $query): Collection | ||
{ | ||
return $this->generateFakeLocations($query); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return self::PROVIDER_NAME; | ||
} | ||
|
||
private function generateFakeLocations(Query $query): Collection | ||
{ | ||
$faker = Factory::create($query->getLocale() ?? Factory::DEFAULT_LOCALE); | ||
|
||
$results = []; | ||
|
||
$i = 0; | ||
while ($i < $query->getLimit()) { | ||
$builder = new AddressBuilder($this->getName()); | ||
$builder | ||
->setCoordinates($faker->latitude(), $faker->longitude()) | ||
->setStreetNumber($faker->buildingNumber()) | ||
->setStreetName($faker->streetName()) | ||
->setPostalCode($faker->postcode()) | ||
->setLocality($faker->city()) | ||
->setCountry($faker->country()) | ||
->setCountryCode($faker->countryCode()) | ||
->setTimezone($faker->timezone()) | ||
; | ||
|
||
$results[] = $builder->build(); | ||
++$i; | ||
} | ||
|
||
return new AddressCollection($results); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2011 — William Durand <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Nominatim Geocoder provider | ||
[![Build Status](https://img.shields.io/github/actions/workflow/status/geocoder-php/Geocoder/provider.yml?style=flat-square)](https://github.com/geocoder-php/faker-provider/actions) | ||
[![Latest Stable Version](https://img.shields.io/packagist/v/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider) | ||
[![Monthly Downloads](https://img.shields.io/packagist/dm/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider) | ||
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/geocoder-php/faker-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/faker-provider) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/geocoder-php/faker-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/faker-provider) | ||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) | ||
|
||
This is the Faker provider from the PHP Geocoder. This is a **READ ONLY** repository. See the | ||
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation. | ||
|
||
## Install | ||
|
||
```bash | ||
composer require geocoder-php/faker-provider | ||
``` | ||
|
||
## Contribute | ||
|
||
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or | ||
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues). |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Geocoder package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Geocoder\Provider\Faker\Tests; | ||
|
||
use Geocoder\IntegrationTest\BaseTestCase; | ||
use Geocoder\Model\Address; | ||
use Geocoder\Provider\Faker\Faker; | ||
use Geocoder\Query\GeocodeQuery; | ||
use Geocoder\Query\ReverseQuery; | ||
|
||
class FakerTest extends BaseTestCase | ||
{ | ||
protected function getCacheDir(): string | ||
{ | ||
return __DIR__.'/.cached_responses'; | ||
} | ||
|
||
public function testGetName(): void | ||
{ | ||
$provider = new Faker(); | ||
|
||
$this->assertEquals('faker', $provider->getName()); | ||
} | ||
|
||
public function testGeocode(): void | ||
{ | ||
$provider = new Faker(); | ||
$result = $provider->geocodeQuery(GeocodeQuery::create('Dummy address')); | ||
|
||
$this->assertContainsOnlyInstancesOf(Address::class, $result); | ||
$this->assertCount(5, $result); | ||
} | ||
|
||
public function testReverse(): void | ||
{ | ||
$provider = new Faker(); | ||
$result = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86, 2.35)); | ||
|
||
$this->assertContainsOnlyInstancesOf(Address::class, $result); | ||
$this->assertCount(5, $result); | ||
} | ||
|
||
public function testQueryWithLimit(): void | ||
{ | ||
$provider = new Faker(); | ||
$result = $provider->geocodeQuery(GeocodeQuery::create('Dummy address')->withLimit(10)); | ||
|
||
$this->assertContainsOnlyInstancesOf(Address::class, $result); | ||
$this->assertCount(10, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Geocoder package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Geocoder\Provider\Faker\Tests; | ||
|
||
use Geocoder\IntegrationTest\ProviderIntegrationTest; | ||
use Geocoder\Provider\Faker\Faker; | ||
use Psr\Http\Client\ClientInterface; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class IntegrationTest extends ProviderIntegrationTest | ||
{ | ||
protected bool $testAddress = false; | ||
|
||
protected bool $testReverse = false; | ||
|
||
protected bool $testIpv4 = false; | ||
|
||
protected bool $testIpv6 = false; | ||
|
||
protected function createProvider(ClientInterface $httpClient): Faker | ||
{ | ||
return new Faker(); | ||
} | ||
|
||
protected function getCacheDir(): string | ||
{ | ||
return __DIR__.'/.cached_responses'; | ||
} | ||
|
||
protected function getApiKey(): string | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "geocoder-php/faker-provider", | ||
"type": "library", | ||
"description": "Geocoder Faker adapter", | ||
"keywords": [], | ||
"homepage": "https://geocoder-php.org/", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Romain Monteil", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"geocoder-php/common-http": "^4.1", | ||
"willdurand/geocoder": "^4.0", | ||
"fakerphp/faker": "^1.23" | ||
}, | ||
"provide": { | ||
"geocoder-php/provider-implementation": "1.0" | ||
}, | ||
"require-dev": { | ||
"geocoder-php/provider-integration-tests": "^1.6.3", | ||
"php-http/message": "^1.0", | ||
"phpunit/phpunit": "^9.5" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "4.0-dev" | ||
} | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Geocoder\\Provider\\Faker\\": "" | ||
}, | ||
"exclude-from-classmap": [ | ||
"/Tests/" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit", | ||
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"php-http/discovery": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php"> | ||
<coverage> | ||
<include> | ||
<directory>./</directory> | ||
</include> | ||
<exclude> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</coverage> | ||
<php> | ||
<server name="USE_CACHED_RESPONSES" value="true"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Geocoder Test Suite"> | ||
<directory>./Tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |